Editing LDR
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
− | + | = 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 = | ||
+ | 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> | ||
+ | |||
+ | |||
+ | == Code Example Arduino Nano Connect RP2040 == | ||
+ | A0 is the analog input with 16 bit resolution. It reads the analog value every second and print it to the console- | ||
+ | |||
+ | <syntaxhighlight lang="python" line='line'> | ||
+ | #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) | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | = Related Tutorial Videos = | ||
+ | <youtube>gjj5KyK2qGI</youtube> |