You are going to create a photoresistor and LED light-based circuit. This circuit is a voltage-divider! The photoresistor changes its resistance based on how much light it detects from the environment. The resistance normally decreases with more light intensity. The main goal is to use the photo-resistor to turn on the LED; by covering the photoresistor, the LED should turn brighter. It’s a nightlight!!
1 Metro M0 Express
1 breadboard
1 330 ohm resistor
1 10k ohm resistor
1 Photoresistor
1 LED light
Wires
Follow the circuit diagram provided to wire the Metro M0 Express.
import board
import pulseio
import time
from analogio import AnalogIn
led = pulseio.PWMOut(__________)
lightLevel = AnalogIn(__________)
while True:
print((lightLevel.value, ))
time.sleep(0.1)
led.duty_cycle = 40535 - lightLevel.value
#theoretically should be 65535 - lightLevel.value
time.sleep(0.1)
import board
import pulseio
import time
from analogio import AnalogIn
led = pulseio.PWMOut(board.D3)
lightLevel = AnalogIn(board.A1)
while True:
print((lightLevel.value, ))
time.sleep(0.1)
led.duty_cycle = 40535 - lightLevel.value
#theoretically should be 65535 - lightLevel.value
time.sleep(0.1)