Detect the darkness with the help of Arduino board and LDR Sensor
In this project, Arduino and LDR Sensor turns on lights automatically,
when an LDR sensor detects darkness.
Requirements of hardware for this project:
- Arduino UNO board
- A USB cable for connecter Arduino UNO board
- LDR Sensor
- Jumper wires male to female
- LED light
Requirements of software in this project:
- Arduino IDE (To program the Arduino board, we need to download the Arduino software.)
The Working principle the project:
The Arduino UNO board is programmed to send the data to the LDR sensor. LDR sensor detects the darkness. The LDR sensor sends the data Arduino UNO board. The code downloaded within the Arduino board verifies the received data and then it turns on or off the LED light.
Write a program for the Arduino IDE.
Full code show in below:
int LDR = 0;
int LDRValue = 0;
int light_sensitivity = 500;
LDRValue = analogRead(LDR);
if (LDRValue < light_sensitivity)
Save the program and compile the code, as shown in the following figure:
Connect your Arduino UNO board to your laptop or desktop computer through the Arduino UNO USB cable. Remove all other connections with the Arduino UNO board, such as the LDR Sensor and LED bulb. After that Upload the program to the Arduino UNO board.
Before uploading the code to the Arduino UNO board make sure that your Arduino serial port is selected. Otherwise, an error message “Serial port not selected” is displayed on the screen.
To select your serial port in your laptop or desktop:
Open Device Manager -> Ports ->Arduino Uno, and then upload your code.
After uploading the program in the Arduino UNO board. Connect all modules with the Arduino UNO board, such as the LDR Sensor and LED bulb. The following image shows the Digital circuit Diagram.
When the LDR Sensor enters in the dark area, then LED light turns on. When the LDR sensor does not enters in the dark area, then LED light turns “off”, as shown in the following image.by