This simple Arduino project reads values from a potentiometer and displays them in the Serial Monitor. It includes a Python script for data collection and visualization.
- Arduino Uno (or compatible board)
- Potentiometer (any value, typically 10kΩ works well)
- Jumper wires
- USB cable for Arduino
- Connect one pin of the potentiometer to 5V on the Arduino
- Connect another pin to Analog pin A0 on the Arduino
Arduino Uno Potentiometer
----------- -------------
5V -------- Pin 1
A0 -------- Pin 2
For more stable and reliable readings, consider using the standard three-wire configuration:
- Connect one outer pin of the potentiometer to 5V on the Arduino
- Connect the other outer pin to GND on the Arduino
- Connect the middle pin (wiper) to Analog pin A0 on the Arduino
Arduino Uno Potentiometer
----------- -------------
5V -------- (+) Pin 1
GND -------- (-) Pin 3
A0 -------- (W) Pin 2 (Middle/Wiper)
- Connect the Arduino to your computer via USB
- Upload the sketch to your Arduino
- Open the Serial Monitor (Tools > Serial Monitor)
- Set the baud rate to 9600
- Turn the potentiometer knob to see the values change in real-time
The Serial Monitor will display:
- Raw analog value (0-1023)
- Calculated voltage (0-5V)
These values update every 500 milliseconds.
The included Python script (script.py
) provides advanced data collection and visualization capabilities.
pip install pyserial matplotlib
python script.py
The script will automatically detect your Arduino port and start collecting data.
python script.py --port /dev/ttyUSB0 --baud 9600 --output my_data.csv --plot
--port
: Specify the serial port manually (e.g., COM3 on Windows, /dev/ttyUSB0 on Linux)--baud
: Set the baud rate (default: 9600)--output
: Specify a custom output filename (default: potentiometer_data_TIMESTAMP.csv)--plot
: Enable real-time plotting of voltage readings
The script saves data in CSV format with the following columns:
- Timestamp: Unix timestamp of the reading
- Elapsed Time (s): Time in seconds since data collection started
- Voltage (V): Voltage reading from the potentiometer (0-5V)
When using the --plot
option, the script displays a real-time graph of voltage readings over time. The graph automatically adjusts to show the most recent 30 seconds of data.
Press Ctrl+C
in the terminal to stop data collection. The script will display a summary of the collected data before exiting.