Shekhar777

2 LDR SENSOR

Mar 28th, 2020
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define LDRpin1 7  // pin where we connect LDR and resistor
  2. #define LDRpin2 8  // pin where we connect LDR and resistor
  3.  
  4. int LDRValue1 = 0; // result of reading the digital pin
  5. int LDRValue2 = 0; // result of reading the digital pin
  6.  
  7. void setup() {
  8.   Serial.begin(9600); // sets serial port for communication
  9. }
  10.  
  11. void loop() {
  12.   LDRValue1 = digitalRead(LDRpin1);// read the value from the LDR
  13.   LDRValue2 = digitalRead(LDRpin2);// read the value from the LDR
  14.  
  15.   Serial.print(LDRValue1);         // print the LDR1 value to the serial port
  16.   Serial.print(" ");               // print a space
  17.   Serial.print(LDRValue2);         // print the LDR2 value to the serial port
  18.  
  19.   if((LDRValue1==1)&&(LDRValue2==1)) {
  20.     Serial.print(" -> HIGH"); }
  21.   else if ((LDRValue1==1)&&(LDRValue2==0)) {
  22.     Serial.print(" -> MEDIUM"); }
  23.   else if ((LDRValue1==0)&&(LDRValue2==0)) {
  24.     Serial.print(" -> LOW"); }
  25.    
  26.   Serial.println(" lighting");
  27.  
  28.   delay(100);                    // wait a little
  29. }
Add Comment
Please, Sign In to add comment