Base Input

๐ŸŽš๏ธ Rotary Potentiometer

๐Ÿ“Œ Description

A rotary potentiometer is a knob that you can turn to change resistance. In electronics, itโ€™s often used to adjust values like volume, brightness, or speed. By turning the knob, the potentiometer outputs a voltage that the microcontroller can read.

๐ŸŽฏ Use

In our projects, the rotary potentiometer is used to:

  • Control LED brightness.
  • Adjust motor speed.
  • Provide manual input to the robot (like a dial).

๐Ÿ‘‰ Think of the potentiometer as the robotโ€™s volume knob โ€” you turn it, and the robot changes something.

Module parameters

Pin name Description
G GND (Power Input Negative)
V VCC (Power Input Cathode)
S Analog signal pins
  • Supply voltage: 3.3V/5V
  • Connection: PH2.0 terminal wire
  • Installation method: double screw fixing

๐Ÿ–ฅ๏ธ Code Explanation

import machine

value = 0
adc4 = machine.ADC(machine.Pin(4))       # Potentiometer connected to pin 4
pwm25 = machine.PWM(machine.Pin(25))     # LED or motor connected to pin 25
pwm25.freq(1000)                         # PWM frequency set to 1000 Hz

while True:
    value = adc4.read()                  # Read potentiometer value (0โ€“4095)
    pwm25.duty(value)                    # Set PWM duty cycle to match value

Step by Step

  1. adc4 = machine.ADC(machine.Pin(4)) โ†’ Reads the potentiometerโ€™s voltage (analog input).
  2. pwm25 = machine.PWM(machine.Pin(25)) โ†’ Sets up PWM output on pin 25 (to control LED or motor).
  3. pwm25.freq(1000) โ†’ Sets PWM frequency to 1000 Hz (smooth control).
  4. while True: โ†’ Loop that repeats forever.
  5. value = adc4.read() โ†’ Reads the potentiometerโ€™s position (0โ€“4095).
  6. pwm25.duty(value) โ†’ Adjusts LED brightness or motor speed based on knob position.

๐Ÿ‘‰ Together, this program makes the LED or motor respond directly to the potentiometerโ€™s rotation.


โœ… Conclusion of the Test

  • If turning the potentiometer changes the LED brightness or motor speed, the program is working correctly.
  • This test shows how the robot can read analog input and control output with PWM.
  • Later, the potentiometer could be used to adjust robot speed, sensor sensitivity, or even menu navigation on a display.
On this page