Difference between revisions of "LDR"
Jump to navigation
Jump to search
(Created page with "= Description = Text Image(s) = How to connect it electrically = Text Image(s) = How to control it in MicroPython = <syntaxhighlight lang="python" line='line'> # todo #...") |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
= Description = | = Description = | ||
− | + | 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 = | = 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'> | <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 = | = Related Tutorial Videos = | ||
− | + | <youtube>gjj5KyK2qGI</youtube> | |
− | |||
− | <youtube> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Latest revision as of 00:26, 30 August 2020
Contents
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.
1 #Example usage for ESP32
2 from machine import Pin, ADC
3 from time import sleep
4
5 analogPin = ADC(Pin(34))
6 analogPin.atten(ADC.ATTN_11DB)
7
8 while True:
9 analogVal = analogPin.read()
10 print(analogVal)
11 sleep(1)
Related Tutorial Videos[edit]