
Hello friends, Welcome to my SriTu Hobby blog. So far we have described 20 articles through the blog. Each of these articles explains the basics of Arduino components. You can read these previous articles. So let’s go to today’s post. Today we are going to talk about the LDR sensor.
What is an LDR sensor?
It is called a Light Dependent Resistor. It is a resistor. This is also known as a photoresistor. This is a semiconductor device. Depending on the amount of light falling on the sensor surface, the resistance value increases or decreases. It depends on the electron value. The higher the light, the higher the electron value, and the lower the light, the lower the electron value. As the electron value increases, the resistance value decreases as the current is easier to flow. When the electron value decreases, the resistance value increases as the current becomes difficult to flow. We can use this method to create light-sensitive circuits. This sensor is also used for night-active street lamps. We can use this sensor for various projects. It depends on your creativity. Ok, let’s check this sensor activity using a multimeter. Use a multimeter and sensor for this.

Components
- Arduino Uno board — Amazon / Our Store
- LDR sensor — Our Store / Amazon
- LED bulb — Banggood / Our Store
- Breadboard — Amazon / Our Store
- 180ohm resistor — Banggood / Our Store
- 10k resistor — Banggood / Our Store
- Jumper wires — Amazon / Our Store
Step 1
Let us identify these components.
Arduino Uno board

LDR sensor


180ohm resistor

10k resistor

Breadboard

Jumper wires

Step 2


Step 3
#define led 3
#define sensor A2
void setup() {
pinMode(led, OUTPUT);
Serial.begin(9600);
}
void loop() {
int value = analogRead(sensor);
value = map(value, 0, 1023, 0, 255);
Serial.println(value);
analogWrite(led, value);
}
After that, the sensor value is read and put into the integer variable. The variable name is called “value”.
int value = analogRead(sensor);
This code converts the value from 0 – 1024 to 0 – 255. This is because the PWM value ranges from 0 – 255.
value = map(value, 0, 1023, 0, 255);
Then, using this value, the LED bulb is turned on and off.
analogWrite(led, value);
This code With this code, the amount of light in the bulb increases or decreases depending on the amount of light received by the sensor. Look at the code below. This code turns on the LED bulb when the sensor value reaches a certain value or higher. For that, the if condition is used. Please upload and check these two codes separately.
The complete program of this project – Download
/*LDR sensor control circuit.
created by the SriTu Tech team.
Read the code below and use it for any of your creation
*/
#define led 3 //led pin
#define sensor A2 //sensor pin
void setup() {
Serial.begin(9600);//serial monitor
pinMode(led, OUTPUT);
}
void loop() {
int value = analogRead(sensor);//get value
Serial.println(value);
if (value >= 950) {
digitalWrite(led, HIGH);//LED ON
Serial.println("LED ON");
} else {
digitalWrite(led, LOW);//LED OFF
Serial.println("LED Off");
}
}
OK Let’s upload the first code.
Step 4


Step 5
Finally, upload the code and enjoy it.

Everything is done. Test this circuit by increasing or decreasing the light. Please upload the second code and check it out. Below is a video of it being done. Please watch it. So, we will meet in the next post. Have a good day. Bye-bye.
LDR sensor control with Arduino