Have you ever wondered how streetlights know when to turn on at night and off during the day? Or how a smartphone adjusts its screen brightness automatically? The answer lies in a simple but powerful component, the light sensor.
In this post, we’ll explore how to use a light sensor with an Arduino board, how it works, and some cool project ideas you can try.
What is a Light Sensor?
A light sensor (often called a photoresistor or LDR – Light Dependent Resistor) is a special resistor that changes its resistance depending on the amount of light falling on it:
Bright light → low resistance (more current flows)
Darkness → high resistance (less current flows)
By connecting this sensor to an Arduino, we can measure the amount of light in an environment and use it to control other devices like LEDs, motors, or relays.
Components You’ll Need
To follow along, you’ll need:
Arduino board (Uno, Nano, etc.)
Light-dependent resistor (LDR)
10kΩ resistor
Breadboard and jumper wires
LED
Circuit Connection
Connect one leg of the LDR to 5V.
Connect the other leg of the LDR to A0 (analog input pin) and also to one end of the 10kΩ resistor.
Connect the other end of the resistor to GND.
Connect an LED to pin 2 through a 1kΩ resistor for testing.
This creates a voltage divider so the Arduino can read the changing resistance of the LDR as light intensity changes.
int ldr_pin = A0;
int led_pin = 2;
int threshold = 500;
void setup() {
// put your setup code here, to run once:
pinMode(led_pin, OUTPUT);
pinMode(ldr_pin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int light_level = analogRead(ldr_pin); // Reads LDR value
if(light_level < threshold){
digitalWrite(led_pin, HIGH);
} else{
digitalWrite(led_pin, LOW);
}
delay(200);
}
Applications of Light Sensors
Light sensors are everywhere around us. Here are some practical uses:
Automatic streetlights
Smart home lighting systems
Solar garden lights
Alarm systems that detect shadows/movement
DIY energy-saving projects
Final Thoughts
Working with a light sensor and Arduino is one of the easiest and most exciting beginner projects. It introduces you to the world of analog inputs and shows how sensors can make electronics more interactive.
Try experimenting:
Adjust the threshold value in the code
Control a motor or relay instead of just an LED
Build a simple light-following robot
With just a few components, you can bring your projects to life with light!