Design a voltmeter with the raspberry pi board and voltage sensor


Design a voltmeter with the raspberry pi board and voltage sensor


This project introduces how to design a voltmeter through the raspberry pi board and voltage sensor , and get the detected data on terminal.


The Component Parts

Raspberry Pi 3
voltage sensor x1
Analog to Digital Converter (ADC) x1
Breadboard x1
Jumper wire(male to male)


Jumper wire(female to female) some


According to resistance divider, the voltage sensor can decreased the voltage to one fifth of the primary voltage. As the working voltage of raspberry pi is 3.3V, you had better input the voltage less than 16.5V (3.3 x 5 = 16.5V).

The output interface of voltage sensor should connect “+” to 3.3V,”-” to GND,”S” to the AD output of ADC. At the other end of voltage sensor, the anode to VCC and  the cathode to GND.

As only the digital signal can be processed by raspberry pi, we need to add a analog to digital converter (ADC) to process the analog signal from voltage module. MCP3008 as ADC chip is very common and recommended highly.



You could choose to connect the raspberry pi to monitor, or login in pi via SSH.

1)Write the code

1)enter the following command to create a new file named and save this file at direction: /home/pi, and then press enter

sudo nano

Enter the sample code in new file, the code can be got by executing shell commands.

sudo wget --no-check-certificate

2)Run python program

sudo python ./

3) Test

Connect the DC port to power supply less 16.5V, the monitor would show the voltage value. For example,you will get the value of 3.29V with the a little allowable error when it connect to 3.3v power supply.


About the Author

amber administrator

11 Comments so far

johnkymPosted on  5:19 pm - Aug 1, 2018

Thanks for your post it was helpful.
However i found i kneaded to give everyone full access to make it work

sudo chmod a+x
sudo chmod a+w

before downloading the file contents.
but great example it helped me a lot.

smemailPosted on  2:45 am - Dec 29, 2018

good morning. i need help. i want print a screen a real voltage, i want measure a voltage range 11- 15 volt and visualize this voltage. is possible?

dinklebergPosted on  11:24 am - May 30, 2019

in the paragraph “Hardware” you say you can lower the voltage to a fifth. I want to measure up to 65 volts. I can easily use a bigger resistor, can’t I? Is there any reason you are so specific?


ashaPosted on  7:31 am - Nov 7, 2019

I am confused on how to test this? What is the set up?

ECE@2019Posted on  11:28 pm - Jan 7, 2020

Please provide the code for the circuit please it’s very urgent

jescobarPosted on  4:13 pm - Oct 8, 2020

Hi, I follow the instructions and it worked. However, I’m trying to use 2 voltage sensors at the same time and doesn’t work. I connect the 2nd sensor in CH1 and it’s like it is reading from CH0. Both give the same reading. I did a copy of the file, changes de channel value and the same results. What I’m missing here?

    FN LNPosted on  11:18 am - Nov 20, 2020

    Jescobar, To do two channels with the ADC, it matters what order the python statements are done. Once CS is set low, you can only do one channel. To do the next channel, you need to finish with the first, then initiate the second channel separately.

FN LNPosted on  11:16 am - Nov 20, 2020

On the voltage divider circuit, 3.3v is not used. The center pin “+” is not connected to anything on the circuit board, so it is not necessary. Also, the ADC input is connected to the “S” pin, but that is ~not~ the center pin. Text correct, diagram wrong.

FN LNPosted on  8:43 pm - Nov 23, 2020

In the python code, 12 bits are read and then the last bit is discarded with a shift-right. This is not necessary. Just read in 11 bits and then don’t do the shift. Results are the same.

You must be logged in to post a comment