Difference between revisions of "Potentiometer"
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 #...") |
|||
(8 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
= Description = | = Description = | ||
− | + | A potentiometer is a resistor that can be mechanically changed. Typically form factors are knobs (turn to change) or sliders. The change of resistance is either linear (resistance changes linear with the angle or distance) or logarithmic. | |
− | + | Potentiometer | |
+ | [[File:Poti.PNG|x150px]] | ||
+ | |||
+ | Slider | ||
+ | |||
+ | [[File:Slider.PNG|x150px]] | ||
= How to connect it electrically = | = How to connect it electrically = | ||
− | + | [[File:PotiConnection1.png|300px]] | |
− | |||
− | |||
= How to control it in MicroPython = | = How to control it in MicroPython = | ||
<syntaxhighlight lang="python" line='line'> | <syntaxhighlight lang="python" line='line'> | ||
− | # | + | #ESP32 or ESP8266 |
− | + | from machine import Pin, ADC | |
+ | from time import sleep | ||
+ | pot = ADC(Pin(34)) | ||
+ | pot.atten(ADC.ATTN_11DB) | ||
+ | while True: | ||
+ | pot_value = pot.read() | ||
+ | print(pot_value) | ||
+ | sleep(0.5) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
<syntaxhighlight lang="python" line='line'> | <syntaxhighlight lang="python" line='line'> | ||
− | # | + | #Raspberry Pi Pico |
− | + | from machine import Pin, ADC | |
+ | from time import sleep | ||
+ | pot = ADC(Pin(26)) | ||
+ | conversion_factor = 3.3 / (65535) | ||
+ | while True: | ||
+ | pot_value = pot.read_u16() * conversion_factor | ||
+ | print(pot_value) | ||
+ | sleep(0.5) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
− | + | Here the voltage of Pin 34 (for the ESP) or on Pin GP26 (for the Pico) is manipulable with the poti: | |
+ | |||
+ | [[File:PotiConnection2.jpg|300px]] | ||
+ | |||
+ | |||
+ | Schematic drawing: | ||
+ | |||
+ | [[File:PotiConnection1.png|300px]] | ||
= Related Tutorial Videos = | = Related Tutorial Videos = | ||
Line 30: | Line 52: | ||
<youtube>gjj5KyK2qGI</youtube> | <youtube>gjj5KyK2qGI</youtube> | ||
− | + | [[Category:Sensor]] | |
− | |||
− | |||
− | |||
− |
Latest revision as of 08:51, 11 June 2024
Contents
Description[edit]
A potentiometer is a resistor that can be mechanically changed. Typically form factors are knobs (turn to change) or sliders. The change of resistance is either linear (resistance changes linear with the angle or distance) or logarithmic.
Potentiometer
Slider
How to connect it electrically[edit]
How to control it in MicroPython[edit]
1 #ESP32 or ESP8266
2 from machine import Pin, ADC
3 from time import sleep
4 pot = ADC(Pin(34))
5 pot.atten(ADC.ATTN_11DB)
6 while True:
7 pot_value = pot.read()
8 print(pot_value)
9 sleep(0.5)
1 #Raspberry Pi Pico
2 from machine import Pin, ADC
3 from time import sleep
4 pot = ADC(Pin(26))
5 conversion_factor = 3.3 / (65535)
6 while True:
7 pot_value = pot.read_u16() * conversion_factor
8 print(pot_value)
9 sleep(0.5)
Here the voltage of Pin 34 (for the ESP) or on Pin GP26 (for the Pico) is manipulable with the poti:
Schematic drawing:
Related Tutorial Videos[edit]