Arduino: Light sensor (basics)

In this article I will show you how to measure the amount of light in a room with Arduino and a light sensor. Measuring light is done by a sensor with a photoresistor (photocell). Photoresistor is basically a resistor which resistance depends on the amount of light it absorbs. Lesser the light higher the resistance and vice versa. What that offers us is the ability to measure its resistance and by that the amount of light in the room.

This can be used for all sorts of projects, like home automation for turning the lights on in case of low amount of light, or alerting you if you left the lights on in your house/room/garage.

Since I will often use this type of sensor for more advanced types of projects, like connecting Arduino to local network and creating a web server to display the data, here is the basic light sensor project that others will be built on.


For this project I will be using:

 – Arduino


– Light sensor – I bought this over eBay, price range about 2$ (something like this)


– 3 x jumper wire




Step 1

Wiring the sensor to Arduino

1. Connect the “female” end of jumper wires to the sensor, in my case: green wire to GND,  purple wire to VCC, yellow wire to SIG.


2. Connect the “male” end of jumper wire to Arduino accordingly: green wire to GND, purple wire to 5V, yellow wire to A0 analog input port.





Step 2

Writing the code

Connect the Arduino to the computer using a USB cable and open up Arduino IDE (which you can download on their webpage), and insert this code:


int sensorPin = 0;   // Analog input pin on Arduino we connected the SIG pin from sensor
int sensorReading;   // Here we will place our reading

void setup() {
// Serial.begin starts the serial connection between computer and Arduino

void loop() {

// Fill the sensorReading with the information from sensor
sensorReading = analogRead(sensorPin);

Serial.print("Amount of light measured: ");
Serial.println(sensorReading);     // Print out the information

// Set a delay from reading so we don't get flooded with information, 1000ms = 1s



Open up your Serial Monitor (in Arduino IDE) and you should get something like this (depending on the light measured).



Congratulations, you just measured the amount of light in your room.

While light sensor is a really easy to build project a lot of other sensors built for Arduino work entirely the same. Connect power, ground and sensor input and read out information.