Photoresistor
Overview
Built-in photoresistor for photoelectric conversion. Generally used for light measurement and light control.
Technical Specifications
Operating voltage: VCC 3.3V -5V
Module dimensions: 24*48mm
Mounting: 2 plastic building block compatible through-holes
Data type: Analog sampling value
Pin Definition
Pin |
Definition |
|---|---|
GND |
Ground |
VCC |
Power |
AO |
A nalog sampling value |
NC |
Not connected |
Example Code
1. AO port outputs analog value, DO port outputs digital value 0/1.
2. The DO port digital value trigger threshold can be adjusted through the potentiometer on the front of the module. When the red LED is on, it indicates digital output 1 is triggered; otherwise, it represents digital output 0.
3. When the analog light sensor measurement value exceeds 500, the mPython Board RGB LED lights up.
from mpython import *
import math
p0 = MPythonPin(0, PinMode.ANALOG)
import time
while True:
oled.fill(0)
oled.DispChar(str('Analog Light'), 0, 0, 1)
oled.DispChar(str(str('Value: ') + str(p0.read_analog())), 0, 16, 1)
oled.show()
if p0.read_analog() > 500:
rgb.fill((int(255), int(0), int(0)))
rgb.write()
time.sleep_ms(1)
time.sleep(1)
else:
rgb.fill( (0, 0, 0) )
rgb.write()
time.sleep_ms(1)