To read in analog voltage signal we will use a potentiometer connected to the analog pin A0 of the arduino uno board. By varying the potentiometer the analog pin A0 will sense different analog voltage. This is internally converted to digital sampled signal by Arduino. Then we can print out the analog signal values.

Hardware setup for Reading analog voltage with Python using Arduino

The following is the schematic diagram for connecting 10KOhm potentiometer with the Arduino pin A0.

schematic diagram for reading analog signal

The actual hardware is shown below.

Reading analog voltage with Python using Arduino

As you can see the center pin(yellow wire) is connected to the analog pin A0. The ground(black) and the red wire are connected to the ground and 5V supply on the arduino board via the breadboard.

Python Programming for reading analog signal using Arduino

In order to program Arduino using python programming language, you should have the pyFirmata and pyserial library installed. If you don’t know how to setup python for programming Arduino see the tutorial Programming Arduino using Python.

Then in your Python program editor type the following python program. Here spyder IDE is used.

from pyfirmata import Arduino, util
from time import sleep
import os

board = Arduino('COM3')
sleep(5)
it = util.Iterator(board)
it.start()

a0 = board.get_pin('a:0:i')

try:
while True:
v = a0.read()
print(v)

except KeyboardInterrupt:
board.exit()
os._exit()

Video demonstration of Reading analog voltage with Python using Arduino

The following video demonstrate this tutorial.

So in this way you can read analog voltage signal using Python programming language and Arduino. This is similar to the tutorial Real Time Oscilloscope using Simulink and Arduino where we used Simulink to acquire analog signal using Arduino and displayed on the time scope in simulink. Also you can use matlab programming language to read analog signal, see Real-Time data acquisition from Arduino to Matlab for this. Lastly the other option is to use the native arduino programming language to do the same, see this tutorial how to read analog signal with Arduino.

Like what you read? Give eewriter eestuffs a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.