Arduino Photoresistor Night Light Project

Project Principle Introduction
In today’s project, a night light circuit will be constructed using an HW-486 photoresistor module and an LED, with the Arduino as the main microcontroller for the circuit. Essentially, when this circuit is placed in low levels of light or in the dark, the green LED will switch on. However, when the amount of light present exceeds a certain threshold, as detected by the photoresistor module, the green LED will switch off. In terms of how this circuit works, the photoresistor module basically acts as a light-dependent resistor where the greater the amount of light it is exposed to, the greater the analogue output values that are received from the module. Contrastingly, as we lower the light levels, the analogue output values from the photoresistor will decrease and these analogue values correspond to both conductance and resistance. In high-light conditions, the conductivity across the electrodes of the photoresistor increases and therefore, resistance decreases. On the contrary, in low-light conditions, the conductivity across the photoresistor decreases and therefore, resistance increases. The low resistance caused by dark/low-light conditions will allow the LED to switch on whereas in bright/high-light conditions, the high resistance will inhibit the LED from receiving enough output voltage to switch on. This simple circuit demonstrates the unique feature of photoresistors and the inverse relationship between light level and resistance within photoresistors.
Prepare
Although this project exhibits a common use of photoresistors for a simple night light, photoresistors may commonly be used as light sensors for weather stations, light meters, solar lamps, outdoor clocks, etc. Plus, another advantage to using photoresistors is that they are extremely affordable and versatile analogue light-dependent resistors, which can easily be added into almost any circuit. Nonetheless, it is still necessary to prepare the components required for the lamp circuit in advance, and you can get FS Technology’s component procurement for help.
- Arduino Nano (other Arduino-compatible boards will work)
- USB cable (compatible with the Arduino board)
- Breadboard
- Male-Male Jumper Wires (5)
- HW-486 Photoresistor Module
- Green LED (common cathode)
- 220Ω resistor
Wiring
Depending on your Arduino board, you may or may not require a breadboard to plug your board in. In this example, an Arduino Nano is used, thus requiring a breadboard but if you are using an Arduino Uno, for example, the jumper wires can be plugged in from the components on the breadboard directly to the board pins. The wiring for this project is fairly simple as aside from the main modules, not a lot of extra components are needed. In terms of the photoresistor module, the HW-486 photoresistor module that is featured in this project has a simple 3-pin configuration where there is a signal (S) pin, positive (+) pin and GND (-) pin. In terms of the green LED (common cathode), the reason that a 220Ω resistor is connected in series with the anode (long leg) is to prevent the LED from burning out when applying a supply voltage of +5 volts. A circuit diagram of the wiring is also featured below.
- HW-486 Photoresistor Module: Connect the signal (S) pin to A2 on your Arduino board, the positive (+) pin to +5v and the GND (-) pin to GND.
- Green LED (common cathode): Insert one 220Ω resistor in the breadboard in series with the anode (long leg) of the LED and use a jumper wire to connect the anode to D2. Connect the cathode (short leg) of the LED to GND.
- Now, you can plug in your Arduino board via the USB cable to the computer.

Project Code
int photoPin = A1;
int ledPin = 2;
int val = 0;
int light = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
val = analogRead(photoPin);
light = map(val, 0, 1023, 0, 10);
Serial.println(light);
if (light < 5) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
delay(100);
}
About Code
In the first block of the code, several integer variables are declared that involve the pins of the photoresistor module (A1) and LED (D2), in addition to several integer variables named ‘val’ and ‘light’ that will be used later to store analogue information that is received from the photoresistor.
In the void setup section, the LED is declared as an output device since information from the Arduino is being sent out to the LED to control it. Plus, serial communication is initiated by setting a baud rate of 9600 bauds.
Moving onto the void loop section, the integer variable ‘val’ that was declared earlier is set equal to the analogue output from the photoresistor module using the analogRead() function. Then, we use the map() function to re-map the analogue output range from the photoresistor of 0 to 1023 to a much smaller range that we can more easily work with, from 0 to 10. The new analogue output value is stored in the integer variable ‘light’.
Next, an if-else statement is introduced where we state that if the light level is below a certain threshold value of 5, the LED switches on but if that threshold is not met, the LED switches off. A delay of 100 milliseconds is also added at the end. This if-else statement essentially forms the basis of this night light circuit.
Next step
Now that you have constructed this night light circuit using the HW-486 Photoresistor Module, it shows how effortless it is to integrate a photoresistor into a project like this. With endless applications for photoresistors, even creating standalone circuits or portable devices that are battery-powered with microcontrollers can be made possible. Oftentimes, you may have seen outdoor garden solar lamps or home intruder prevention lights that typically utilize some sort of photoresistor technology to be activated during the night. To expand upon this LED PCBA project, you could also utilize relays to control much larger electrical appliances and therefore be on your way to innovating more practical or even commercial devices.
Related Blogs
How to install WSJT-X on Raspberry Pi? If you are an avid amateur radio operator or simply an interested electronic hobbyist, then this tutorial is
Hot Swap Keyboard PCB Guidelines Traditional PCBA boards rely on the soldering process to securely attach components to the surface of the circuit board. While
How to stress test your Raspberry Pi? If you are interested in finding out the true capabilities of your Raspberry Pi, especially if you have
How to overclock your Raspberry Pi? Have you ever wanted to boost the capabilities of your Raspberry Pi without the need for additional hardware or
Arduino Photoresistor Night Light Project Project Principle Introduction In today’s project, a night light circuit will be constructed using an HW-486 photoresistor module and an
Arduino Shock/Vibration Detector Project In this project, you will be exploring the capabilities of the HW-513 Shock/Vibration Sensor as a shock/vibration detector that may be