Difference between revisions of "Potentiometer"
Jump to navigation
Jump to search
(One intermediate revision by one other user not shown) | |||
Line 15: | Line 15: | ||
= 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 machine import Pin, ADC | ||
from time import sleep | from time import sleep | ||
Line 25: | Line 26: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | Here the voltage of Pin 34 is manipulable with the poti: | + | <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> | ||
+ | |||
+ | |||
+ | 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]] | [[File:PotiConnection2.jpg|300px]] | ||
+ | |||
Schematic drawing: | Schematic drawing: | ||
[[File:PotiConnection1.png|300px]] | [[File:PotiConnection1.png|300px]] | ||
− | |||
− | |||
= Related Tutorial Videos = | = Related Tutorial Videos = | ||
<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]