LDR

From Sketching with Hardware at LMU Wiki
Revision as of 00:21, 30 August 2020 by Skwhadmin (talk | contribs)
Jump to navigation Jump to search

Description

Text

Image(s)


How to connect it electrically

Connecting the light dependent resistor (LDR). The value you read is dependent on how bright it is.


How to control it in MicroPython

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)

Related Tutorial Videos