The CircuitPython analogio
module has many applications. You can set up an analog input with a potentiometer connected to an analog input pin on your board.
Necessary Hardware
You'll need the following additional hardware to complete the examples on this page.


- JST-SH signal to potentiometer wiper (white wire)
- JST-SH 3.3V to potentiometer positive (red wire)
- JST-SH GND to potentiometer ground (black wire)
Reading the Potentiometer
In the example below, click the Download Project Bundle button below to download the necessary libraries and the code.py file in a zip file. Extract the contents of the zip file, open the directory CircuitPython_Templates/analog_voltage_values/ and then click on the directory that matches the version of CircuitPython you're using.
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries # SPDX-License-Identifier: MIT """CircuitPython analog voltage value example""" import time import board import analogio analog_pin = analogio.AnalogIn(board.A0) def get_voltage(pin): return (pin.value * 3.3) / 65535 while True: print(get_voltage(analog_pin)) time.sleep(0.1)
In the editor window in your browser, click the Open button to view the file dialog. Then, click the Upload button and select Upload Files.
You'll be asked if you want to overwrite the previous code.py with the new code.py file from the Project Bundle. Click OK.
You'll see a new code.py file appear in the file browser. Select it and click Open to view it in the code editor.
You'll see the analog input code.py file contents. Click Restart above the Serial monitor to run the analog input code.
Now, twist and turn the potentiometer. You'll see the analog voltage values print to the serial console.
Page last edited January 27, 2025
Text editor powered by tinymce.