Light-Dependent Resistors
(Redirected from Photoresistor)
Description[edit]
An LDR is a light-dependent resistor. It changes it's resistance depending on the light falling onto the LDR.
How to connect it electrically[edit]
Connecting the light dependent resistor (LDR). The value you read is dependent on how bright it is.
How to control it in MicroPython[edit]
This makes Pin 34 an analog input and set it to 12 bit. It reads the analog value every second and print it to the console.
#Example usage for ESP32
from machine import Pin, ADC
from time import sleep
analogPin = ADC(Pin(34))
analogPin.atten(ADC.ATTN_11DB)
while True:
analogVal = analogPin.read()
print(analogVal)
sleep(1)
Code Example Arduino Nano Connect RP2040[edit]
A0 is the analog input with 16 bit resolution. It reads the analog value every second and print it to the console-
#Example usage for Arduino Nano
from machine import Pin, ADC
from time import sleep
analogPin = ADC(Pin(26))
while True:
analogVal16 = analogPin.read_u16()
print(analogVal16)
sleep(1)
Related Tutorial Videos[edit]