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!
2.2.1 Photoresistorο
Introductionο
Photoresistor is a commonly used component of ambient light intensity in life. It helps the controller to recognize day and night and realize light control functions such as night lamp. This project is very similar to potentiometer, and you might think it changing the voltage to sensing light.
Componentsο

Schematic Diagramο


Experimental Proceduresο
Step 1: Build the circuit.

Step 2: Go to the folder of the code.
cd ~/davinci-kit-for-raspberry-pi/nodejs/
Step 3: Run the code.
sudo node photoresistor.js
When the code is running, the brightness of the LED will change according to the light intensity sensed by the photoresistor.
Code
const Gpio = require('pigpio').Gpio;
const ADC0834 = require('./adc0834.js').ADC0834;
exports.ADC0834 = ADC0834;
const adc = new ADC0834(17, 18, 27);
const led = new Gpio(22, {mode: Gpio.OUTPUT});
setInterval(() => {
adc.read(0).then((value) => {
console.log(value);
led.pwmWrite(value);
}, (error)=>{
console.log("Error: " + error);
});
}, 100);
Code Explanation
The codes here are the same as that in 2.1.4 Potentiometer. Please check the code explanation of 2.1.4 Potentiometer for details.
Phenomenon Pictureο
