Learn how to use an LDR circuit with an Arduino.

Learn how to use an LDR circuit with an Arduino. Arduino Light Sensor Circuit using LDR
A SIMPLE SOFTWARE SERVICE PROJECT USING A RASPBERRY PI THAT CONTROLS ELECTRICAL APPLIANCES WHEN AN LDR SENSOR DETECTS DARKNESS.

LDR Sensor With Arduino

Wouldn’t it be awesome if we could banish the night? I’ve posted a pretty straightforward Arduino project that aims to banish the darkness. A light bulb automatically comes on whenever a room becomes dark owing to a blown fuse or any other reason. Even as an emergency lighting system, you can utilize this. Use it to set a light to come on automatically when a room is too dark.

We utilize a sensor known as an LDR to measure the amount of light or darkness (light-dependent resistor). The LDR is a unique kind of resistor that passes a low voltage (high resistance) when it is dark and a high voltage (low resistance) when there is a high intensity of light. In our DIY Arduino LDR sensor project, we can make use of this LDR feature.

How Does It Function?

By detecting the amount of light present in its surroundings, this system operates. An LDR is a type of sensor that can be used to detect light. You may purchase it from any nearby electronics store or online at a reasonable price.

When connected to VCC (5V), the LDR emits an analog voltage whose magnitude varies in direct proportion to the amount of input light it receives. In other words, the voltage coming from the LDR will increase in proportion to the brightness of the light. The analog input pin on the Arduino is linked to the LDR because it emits an analog voltage. The Arduino then transforms the analog voltage (between 0 and 5 volts) into a digital value within the range of (0-1023). The translated digital values read from the LDR through the Arduino will be in the range of 800-1023, depending on how much light is present in its surroundings or on its surface.

Learn how to use an LDR circuit with an Arduino. image 5
Arduino LDR Sensor working
Learn how to use an LDR circuit with an Arduino. image 12

The Arduino is then programmed to activate a relay. Turn on an appliance (a light bulb), in accordance, when the light intensity is low, that is, when the digital values read are higher than usual. You can do this by covering the LDR’s surface with any object.

Arduino LDR Sensor Connections

The LDR must first be connected to the Arduino’s analog input pin zero. To do this, a voltage divider setup must be used. The following is the Arduino connection schematic.

Learn how to use an LDR circuit with an Arduino. image 6
LDR connectors for Arduino

The Arduino’s analog pin 0 and VCC (5V) are connected to one leg and the analog pin 0 to the other of the LDR, respectively. Additionally linked to the same leg and grounded is a 100K resistor.

Testing the Arduino LDR Sensor Code

You may use your Arduino to check for the values coming from the LDR after attaching it. Connect the Arduino to your PC using USB to accomplish this, then launch the Arduino IDE or software. Paste this code after that, then upload it to your Arduino:

int sensorPin = A0; // select the input pin for LDR int sensorValue = 0; // variable to store the value coming from the sensor void setup() { Serial.begin(9600); //sets serial port for communication } void loop() { sensorValue = analogRead(sensorPin); // read the value from the sensor Serial.println(sensorValue); //prints the values coming from the sensor on the screen delay(100); }

After uploading the code, select the “Serial monitor” button on the Arduino IDE to create a new window that outputs various numbers on the screen. Now, try out the sensor by obstructing its surface with light and observe what values you get on the serial monitor.

Learn how to use an LDR circuit with an Arduino. image 7
Arduino LDR Sensor – Serial Monitor

Linking the Arduino to the Relay

An electromechanical switch is a relay. It can be used to ON/OFF switch AC/DC powered appliances. The relay is turned on (the switch is ON) when the Arduino sends HIGH power (5V) to it; otherwise, it is left off.

A 5V SPDT (single pole, double throw) relay was employed in this project. The Arduino’s digital pin 2 is linked to one terminal of the relay coil, and GND is attached to the other. We additionally connected a light bulb to it. Be cautious to take the necessary precautions because we are working with high-power AC voltages. Read this article on relay logic if you’re still unclear about how to connect a relay to an appliance. Below is a diagram of the complete circuit.

LDR Sensor
Arduino LDR Sensor and Relay – Connection Diagram

CHECK THIS VIDEO FOR ARDUINO PROJECT INSPO: EDUCATIONAL ENGINEERING TEAM