Note
Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.
Why Join?
Expert Support: Solve post-sale issues and technical challenges with help from our community and team.
Learn & Share: Exchange tips and tutorials to enhance your skills.
Exclusive Previews: Get early access to new product announcements and sneak peeks.
Special Discounts: Enjoy exclusive discounts on our newest products.
Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.
π Ready to explore and create with us? Click [here] and join today!
Photoresistor Moduleο

Introductionο
A photoresistor module is a device that can detect the intensity of light in the environment. It can be used for various purposes, such as adjusting the brightness of a device, detecting day and night, or activating a light switch.
An important component of the photoresistor module is the photoresistor. A photoresistor is a light-controlled variable resistor. The resistance of a photoresistor decreases with increasing incident light intensity; in other words, it exhibits photo conductivity.
A photoresistor can be applied in light-sensitive detector circuits and light-activated and dark-activated switching circuits acting as a resistance semiconductor. In the dark, a photoresistor can have a resistance as high as several megaohms (MΞ©), while in the light, a photoresistor can have a resistance as low as a few hundred ohms.
Here is the electronic symbol of photoresistor.

Principleο
The photoresistor module works on the principle of changing resistance in response to different light intensities. The sensor has a built-in potentiometer that adjusts the sensorβs digital output (D0) threshold. When the intensity of light exceeds a certain threshold, the resistance of the sensor changes. This change in resistance is then converted to an electrical signal that can be read by the Arduino board.
Module Schematic Diagramο

Usageο
Hardware components
Arduino Uno R4 or R3 board * 1
Photoresistor Module * 1
Jumper Wires
Circuit Assembly

Codeο
Code explanationο
This line of code defines the pin number to which the photoresistance sensor is connected on the Arduino board.
const int sensorPin = 7;
The
setup()
function is a special function in Arduino that is executed only once when the Arduino is powered on or reset. In this project, the sensorPin is set as INPUT because we are reading values from it. The Serial.begin(9600) command initiates serial communication at a baud rate of 9600.void setup() { pinMode(sensorPin, INPUT); Serial.begin(9600); }
The
loop()
function is the main function where the program runs repeatedly. In this function, the digitalRead function reads the digital value from the photoresistor sensor and prints it to the serial monitor using Serial.println. Thedelay(50)
command makes the program wait for 50 milliseconds before taking the next reading.void loop() { Serial.println(digitalRead(sensorPin)); delay(50); }
Additional Ideasο
Use the sensor to turn on/off an LED or relay.
Plot the analog output instead of just digital HIGH/LOW. Use AO pin.