Arduino Nano - Light Sensor LED
This tutorial instructs you how to use Arduino Nano and light sensor to trigger LED. In detail:
- Arduino Nano turns on the LED if the analog value of the light sensor is lower than a certain threshold (when dark)
- Arduino Nano turns off the LED if the analog value of the light sensor is greater than a certain threshold (when light)
The light sensor is also known as photoresistor, light-dependent resistor, photocell, LDR. Arduino Nano measures the light level of ambience via a light sensor, if it is dark, Arduino Nano turns on LED and vice versa.
Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of LED and Light Sensor
If you are unfamiliar with LED and light sensor (pinout, functionality, programming ...), please refer to the following tutorials:
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
See The best way to supply power to the Arduino Nano and other components.
Arduino Nano Code
Detailed Instructions
- Connect your Arduino Nano to your computer using a USB cable.
- Launch the Arduino IDE, select the appropriate board and port.
- Copy the code above and open it in the Arduino IDE.
- Click the Upload button in the Arduino IDE to compile and upload the code to the Arduino Nano.

- Emit light source towards the sensor
- Check out the LED's state
Code Explanation
Check out the line-by-line explanation contained in the comments of the source code!