You will learn how to make Automatic Night Light using LDR Relay Arduino UNO. We are nowadays want everything automated. Automatic Night Light is a very popular device. The light will glow in the night or when the area is dark. In the day time or bright condition light will be off.
Components Used:(Click to Buy)
Connection Setup for LDR Relay Arduino
How to connect 220V Ac with Relay
To Connect with AC line we need a small wire. The neutral line will be connected directly to the bulb. Live wire first go to COM port of Relay. Then one small wire will be connected to the bulb from Normally Open(NO) Port. In the following diagram, we have shown a battery instead of the AC line for your understanding.
How to connect Arduino with Relay
Connection with Arduino UNO is a very simple one. Just we have to connect 5V to the VCC and Ground to the GND. Then we have to connect the data line. Here we are using D4 pin.
If you want to control Light via WiFi in NodeMCU, see this post.
Home Automation Using ESP8266 NodeMCU with Relay
Connection Diagram for LDR Relay Arduino
You can connect seeing the following diagram. Just replace the LED with your 220V bulb & Battery with 220V AC line.
I have connected 10K Ohm register with the LDR as a voltage divider. If you connect 3V led then use 220 Ohm register with the LED. If you use AC line, then no registor needed.
Code Explain of LDR Relay Arduino
The important thing in this code lies in line no 17. After determining the analogue value in dark condition on line no 24, set that value in the place of 650 on line 17.
The bulb will be on if outside area is dark as the code written on line no 18.
Arduino Sketch for LDR Relay Arduino
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | /* https://somtips.com https://youtube.com/somtips */ const int ledPin = 4; const int ldrPin = A0; void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); pinMode(ldrPin, INPUT); } void loop() { int ldrStatus = analogRead(ldrPin); if (ldrStatus < 650) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } //checking value Serial.println(ldrStatus); delay(500); } |
Output LDR Relay Arduino
After all the connection done, you will notice the 220V Bulb will switch on/off depending upon present light condition.