Advertisement
pleasedontcode

"Sensor Data" rev_01

Apr 19th, 2025
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Sensor Data"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-04-19 19:39:23
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* i need the sensor to be very accurate in the color */
  21.     /* coding  I need to be able to read the codes */
  22.     /* through my software */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /* START CODE */
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <FreqCount.h>  //https://github.com/PaulStoffregen/FreqCount
  29. #include <DHT.h>    //https://github.com/adafruit/DHT-sensor-library
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void GetData(); // Added prototype for GetData function
  35. void ReadColorData(); // New prototype for reading color data
  36.  
  37. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  38. const uint8_t myDHT22_DHT22_DOUT_PIN_D2     = 2;
  39.  
  40. // Added definitions for the photodiode module pins
  41. #define s0 8       // Module pins wiring
  42. #define s1 9
  43. #define s2 10
  44. #define s3 11
  45. #define out 12
  46.  
  47. int data=0;        // This is where we're going to stock our values
  48.  
  49. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  50. // Instantiate DHT sensor
  51. DHT dht(myDHT22_DHT22_DOUT_PIN_D2, DHT22); // Assuming DHT22 sensor
  52.  
  53. void setup(void)
  54. {
  55.     // put your setup code here, to run once:
  56.  
  57.     pinMode(myDHT22_DHT22_DOUT_PIN_D2, INPUT_PULLUP);
  58.  
  59.     // Initialize photodiode pins
  60.     pinMode(s0, OUTPUT);    // pin modes
  61.     pinMode(s1, OUTPUT);
  62.     pinMode(s2, OUTPUT);
  63.     pinMode(s3, OUTPUT);
  64.     pinMode(out, INPUT);
  65.  
  66.     Serial.begin(9600);   // Initialize the serial monitor baud rate
  67.    
  68.     digitalWrite(s0, HIGH);  // Putting S0/S1 on HIGH/HIGH levels means the output frequency scaling is at 100% (recommended)
  69.     digitalWrite(s1, HIGH); // LOW/LOW is off HIGH/LOW is 20% and LOW/HIGH is 2%
  70.  
  71.     // Initialize DHT sensor
  72.     dht.begin();
  73. }
  74.  
  75. void loop(void)
  76. {
  77.     // put your main code here, to run repeatedly:
  78.     ReadColorData(); // Call to read color data
  79.  
  80.     Serial.println();
  81.  
  82.     delay(2000);
  83. }
  84.  
  85. void GetData(){
  86.     data = pulseIn(out, LOW);       // here we wait until "out" goes LOW, we start measuring the duration and stops when "out" is HIGH again
  87.     Serial.print(data);          // it's a time duration measured, which is related to frequency as the sensor gives a frequency depending on the color
  88.     Serial.print("\t");          // The higher the frequency the lower the duration
  89.     delay(20);
  90. }
  91.  
  92. void ReadColorData() {
  93.     // Read Red value
  94.     digitalWrite(s2, LOW);
  95.     digitalWrite(s3, LOW);
  96.     Serial.print("Red value= ");
  97.     GetData();                   // Executing GetData function to get the value
  98.  
  99.     // Read Blue value
  100.     digitalWrite(s2, LOW);
  101.     digitalWrite(s3, HIGH);
  102.     Serial.print("Blue value= ");
  103.     GetData();
  104.  
  105.     // Read Green value
  106.     digitalWrite(s2, HIGH);
  107.     digitalWrite(s3, HIGH);
  108.     Serial.print("Green value= ");
  109.     GetData();
  110. }
  111.  
  112. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement