# Digital voltmeter using pic microcontroller

In this project, digital voltmeter using pic microcontroller is designed. Digital voltmeter using pic can read voltage from  0-40 volt. This voltmeter can read only DC voltage. Digital AC voltmeter can also be designed using microcontrollers. Digital DC voltmeter is designed to measure DC voltage using PIC16F877A microcontroller. Voltage divider circuit is used to divide voltage into two parts. To prevent more than 5 volt appearing across pic microcontroller Because microcontroller can not read voltage more than 5 volt directly. Liquid crystal display is interfaced with the microcontroller to display measured voltage value.  Built-in analog to digital converter of pic microcontroller is used to measured analog voltage.

Before going further in this article about digital voltmeter using pic controller, you should know how to interface LCD with pic16f877A microcontroller and how to use analog to digital converter module of pic microcontroller. If you don’t know read following articles first:

### Circuit diagram of digital voltmeter using pic microcontroller

circuit diagram of digital voltmeter using pic microcontroller is given below. 40 volt battery is used as q source whose voltage you want to measure. PIC16F877A microcontroller can not directly read 40 volt. Voltage divider circuit using resistor is used to step down dc voltage appearing across analog to digital converter pin of PIC16F877A microcontroller.

### How to measure voltage with pic microcontroller

Resistor R1=18k and R2=2k is used as voltage divider. According to voltage division formula, voltage less than 5 volt appear across pic microcontroller in the case of maximum input voltage 40 volt.

Vout = (R2 / R1+R2 ) * Vinput

Vout = ( 2 / 18+2) * 40 = 4 volt

Hence at maximum input voltage of 40 volt, only 4 volt appear across pic microcontroller which is less than 5 volt. PIC16F877A microcontroller has seven analog to digital converter channels. It’s means it can be interfaced with seven analog channels or it can measure seven analog quantities. In this project AN0 channel of pic16F877A microcontroller is used. ADC module of pic microcontroller converts analog signal into binary numbers. PIC16F877A microcontroller have 10 bit ADC. So it converts analog signal to 10 bit digital number which can be back converted into voltage using following calculation in programming of digital voltmeter. resolution is important to discuss here. resolution means value for which ADC increment by one. For example pic16f877A microcontroller have 10-bit ADC and it counts binary from 0-1023 for every minimum analog value of input signal. This minimum analog value is called resolution.ADC increment by one. For example pic16f877A microcontroller have 10-bit ADC and it counts binary from 0-1023 for every minimum analog value of input signal. This minimum analog value is called resolution.

Resolution = (Vrer+ – Vref-) / (1024 -1 ) ;

In this project we are taking Verf+= 5 volt and Vref- = 0 volt . Hence by using these values in above formula:

resolution = (5 – 0 )/ (1023) = 4.8876 mV;

It means for every analog signal of 4.87mV, ADC value increments by one. Liquid crystal display is used to display values of voltage. As shown in figure below. Below diagram shows the result of digital voltmeter using pic microcontroller and LCD display.

### Digital voltmeter using pic program

Now lets discuss how to write program for digital dc voltmeter using pic microcontroller. Above I have discussed function of each components and its working in dc voltage measurement with pic microcontroller. Code for digital voltmeter is written using Mikro C  pro compiler. voltage measured by ADC module of PIC16F877A microcontroller can be calculated by following programming commands:

voltage = (voltage * 5 * 10)/ (1024); resolution factor and voltage divider factor
Statement one is used to read ADC value and stores its value in variable voltage and in second statement voltage value is multiplied with resolution factor and voltage divider factor to convert it into input voltage value.

[sociallocker]

sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
float voltage;
char volt[4];
void main() {

PORTA = 0;
TRISA = 0X01;
PORTB = 0;
TRISB = 0;
LCD_Init();
LCD_Cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1, 1, “Digital voltmeter”);
delay_ms(1000);
while (1)
{
voltage = (voltage * 5 * 10)/ (1024);
inttostr(voltage,volt); // it converts integer value into string
Lcd_Out(2,1,”Voltage = “);
Lcd_Out(2,11,Ltrim(volt));
Lcd_Out(2,13,”Volt”);
}
}

[/sociallocker]

This digital voltmeter using pic can read voltage only between 0-40 volt. High voltage measurement voltmeter can also be designed using pic microcontroller and difference amplifier. Difference amplifier will be used to step down dc voltage instead of voltage divider.

You may also check:

1. Rajib May 9, 2015
2. Rajib May 9, 2015
• BILAL Malik May 10, 2015
3. faiz May 10, 2015
• wan aizat August 13, 2015
4. Lakindu Sandaru August 1, 2015
• BILAL Malik August 1, 2015
5. Newbie243 August 5, 2015
6. bob August 6, 2015
7. Mohammed Aljohani November 8, 2015
8. Ali Khan December 10, 2015
9. Shameem February 21, 2016
10. Mohamed February 26, 2016
11. Yassine Attia May 3, 2016
12. Eric September 15, 2016
13. raj October 30, 2016
• BILAL Malik October 30, 2016
14. Indra November 15, 2016
15. Saad mehmood January 25, 2017
16. rahul March 3, 2017
17. circuit March 11, 2017
18. Harendra singh April 9, 2017
19. Stam May 13, 2017
20. Stam May 13, 2017
21. abubakar saleh June 15, 2017
22. Stamatis July 6, 2017
23. BM September 8, 2017
24. Rajni Singh October 17, 2017