LDR: Difference between revisions

From Sketching with Hardware at LMU Wiki
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 #..."
 
No edit summary
Line 6: Line 6:


= How to connect it electrically =
= How to connect it electrically =
Text
Connecting the light dependent resistor (LDR). The value you read is dependent on how bright it is.
 
[[File:Rldr.JPG|300px]]


Image(s)


= How to control it in MicroPython =
= How to control it in MicroPython =
<syntaxhighlight lang="python" line='line'>
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.
# todo
# code goes here
</syntaxhighlight>


= A small Program in MicroPython =
<syntaxhighlight lang="python" line='line'>
<syntaxhighlight lang="python" line='line'>
# todo
#Example usage for ESP32
# code goes here
from machine import Pin, ADC
</syntaxhighlight>
from time import sleep


text
analogPin = ADC(Pin(34))
analogPin.atten(ADC.ATTN_11DB)


image(s)
while True:
  analogVal = analogPin.read()
  print(analogVal)
  sleep(1)
</syntaxhighlight>


= Related Tutorial Videos =
= Related Tutorial Videos =
change to the right video
<youtube>gjj5KyK2qGI</youtube>
 
<youtube>0KGgYsEZcZM</youtube>
 
 
= Background =
text
 
image(s)

Revision as of 00:21, 30 August 2020

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