Difference between revisions of "LDR"

From Sketching with Hardware at LMU Wiki
Jump to navigation Jump to search
(Redirected page to Light-Dependent Resistors)
Tag: New redirect
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
= Description =
+
#REDIRECT [[Light-Dependent Resistors]]
An LDR is a light-dependent resistor. It changes it's resistance depending on the light falling onto the LDR.
 
 
 
[[File:Ldr01.PNG|200px]]
 
 
 
= How to connect it electrically =
 
Connecting the light dependent resistor (LDR). The value you read is dependent on how bright it is.
 
 
 
[[File:Rldr.JPG|300px]]
 
 
 
 
 
= 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.
 
 
 
<syntaxhighlight lang="python" line='line'>
 
#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)
 
</syntaxhighlight>
 
 
 
= Related Tutorial Videos =
 
<youtube>gjj5KyK2qGI</youtube>
 

Latest revision as of 23:40, 10 June 2024