LED Control With LDR and Arduino
Youtube Tutorial:-
Components Required:- - Arduino Uno
- Breadboard
- led light
- LDR
- Resistor 200 ohm *1
- Resistor 10k ohm *1
- jumper wire
Circuit Diagram:-
Watch full Youtube video for diagram
Code:-
//set pin numbers
- Arduino Uno
- Breadboard
- led light
- LDR
- Resistor 200 ohm *1
- Resistor 10k ohm *1
- jumper wire
//const won't change
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
//check if the LDR status is <= 300
//if it is, the LED is HIGH
if (ldrStatus <=300) {
digitalWrite(ledPin, HIGH); //turn LED on
Serial.println("LDR is DARK, LED is ON");
}
else {
digitalWrite(ledPin, LOW);
//turn LED off
Serial.println("---------------");
}
}
0 Comments