Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: "Sensor Data"
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2025-04-19 19:39:23
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* i need the sensor to be very accurate in the color */
- /* coding I need to be able to read the codes */
- /* through my software */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <FreqCount.h> //https://github.com/PaulStoffregen/FreqCount
- #include <DHT.h> //https://github.com/adafruit/DHT-sensor-library
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void GetData(); // Added prototype for GetData function
- void ReadColorData(); // New prototype for reading color data
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t myDHT22_DHT22_DOUT_PIN_D2 = 2;
- // Added definitions for the photodiode module pins
- #define s0 8 // Module pins wiring
- #define s1 9
- #define s2 10
- #define s3 11
- #define out 12
- int data=0; // This is where we're going to stock our values
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Instantiate DHT sensor
- DHT dht(myDHT22_DHT22_DOUT_PIN_D2, DHT22); // Assuming DHT22 sensor
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(myDHT22_DHT22_DOUT_PIN_D2, INPUT_PULLUP);
- // Initialize photodiode pins
- pinMode(s0, OUTPUT); // pin modes
- pinMode(s1, OUTPUT);
- pinMode(s2, OUTPUT);
- pinMode(s3, OUTPUT);
- pinMode(out, INPUT);
- Serial.begin(9600); // Initialize the serial monitor baud rate
- digitalWrite(s0, HIGH); // Putting S0/S1 on HIGH/HIGH levels means the output frequency scaling is at 100% (recommended)
- digitalWrite(s1, HIGH); // LOW/LOW is off HIGH/LOW is 20% and LOW/HIGH is 2%
- // Initialize DHT sensor
- dht.begin();
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- ReadColorData(); // Call to read color data
- Serial.println();
- delay(2000);
- }
- void GetData(){
- data = pulseIn(out, LOW); // here we wait until "out" goes LOW, we start measuring the duration and stops when "out" is HIGH again
- Serial.print(data); // it's a time duration measured, which is related to frequency as the sensor gives a frequency depending on the color
- Serial.print("\t"); // The higher the frequency the lower the duration
- delay(20);
- }
- void ReadColorData() {
- // Read Red value
- digitalWrite(s2, LOW);
- digitalWrite(s3, LOW);
- Serial.print("Red value= ");
- GetData(); // Executing GetData function to get the value
- // Read Blue value
- digitalWrite(s2, LOW);
- digitalWrite(s3, HIGH);
- Serial.print("Blue value= ");
- GetData();
- // Read Green value
- digitalWrite(s2, HIGH);
- digitalWrite(s3, HIGH);
- Serial.print("Green value= ");
- GetData();
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement