hey there!, in this post i will show you how to control led using ldr & arduino UNO
Component required
Arduino Uno
LED
LDR (photoresistor)
220 and 10k ohm resistors
Wires
Breadboard
Connection diagram of LED, LDR, & ARDUINO UNO:
Upload the code to arduino:
const int ledPin = 13;
const int ldrPin = A0;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(ldrPin, INPUT);
}
void loop() {
int ldrStatus = analogRead(ldrPin);
if (ldr Status <=300) {
digitalWrite(ledPin, HIGH);
Serial.println("LDR is DARK, LED is ON");
}
else {
digitalWrite(ledPin, LOW);
Serial.println("---------------");
}
}
Result:
Comments