Arduino with darkness Sensor and LED
Today we shall learn to use a LDR with arduino.
The required kits are :
- An arduino and its adapter
- Few jumper Wires
- LDR with 10k OHM resistor
- A LED with 220 OHM resistor
- A breadboard
- Fix the LED on the breadboard.
- Connect longer LED leg to pin 12 on the arduino.
- Connect shorter LED leg to GND pin on the breadboard through a 220 ohm resistor.
- Connect 5V pin on the arduino to +VE on the breadboard .
- Connect GND pin on the arduino to -VE on the breadboard .
(Code)
const int ledpin=12;const int ldrpin=A2;
int darknesssensvalue=0;
int threshold=500;
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
pinMode(ledpin,OUTPUT);
pinMode(ldrpin,INPUT);
}
void loop() {
darknesssensvalue=analogRead(ldrpin);
if (darknesssensvalue<=threshold) {
digitalWrite(ledpin,HIGH);
delay(100);
digitalWrite(ledpin,LOW) ;
delay(100);
}
else {
digitalWrite(ledpin,LOW);
}
}
Hi there,
ReplyDeleteThank you sharing such a useful information.
We are leading motion sensors, smart lights, home automation products manufacturers in Vadodara
Visit our website for more information - Smart Home Automation
Very good & informative content on topic
ReplyDeleteThanks for sharing such a useful tips.
Visit our website for Web development company in Vadodara
Thank you for sharing such a useful information.
ReplyDeleteiMagic Baroda
Apple authorized store in Vadodara