In this tutorial, we will design a digital voltmeter using a 7-segment display and pic microcontroller. Usually, we use LCDs to display sensor data. In the last tutorial, we designed a DC digital voltmeter with a 16×2 Liquid crystal display. But in this post, instead of using LCD, we will use a four-digit 7-segment display to print voltage value. We will use the ADC module of PIC16F877a microcontroller to measure DC voltage.

Components Required

PIC16F877A Microcontroller

4-digital Seven Segment Display

Resistors

Crystal Oscillator

Capacitors

NPN transistors

Digital Voltmeter with 7-segment display circuit diagram

A picture below shows the circuit diagram of DC voltmeter with four digit seven-segment display and voltage divider circuits interfacing with PIC16F877A microcontroller. But you can use any other pic microcontroller also.

How to measure DC voltage?

Firstly, lets discuss do we need to use a voltage divider circuit. The simple and basic reason to use voltage divider circuit is that pic microcontroller operating voltage is between 0-5 volts. Hence, built-in ADC module of PIC16F877A microcontroller can read analog signal in the range 0 to 5 volts only. Therefore, in order to measure dc voltages higher than this level, we need come up with a solution to step down input voltage. This is the reason a voltage divider circuit is required in this project.

A voltage divider circuit as its name suggests divides the voltage between across two resistors. As you can see from the above circuit of dc voltmeter, we used two resistors

R9 = 180K
R7 =20k

The formula of voltage divider is very simple that is

VOUT = (R7/(R7+R9) x VIN)

For example, if input voltage is 19 volts, the output voltage will be:

VOUT = (20k/(20k+180k) x 19) = 1.9 volts

1.9 volts is less than 5 volts. Therefore, we can measure this voltage with ADC of PIC16F877A microcontroller. If you see from the voltage divider formula, the voltage step down or reduction factor is 20/200 = 1/10

Step down factor = 1/10

We can use this reduction factor in our programming to get actual voltage by measuring only the output voltage of voltage divider. We will measure step -down voltage that is the output of voltage divider circuit. But, inside our program, we will multiply measured voltage value with the reduction factor to get actual value of input voltage.

We used analog channel AN0/RA0 of PIC16F877A microcontroller. We have already post a guide on how to use analog digital module of Pic Microcontroller, you can read this post:

Connection with 4-digital seven-segment device

As you know that there are two types of 7-segment displays: namely common anode and common cathode type. We will use a common cathode type 4-digit device to display measure voltage value.

Connect PORTD with A-g pins of 4-digital seven-segment display using 330ohm current limiting resistors. Also connect RB0-RB3 pins of PORTB with control pins 1-4 of display device. Same data lines are used to send binary pattern to each digit of display device, but control lines select that at which place (7-segment) we want to display a digit.

To explore further on 7-segment displays interfacing with pic microcontrollers, go through these in-depth guides:

Digital voltmeter with 7-segment display Simulation

This circuit is simulated with proteus. As you can see, we connect a 50 volts DC source with a voltage divider circuit through a variable resistor. We use this variable resistor to apply a variable voltage to the circuit.

We can observe the same voltage on a 4-digit seven-segment device according to the input voltage variation.

MikroC Code

This code is written using MikroC for Pic compiler. Create a new project with MikroC compiler by selecting PIC16F877A microcontroller and set frequency to 8MHz. If you don’t know how create new project in mikroC, we suggest you read this post:

MPAB XC8 Code

After creating a new project, set configuration bits by generating configuration bit file with MPLAB XC8. While generating this file, select the HS crystal option and leave the remaining setting as to default settings.

Hi. Just very quickly sifted through this, but found it somewhat uninteresting since it has “only” 4 digits. Is there any tip of any micro processor that has higher resolution, as a build I mean, so that it might have, 5 or 6 digits instead?

I think many would find such a build very interesting, but it’d, of course, had to be reliable too. I’d like to have one that can measure more finite than these cheap-o-meter out there, but I don’t feel like paying multiple digits, in cash that is.

I noticed that the input is very rudimentary on this build, and I can only imagine that a real one would have, besides low tolerances on the components, also have more sophisticated setup of components.

It is just for a demo purpose. To make better and practical design, we can use a shift register like 74HC595 and I2C communication to display data. By using a shift register like 74HC595 we can achieve same result with microcontroller three pins only.

Yeah, I know that, but I was more interested in the micro controller and input-circuitry. I don’t know how high resolution this particular controller has, but I’d imagine 10 bit as most has. Sure you could use an external ADC with high resolution like, I dunno, 16-24 bit, but this is a bit over my knowledge when it comes to hooking the stuff up (Seem to always be some weird connections by some strange components, some filtering-caps and whatnot) as well as programming, I’m sort of semi-lost.

I haven’t even used any PIC yet, only some small-time projects with ATMEGA, apart from my washing machine (re)build which incorporates a 2560 with tons of sensors and output to 3-phase motor-controller and lots of other stuff. Haven’t started programming that yet, but it’ll be an hell of a challenge!