Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. const int ledPin = 13;   //the number of the LED pin
  2. const int ldrPin = A0;  //the number of the LDR pin
  3.  
  4.  
  5. void setup() {
  6.  
  7.   Serial.begin(9600);
  8.   pinMode(ledPin, OUTPUT);  //initialize the LED pin as an output
  9.   pinMode(ldrPin, INPUT);   //initialize the LDR pin as an input
  10. }
  11.  
  12. void loop() {
  13.  
  14.   int ldrStatus = analogRead(ldrPin);   //read the status of the LDR value
  15.  
  16.   Serial.println(ldrStatus);
  17.  
  18.   if (ldrStatus >= 400) { // if bright, turn LED on
  19.  
  20.     digitalWrite(ledPin, HIGH);               //turn LED on
  21.     Serial.println("LED ON");
  22.   }
  23.  
  24.   else {  //if dark turn LED off
  25.  
  26.     digitalWrite(ledPin, LOW);          //turn L ED off
  27.     Serial.print("LED OFF");
  28.   }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement