Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int ledPin = 13; //the number of the LED pin
- const int ldrPin = A0; //the number of the LDR pin
- void setup() {
- Serial.begin(9600);
- pinMode(ledPin, OUTPUT); //initialize the LED pin as an output
- pinMode(ldrPin, INPUT); //initialize the LDR pin as an input
- }
- void loop() {
- int ldrStatus = analogRead(ldrPin); //read the status of the LDR value
- Serial.println(ldrStatus);
- if (ldrStatus >= 400) { // if bright, turn LED on
- digitalWrite(ledPin, HIGH); //turn LED on
- Serial.println("LED ON");
- }
- else { //if dark turn LED off
- digitalWrite(ledPin, LOW); //turn L ED off
- Serial.print("LED OFF");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement