Voltmeter and Ammeter using PIC Microcontroller


Voltmeter and Ammeter can be easily made using PIC Microcontroller having ADC (Analog to Digital Converter). I am using PIC16F877A and the result is displayed on an LCD Display. PIC16F877A is enough if you do this project only for testing purposes. I suggest to use PIC with low pin numbers and multiplexed 7 segment display if you wish to use this as your measuring instrument.

If you don’t know the basis of PIC ADC and LCD Interfacing please read the following articles.

ADC module of PIC Microcontroller converts the Signals on its analog pin to 10 bit binary data and it has software selectable high and low voltage reference input to some combination of VDD, VSS, RA2 and RA3. The analog input to PIC is limited to VSS and VDD voltages (0 – 5V) of PIC.

This circuit is designed to measure 0 to 30V. So we will map 0 to 30V to 0 to 5V by using a voltage divider. Current through a circuit can be measured by introducing  a 1 ohm resistor and measuring the voltage across it. To minimize the path resistance we will use .47 ohm special resistor with fuse (shown in figure) and current is calculated. Voltage and Current Sampling circuit is shown below.

When the Input voltage is 30V (max) the voltage across 20K ohm resistor becomes 5V which is feedback to the analog pin RA2 of the PIC Microcontroller.

The voltage across .47 ohm resistor is also feedback to the analog pin RA3 via 100K ohm resistor. 5.1V Zener Diode is added in parallel to these analog input pins to protect PIC from over voltages.

The ADC module of PIC converts analog input to 10 bit digital number. We want to convert this digital to corresponding voltage in decimal.

0v  =  0 0 0 0

5v  =  1  1  1  1

Resolution = (Vref+ – Vref-)/(1024-1)   (as it is 10 bit ADC)

= 5/1023

= 4.887 mV

Thus it means that for a change in 4.887mV, the binary output changes by 1.

So voltage input to the analog pin of PIC can be calculated as follows…

v = ADC_Read(2);  // ADC value of channel 2 (voltage)
i = ADC_Read(3);  // ADC value of channel 3 (current)
V = v*4.89;       // Converting ADC value to mV
I = i*4.89;       // Converting ADC value to mV

By using values V and I we can calculate the Input Voltage and Current across the Load (Connected across Output terminals).

Voltage across 20K resistor = V

Current through 20K = V/20K

Input Voltage = Current through 20K * 120K  (Current flowing to PIC can be neglected)

Thus,

V = (V/20)*120;

Voltage across 0.47 ohm resistor = V

Current through Load = Current through 0.47 ohm resistor = V/0.47

Thus,

I = I/0.47;

To display the results in LCD Display we need to convert these readings into string, we use the user defined function look() for it. It converts each digit in the reading to corresponding character (see the source code).

Circuit Diagram

Note: VDD and VSS of the pic microcontroller is not shown in the circuit diagram. VDD should be connected to +5V and VSS to GND.

 You can download the hex file, MikroC source code, Proteus files etc here…
Voltmeter and Ammeter using PIC Microcontroller




You may also like...

  • ezugi

    thx you is very good!!!

  • Njanani791992

    i cant download this file.. please help me..

  • http://www.electrosome.com/ Ligo George

    You must login to download the file…
    You can login or register here: http://www.electrosome.com/wp-login.php

    Download Link: http://www.electrosome.com/wp-content/plugins/download-monitor/download.php?id=5

  • seahorse

    current reading is not showing..
    do i have to connect load across the output terminal for it ?
    plz answer briefly..

  • http://www.electrosome.com/ Ligo George

    Yes you must connect Load………No Load current is Zero.

  • kevin

     is that possible for me to make also a digital ohmmeter? ranges from 30 ohms up to 1M ohm? iam hoping that you can help me. thanks!

  • http://www.electrosome.com/ Ligo George

    Yes it is possible………Apply a known voltage to the unknown resistor and find the current through that resistor………..Then we can easily calculate the unknown resistor…………..

    For measuring currents up to 1M ohm, you may need to change the +Vref & -Vref of the PIC ADC………..

  • kevin

    can i also use the Voltage Divider principle for that ? like in your circuit?. sir with your permission can i use your schematic diagram up there to build my digital ohmmeter?.

    how about changing the +Vref and -Vref?  instead of 5v i will change it to > or < 5v?. thank you sir!

  • Yo3lnugraha

    cool project…how much maximum amp input?

  • http://www.electrosome.com/ Ligo George

    Yes .. of-course

    The min voltage PIC ADC can measure when -Vref = 0 and +Vref = 5 is (5-0)/1023 = 0.0049……

    When a 5V is applied to a 1M ohm resistor..
    current = 5/1M = 0.000005

    So we can’t measure this current because the voltage produced by this current is very less than the min voltage that PIC ADC can measure…

    So you must adjust +Vref to a lower value………

    Note: You can’t adjust +Vref above 5V…….

  • http://www.electrosome.com/ Ligo George

    You can adjust the max current by varying the circuit and program……..

    In this circuit it is about 10A……

  • kevin

    so you mean to say i will use 5v lower ? 4v? 3.5v? sir can you help me how to declare it. or how can i deal with it in the complier(“mikroc”)?. thank you sir!

  • http://www.electrosome.com/ Ligo George

    Please refer the datasheet of particular pic you are dealing with………….

    Go to Analog to Digital Converter section..

    Read it and set the ADCON1 register according to your needs…..

    When ADCON1 = 0×88

    Voltage at pin AN3 is the Vref+ and voltage at pin AN2 is the Vref-

  • Kevin

    Sir if I may ask can you please send me a sample code for digital ohmeter?

  • http://www.electrosome.com/ Ligo George

    I think it is better to use Wheatstone bridge to find unknown resistance. In this case you need’nt change the +Vref,,,,,,,,,,,,,,instead of you can change the known resistors in the Wheatstone bridge according to the range of resistances you want to measure…..

  • kevin

    sir we dont have a problem with our circuit, but our problem is coding, if you could please make a sample code for us it would be a big help.

  • http://www.electrosome.com/ Ligo George

    Circuit is a problem………….

    Use a potential divider to find unknown resistance………..
    Connect unknown resistance in series with a known resistance………You may change the known resistance according to the range of Unknown resistance to be measured.

    Then by reading voltage across unknown resistance we can easily calculate unknown resistance………

    In MikroC you can use the same expressions as in C…….

  • kevin

    sir using this:

    VCC=5V
    R1=known resistance or(fixed R1)
    R2= unknown or to be measured
    v= adc value * 4.89

    from:

    v=(R2*VCC)/(R1+R2)

    i will find R2

    after rearranging the equation

    it will come up like this sir:

    R2=(v*R1)/(VCC-V)

    so sir. can i directly put this equation in mikroC compiler?

    how about the declaration in mikroC sir?. thank you sir!

  • http://www.electrosome.com/ Ligo George

    Yes you can put that equation in mikroC…
    Note that actual voltage is adc value * 0.00489 …
    I used 4.89 to minimize the floating point calculations…..

    Declarations are similar to C…
    int variable_name;
    float var_name;
    short var_name;
    etc………

  • kevin

    can you explain this part sir i get confused with this:

    volt[0] = look(v/10000);       volt[1] = look((v/1000)%10);       volt[3] = look((v/100)%10);       Lcd_Out(1,1,”Voltage = “);       Lcd_Out(1,11,volt);       Lcd_Out(1,16,”V”);

  • http://www.electrosome.com/ Ligo George

    I use those steps for converting integer to string to be displayed in the LCD………….You needn’t bother about it use inbuilt functions of mikroC such as FloatToStr() , IntToStr()
    to convert numbers to corresponding string…

  • kevin

    sir this is my code in my digital ohmmeter. i hope you can help me with this….

    // LCD module connections sbit LCD_RS at RC4_bit; sbit LCD_EN at RC5_bit; sbit LCD_D4 at RC0_bit; sbit LCD_D5 at RC1_bit; sbit LCD_D6 at RC2_bit; sbit LCD_D7 at RC3_bit; sbit LCD_RS_Direction at TRISC4_bit; sbit LCD_EN_Direction at TRISC5_bit; sbit LCD_D4_Direction at TRISC0_bit; sbit LCD_D5_Direction at TRISC1_bit; sbit LCD_D6_Direction at TRISC2_bit; sbit LCD_D7_Direction at TRISC3_bit;// End LCD module connections// Define Messages

    void main() { char message1[] = “DIGITAL OHMMETER “; char *temp = “0000000″; unsigned int v,R1,R2,VCC;  TRISC = 0; // PORTC All Outputs  TRISA = 0b000011; // PORTA All Outputs, Except RA3 and RA2    Lcd_Init();                      // Initialize LCD  Lcd_Cmd(_LCD_CLEAR);             // CLEAR display  Lcd_Cmd(_LCD_CURSOR_OFF);        // Cursor off  Lcd_Out(1,1,message1);           // Write message1 in 1st row  do {  ADCON1 = 0×00;  VCC=5000;  R1=10000;  v = ADC_Read(1);  R2=((v*4.89*R1))/VCC-v*4.89;     temp[0] = (R2/1000000)+48; // Add 48 to get the ASCII character value   temp[1] = ((R2/100000)%10) + 48;   temp[2] = ((R2/10000)%10) + 48;   temp[3] = ((R2/1000)%10) + 48;   temp[4]=  ((R2/100)) %10+48;   temp[5] =  (R2%10)%10 + 48;   temp[6] =  R2%10 + 48;   Lcd_Out(2,7,temp);   Delay_ms(400);  } while(1); }

    we are encountering problems in displaying it in the LCD. because for example our. R1(fixed)=10000 ohms and our R2(to be measured)=5k ohms. in the display it shows only. less than the desired value..

    i will send our ckt diagram in your email sir. because we have problems in uploading the image here. thanks sir!

  • http://www.electrosome.com/ Ligo George

    Ok mail me the circuit diagram, program, Proteus files etc……..i will check it.

  • kevin

    ill just add you sir in your facebook and maybe ill send the schematic there because in email it fails. thank you sir!

  • http://www.electrosome.com/ Ligo George

    You may use our new forums………..

  • Palanee64

    voltmeter and ammeter can i know the crystal frequency
    thx 

  • http://www.electrosome.com/ Ligo George

    8Mhz……

  • B Tserentogtoh

    Current through 20K = V/20K its may false syntax, maybe its I=V/20k

  • Ligo George

    Using PIC microcontroller we will read the voltage across 20K resistor, then the current through it can be calculated by dividing it with 20K…………
    Then the input voltage can be calculated easily by multiplying current through 20K ohm resistor * 120K

  • Pradip

    I couldn’t find frequency of the crystal X1 used in your circuit. Would youl let me know that ….?

  • Ligo George

    I used 8Mhz……you can use 4 or 8 or 20….

  • Pradip

    Thanks a lot for your quick response.

  • Pradip

    I built this circuits and thanks. However, following are my observations:-
    1) For higher amp it reads data properly (e.g. higher than 500mA), but for values lower than 50mA it does not show the correct conversion/ reading
    2) Also ADC pin reading are not stable and changes upto +/-3 times, where as load/amp has not been changed
    3) I also found that PIC ADC cannot read value below 20 mV and if voltage at ADC pin is lower than it shows output 0 (Zero).
    4) also lower amp value shows slightly lower and higher amp values show slightly higher

    Thanks.

  • http://www.electrosome.com/ Ligo George

    You may use a small value capacitor (0.001uF) parallel to reduce voltage fluctuations ……… Change the +Vref & -Vref according to voltage that to be converted to digital to increase the accuracy of the adc conversion.

  • laurent

    hello
    I am French and would like to get into this project before but I want to know what tolerence in% and W for resistance R1, R2, R3
    1% 0,6 W?
    thank you

  • http://www.electrosome.com/ Ligo George

    You can use 1/4 watt resistors for R1, R2, R3. Better to use resistors of tolerence 1%. After completing the project measure the value of R1 & R2 and change the program accordingly for accurate results..

  • akshay

    what if i operate ic MCU with Vss as 5v and Vdd as 10V

  • akshay

    what if, I operate Pic MCU with Vss as 5v and Vdd as 10V ???

  • http://www.electrosome.com/ Ligo George

    It will work normally…………. Note: The GND of both power supplies should be connected…

  • adil

    i did not understand the current calculations
    can you please elaborate
    thank you

  • http://www.electrosome.com/ Ligo George

    That means you understand voltage calculation…………

    Current through 0.47ohm resistor is calculated from the voltage across it…..just ohms law…

  • Jim

    how to download the hex file, MikroC source code?

  • http://www.electrosome.com/ Ligo George
  • Jim

    i already registered and login

  • http://www.electrosome.com/ Ligo George

    After login click on the download link……. or go to this link

    http://www.electrosome.com/wp-content/plugins/download-monitor/download.php?id=5

  • Kalpesh

    Hello sir,

    i have made this great Digital Meter + Ammeter. But as soon as i finished programming it with my Pickit3 the values of current and voltage are dancing/fluctuating randomly and its not measuring any value… could u tell me what could be the reason ?

  • http://www.electrosome.com/ Ligo George

    Could you please elaborate?

    What type of voltage and current ??

  • kalpesh

    I mean to say the values display on LCD keep on fluctuating without connecting any measurement…so what could be the reason ?

  • http://www.electrosome.com/ Ligo George

    Try after grounding the inputs….
    did you change the program?

  • kalpesh

    yes, its working fine i forgot to ground both circuits :p

  • Carl Victor

    hello sir, i can’t download the hex file, mikroC and proteus files cause i can’t register
    would you help me?

  • http://www.electrosome.com/ Ligo George

    Please elaborate the problem……

    Go to this link to register : http://www.electrosome.com/wp-login.php?action=register

  • Carl Victor

    i did

    but still there is no password emailed

  • http://www.electrosome.com/ Ligo George

    Your username and mail id?

  • Carl Victor
  • http://www.electrosome.com/ Ligo George

    I think this mail id is not valid because I can’t sent mails to it..

  • http://www.electrosome.com/ Ligo George

    Nop… because PICs are different…. for using this circuit.. you may modify my program…

  • Argon

    Hi! can you please explain in depth what resistors R3 and R4 do? For example, if the input voltage is 30volts on the .47ohm resistor, wouldnt that make the current 63 amps?! wouldnt that fry the micro controller?

  • http://www.electrosome.com/ Ligo George

    Nop, 0.47 ohm resistor is connected in series with load, so current through it depends on the load resistance…. and the voltage across the 0.47 resistor is given to an analog pin of pic microcontroller..

  • Alif

    hello sir, in my Embedded course project,i must using this dspic33fj128gp802 PIC. so,which code in asm that i need to change..sorry,i’m newbie about this embedded system.hope u can help me figure i out..thanks for ur support

  • http://www.electrosome.com/ Ligo George

    Please refer the datasheet of corresponding pic…… If you want to code in asm, its datasheet will include all its instructions……

  • Alif

    hello sir,
    i using dspic33 ,in .C language,and using mikroC debugger. i have coded it but appear error at ” ADC_READ undeclared identifier”..here my code,can u explain the error why the error.hope ur reply soon.
    ===============================================================
    // LCD module connections
    sbit LCD_RS at RB5_bit;
    sbit LCD_EN at RB6_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 TRISB5_bit;
    sbit LCD_EN_Direction at TRISB6_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;
    // End LCD module connections

    char look(int a)
    {
    switch(a)
    {
    case 0:
    return ’0′;
    case 1:
    return ’1′;
    case 2:
    return ’2′;
    case 3:
    return ’3′;
    case 4:
    return ’4′;
    case 5:
    return ’5′;
    case 6:
    return ’6′;
    case 7:
    return ’7′;
    case 8:
    return ’8′;
    case 9:
    return ’9′;
    default:
    return ‘.’;
    }
    }

    void main()
    {

    unsigned int v,vp,ip,i;
    char *volt = “00.0″;
    char *current = “0.00″;
    TRISA = 0xFF;
    Lcd_Init();
    Lcd_Cmd(_LCD_CLEAR);
    Lcd_Cmd(_LCD_CURSOR_OFF);

    do
    {

    AD1CON1 = 0×00;
    v = ADC_Read(2);
    i = ADC_Read(3);
    i = (i*4.89)/0.47;
    v = ((v*4.89)/20)*120;
    if(v!=vp || i!=ip )
    Lcd_Cmd(_LCD_CLEAR);
    vp = v;
    ip = i;
    volt[0] = look(v/10000);
    volt[1] = look((v/1000)%10);
    volt[3] = look((v/100)%10);
    Lcd_Out(1,1,”Voltage = “);
    Lcd_Out(1,11,volt);
    Lcd_Out(1,16,”V”);

    current[0] = look(i/1000);
    current[2] = look((i/100)%10);
    current[3] = look((i/10)%10);
    Lcd_Out(2,1,”Current = “);
    Lcd_Out(2,11,current);
    Lcd_Out(2,16,”A”);
    Delay_ms(250);
    } while(1);
    }

  • http://www.electrosome.com/ Ligo George

    For dsPICs you should use MikroC Pro for dsPIC… google it .. you can download it and its tutorials from mikroelectronica website..

  • ShaN

    thx for this but i have a question. I have a project titled “PIC 16 analog inputs”. That’s the title, i find it vague. So i was wondering if this fits for that category. We also have to use proteus isis 7 professional to simulate. It’s purely educational it doesn’t have to be actually created as hardware. Note : i am new to this domain but i’m a fast learner.

  • http://www.electrosome.com/ Ligo George

    Yes, this comes under the title PIC 16 analog inputs… as this project uses ADC of PIC 16F877A………. You can download proteus files at the bottom of the article..

  • ShaN

    thank you so much

  • Juan

    hello sir.
    how I have to connect to measure current??

  • http://www.electrosome.com/ Ligo George

    Connect the supply voltage to input side and connect the load to output side..

  • http://www.facebook.com/marketiva.ro Marketiva Ro

    hello sir

    Can you put the pcb files in proteus ares for this ?
    thanks

  • http://www.electrosome.com/ Ligo George

    Sorry, i included the proteus isis file in the download.. kindly convert that file to ares..

  • mashal

    HI there !

    when i connect a battery through a pot at the INPUT it shows Volts on the Lcd but not the amps ! so what i am doing wrong !

    and kindly tell me the configuration settings i.e

    Oscillator , MCLR, PWRT , WDT OFF.
    regards

  • http://www.electrosome.com/ Ligo George

    use 8Mhz oscillator… connect mclr to VDD…
    ignore other settings…

    For current you should connect a load in series with 0.47 ohm resistor…

  • donleo

    Wonderfull project i want to make it thanks for it!

    I have 2 questions:

    a what kind of crystal you use
    and can i take the 5v from the same travo or do i use a second supply for the PIC ?
    Thanks

  • donleo2001

    Sorry the first question i read under, about the freq. of the crystal :-)

  • http://www.electrosome.com/ Ligo George

    8Mhz crystal…
    It is better to use a separate power supply for this circuit..

  • donleo2001

    thanks it works fine !!!!

  • donleo

    Hi , I have made this great meter but i have i small problem ow he is in my powersupply the suppl is 24 volt and 5 amp and when i have no load the current gives me 150ma the voltage is perfect what can i dot to change is to zero?
    I doint now how to change the software is there a way with a resistor or something?
    Thank and sorry for my bad english

  • elisilva

    // LCD module connections
    sbit LCD_RS at RB5_bit;
    sbit LCD_EN at RB7_bit;
    sbit LCD_D4 at RC4_bit;
    sbit LCD_D5 at RC5_bit;
    sbit LCD_D6 at RC6_bit;
    sbit LCD_D7 at RC7_bit;

    sbit LCD_RS_Direction at TRISB5_bit;
    sbit LCD_EN_Direction at TRISB7_bit;
    sbit LCD_D4_Direction at TRISC4_bit;
    sbit LCD_D5_Direction at TRISC5_bit;
    sbit LCD_D6_Direction at TRISC6_bit;
    sbit LCD_D7_Direction at TRISC7_bit;
    // End LCD module connections

    char look(int a)
    {
    switch(a)
    {
    case 0:
    return ’0′;
    case 1:
    return ’1′;
    case 2:
    return ’2′;
    case 3:
    return ’3′;
    case 4:
    return ’4′;
    case 5:
    return ’5′;
    case 6:
    return ’6′;
    case 7:
    return ’7′;
    case 8:
    return ’8′;
    case 9:
    return ’9′;
    default:
    return ‘.’;
    }
    }

    void main()
    {

    unsigned int v,vp,ip,i;
    char *volt = “00.0″;
    char *current = “0.00″;
    TRISA = 0xFF;
    Lcd_Init();
    Lcd_Cmd(_LCD_CLEAR);
    Lcd_Cmd(_LCD_CURSOR_OFF);

    do
    {

    ADCON1 = 0×00;
    v = ADC_Read(2);
    i = ADC_Read(3);
    i = (i*4.89)/0.235;
    v = ((v*4.89)/20)*120;
    if(v!=vp || i!=ip )
    Lcd_Cmd(_LCD_CLEAR);
    vp = v;
    ip = i;
    volt[0] = look(v/10000);
    volt[1] = look((v/1000)%10);
    volt[3] = look((v/100)%10);
    Lcd_Out(1,1,”Voltage = “);
    Lcd_Out(1,11,volt);
    Lcd_Out(1,16,”V”);

    current[0] = look(i/1000);
    current[2] = look((i/100)%10);
    current[3] = look((i/10)%10);
    Lcd_Out(2,1,”Current = “);
    Lcd_Out(2,11,current);
    Lcd_Out(2,16,”A”);
    Delay_ms(250);
    } while(1);
    }

    error in compiling

    2:0 11 ‘;’ excepted but LCD_RS found
    2:0 12 Internal error
    I need help to on this file i used MikroC 8.2 , i try make it to read Current 20A , since already thanks very much.
    Elionaldo.´.

  • http://www.electrosome.com/ Ligo George

    Above code is working fine with my compiler. I am using MikroC Pro 5.8.0
    I think you are using MikroC…. Use MikroC Pro..

  • eli silva

    Good evening Thanks very much the friend Ligo George , i tried use too MikroC PRO 5.8.0 but don’ works, if possible you help me i need ready 40V 30A , possible compiler for me , since already thanks very much one more time , have great hug from Brazil.

    Elionaldo.´.

  • eli silva
  • http://www.electrosome.com/ Ligo George

    It is compiling fine in my pc… Create a new project and copy paste the code. Then try to compile
    ..

  • Vanja Halulic

    Hi my friend.
    I have made this very nice VM-AM, but the HEX file is wrong.
    Please would you like to send me new hex file.
    Best Regards
    Vanja

  • http://www.electrosome.com/ Ligo George

    It is the correct hex file… Note the microcontroller is PIC 16F877A not PIC 16F877 ..

  • Vanja Halulic

    Hi, my friend L George.
    Thanks from replay. O yeah the pic is PIC16F877A and hex does not works. Crystal is 8MHz.
    My friend I am bad programmer and I do not know to make HEX file, but I am electronic engineer. I do not have any problem to make PCB and I made it. But hex file make me solid problem. Please would you like to send me one time again that hex file.
    Best Regards my friend L George and have a nice day.
    Vanja

  • http://www.electrosome.com/ Ligo George

    The hex file in the above zif folder is 100% working. Now I checked its working in Proteus ISIS. We don’t provide any wrong hex files in this website.

  • Vanja Halulic

    OK, thank you young man and have a nice day/
    Best Regards
    Vanja

  • cha

    hi if wont use this module to 230v i can use transformer and low down the voltage dc 5 but where should i change the programmer?
    do you have any tutorials about RF modules and compactors?
    thank you vary much

  • http://www.electrosome.com/ Ligo George

    It is better to decrease that offset through in program…

  • luc888

    Thank you very much!

  • antoniocarmelitolizada

    Is it possible to measure Resistance by simply dividing measured voltage v by measured current i ? I guess the only problem is that the Resistance to be measured must have a voltage across it

  • http://www.electrosome.com/ Ligo George

    Yes, you can.. In every ohm meter, resistance is measured by giving a voltage to it..

  • Vanja1404

    Hi my friend.
    Thanks from software and hardware of VM-AM whit PIC16F877A.
    I have made it Voltage is shown up correct bt the amps on 12.00V is shown 160mA without load. What did I do wrong.
    Best Regards

  • http://www.electrosome.com/ Ligo George

    It may caused due to many problems.. you just subtract the correction from the output voltage.. like zero correction..

  • manojsoorya

    The code with this report is not working. But in Proteus, Its work well. But I cant Burn the chips. But intime, I can burn other programme to the same chips. That means, the programmer and the chip are good….
    Hope your help soon..

  • http://www.electrosome.com/ Ligo George

    This code is completely working.. This is PIC16F877A not PIC16F877….. What is the error when writing the program??

  • Mridul Mohan

    sir ,
    which software using for download the program to pic……

  • http://www.electrosome.com/ Ligo George

    You need a pic programmer to write program to the pic microcontroller… The required software will depend on the programmer you are using..

  • ASequeira

    Hi great projedt1 I just have one question..what is the max. amp’s. that this circuit can read in this program ?Thanks in advance.

  • http://www.electrosome.com/ Ligo George

    You can measure up to 10A, buy you should use should increase the wattage of 0.47 fusible resistor..

  • robert

    is there a HI-tech with MPLAB IDE counterpart of this?

  • http://www.electrosome.com/ Ligo George

    Nop, but you can convert it to Hi-Tech C by just by replacing ADC functions, lcd functions and some register assigning statements.. See our Hi-Tech C LCD and ADC tutorials..

  • tasos17

    hello first of all nice work
    secondly can you help me with a project of mine?
    can i use pic16f88 instead of pic16f877? what changes would i have to make?
    how can i have a serial output? i want to send it to another pic16f628.

  • http://www.electrosome.com/ Ligo George

    I haven’t checked the datasheet of 16f88………. If it has 2 adc inputs and uart modules.. you can read voltage, current and send it serially to pic 16f628……….

    Try this link : http://www.electrosome.com/pic-to-pic-communication-uart/

  • mohannad obead

    hi i have problem the voltmeter dose not give me right reading when the input is 9 the reading is 30.9 when i test it with avometer across 20k its reads 9 but the lcd reads 30.9 … help me

  • mohannad obead

    iam using 4MHz it is ok or the problem that i found from it help me

  • http://www.electrosome.com/ Ligo George

    Does the proteus simulation worked fine???

  • http://www.electrosome.com/ Ligo George

    I used 8MHz crystal.. for using 4 MHz you should change it in mikroc project settings and rebuild it… .. and write the new hex file in the pic microcontroller..

  • tasos17

    hello do you agree with this?
    MikroC Code

    Transmitter

    void main()

    {

    unsigned int v,vp,ip,i;
    TRISA = 0xFF;

    PORTB = 0;

    do

    {

    ADCON1 = 0×00;

    v = ADC_Read(2);

    i = ADC_Read(3);

    i = (i*4.89)/0.47;

    v = ((v*4.89)/20)*120;

    if(v!=vp || i!=ip )

    vp = v;

    ip = i;

    }

    while(1);

    UART1_Init(9600); // Initialize UART module at 9600bps

    Delay_ms(100); // Wait for UART module to stabilize

    while (1)

    { // Endless loop

    UART1_Write(PORTB); // and send data via UART

    Delay_ms(500);

    }

    }

    Receiver

    void main()

    {

    TRISB = 0;

    PORTB = 0;

    UART1_Init(9600); // Initialize UART module at 9600bps

    Delay_ms(100); // Wait for UART module to stabilize

    while (1)

    { // Endless loop

    if (UART1_Data_Ready())

    { // If data is received,

    PORTB = UART1_Read(); // read the received data,

    }

    }

    }

  • http://www.electrosome.com/ Ligo George

    That code is not completely correct… I think you need to send voltage and current to second pic. .then why you are writing PORTB to UART…?? if so write voltage and current……

  • Bruno

    that’s working really good. but I would also want to know how to display only 0 to 10 V and 4 to 20 mA if you can help me with the program. Thanks in advance.

  • http://www.electrosome.com/ Ligo George

    Just change the voltage divider for sensing voltage and change the constants multiplied with the data read from adc channel..

  • Bruno

    Sir

    do I hev to change even the hex code for a 0 to 10 V and 4 to 20 mA, if so can you help me with it also with the program. im such a bad programmer.

  • Bruno

    Sir
    do I have to change even the hex code, if so can you help me with it also with the program. im such a bad programmer.

  • http://www.electrosome.com/ Ligo George

    It is very simple to change the hex file…. you just edit the mikroc program by changing the constant andthen Build the project… The new hex file will be generated automatically..

  • http://www.electrosome.com/ Ligo George

    To measure current through LED, put a 0.47 ohm fusible resistor (power rating depends of the current required for the LED…. give the voltage across that resistor to the ADC input of PIC… as given in the above circuit diagram… Note one thing, if you are using 2 power supplies, both of them should have a common ground.. as given above..

  • Preethi Shivanand

    thank you ill try this and get back to you..

  • Preethi Shivanand

    My query is related to pwm- is it possible to switch voltage levels in ton of a same duty cycle i.e. in the on time i want to divide on time of the duty cycle into 3 samples,provide (assign) three different voltages into these 3 samples -is it possible? i am reading the voltage across resistor to adc pin of uC and displaying voltage on scope thru pwm pin.pls help.

  • Bruno

    i cant find OP295A can i still use OP295GPZ or in fact, which other op amps can i replace it with

  • http://www.electrosome.com/ Ligo George

    opamp???

  • http://www.electrosome.com/ Ligo George

    Sorry, I don’t understand your question…

  • samiul.bd

    Hello Sir,
    This is a wonderful project. But I have some question.
    1. If we want to measure voltage higher then 30V (like 300V) what to do?
    2. Can we measure both AC and DC volt with this module?
    3. What is the max current that can measure by this module?
    4. If we can measure both current and voltage, we can find energy by multiplying them and display in LCD. What should be the code for doing so?
    Pls discuss.

    Best Regards

  • http://www.electrosome.com/ Ligo George

    1. Adjust the potential divider network for the required voltage range..
    2. Yes.. for measuring AC.. .first convert it to dc.. the ac voltage = dc voltage/squrt(2)
    3. Max current depends on the series resistor…here it is 5V/0.47 …
    4. Yes you can measure both voltage and current…. In DC, you can measure power by just multiplying current and voltage..

  • samiul.bd

    Thanks for the reply.

    Regards

  • Preethi Shivanand

    V = v*4.89; // Converting ADC value to mV
    SO U MEAN TO SAY THAT 4.89 IS MULTIPLIED JUST TO CONVERT THE VOLTAGE DROP TO MILLIVOLT ???

  • http://www.electrosome.com/ Ligo George

    Yes.. it just converts the 10bit ADC value to corresponding milli volt..

  • Preethi Shivanand

    is it mandate to always covert into millivolt,can i use the corresponding adc value read as my voltage value and convert it to current and use it….

  • Preethi Shivanand

    do you have any website or link which could help me understand basic sampling from volttage drop to adc,,,if yes pls provide

  • http://www.electrosome.com/ Ligo George

    for a 10bit adc of reference voltages…. 0 and 5V..

    INput —- > ADC-Output

    0 —-> 0000000000

    4.887mV—-> 0000000001

    2.5 —-> 0000011111

    5V —-> 1111111111

    So ADC output is not voltage.. it is the corresponding 10 bit digital value……

    You can convert it to any format as per your requirement…… Here for convince .. it is converted to milli volt…..

    Read this article carefully..

    Try this too..

    http://www.electrosome.com/analog-to-digital-converter-pic/

  • samiul.bd

    Sir,

    As you say I multiply current and voltage but the output gives weird. Would you pls check where I have done wrong I pest full code and output image here. I put i=10; as testing purpose.

    // LCD module connections
    sbit LCD_RS at RB5_bit;
    sbit LCD_EN at RB7_bit;
    sbit LCD_D4 at RC4_bit;
    sbit LCD_D5 at RC5_bit;
    sbit LCD_D6 at RC6_bit;
    sbit LCD_D7 at RC7_bit;

    sbit LCD_RS_Direction at TRISB5_bit;
    sbit LCD_EN_Direction at TRISB7_bit;
    sbit LCD_D4_Direction at TRISC4_bit;
    sbit LCD_D5_Direction at TRISC5_bit;
    sbit LCD_D6_Direction at TRISC6_bit;
    sbit LCD_D7_Direction at TRISC7_bit;
    // End LCD module connections

    char look(int a)
    {
    switch(a)
    {
    case 0:
    return ’0′;
    case 1:
    return ’1′;
    case 2:
    return ’2′;
    case 3:
    return ’3′;
    case 4:
    return ’4′;
    case 5:
    return ’5′;
    case 6:
    return ’6′;
    case 7:
    return ’7′;
    case 8:
    return ’8′;
    case 9:
    return ’9′;
    default:
    return ‘.’;
    }
    }

    void main()
    {

    unsigned int v,vp,ip,i,w;
    char *volt = “00.0″;
    char *current = “0.00″;
    char *watt = “00.0″;

    TRISA = 0xFF;
    Lcd_Init();
    Lcd_Cmd(_LCD_CLEAR);
    Lcd_Cmd(_LCD_CURSOR_OFF);

    do
    {

    ADCON1 = 0×00;
    v = ADC_Read(2);
    i =10;// ADC_Read(3);
    i = (i*4.89)/0.47;
    v = ((v*4.89)/20)*120;
    w = v*i;

    if(v!=vp || i!=ip )
    Lcd_Cmd(_LCD_CLEAR);
    vp = v;
    ip = i;
    volt[0] = look(v/10000);
    volt[1] = look((v/1000)%10);
    volt[3] = look((v/100)%10);
    //Lcd_Out(1,1,”Voltage = “);
    Lcd_Out(1,1,volt);
    Lcd_Out(1,6,”V”);

    current[0] = look(i/1000);
    current[2] = look((i/100)%10);
    current[3] = look((i/10)%10);
    //Lcd_Out(2,1,”Current = “);
    Lcd_Out(1,9,current);
    Lcd_Out(1,14,”A”);
    //Delay_ms(250);

    watt[0] = look(w/10000);
    watt[1] = look((w/1000)%10);
    watt[3] = look((w/100)%10);
    Lcd_Out(2,1,watt);
    Lcd_Out(2,5,”W”);

    } while(1);
    }

  • samiul.bd

    Sir,

    As you say I multiply current and voltage but the output gives weird.
    Would you pls check where I have done wrong I pest full code and output
    image here. I put i=10; as testing purpose.

    // LCD module connections
    sbit LCD_RS at RB5_bit;
    sbit LCD_EN at RB7_bit;
    sbit LCD_D4 at RC4_bit;
    sbit LCD_D5 at RC5_bit;
    sbit LCD_D6 at RC6_bit;
    sbit LCD_D7 at RC7_bit;

    sbit LCD_RS_Direction at TRISB5_bit;
    sbit LCD_EN_Direction at TRISB7_bit;
    sbit LCD_D4_Direction at TRISC4_bit;
    sbit LCD_D5_Direction at TRISC5_bit;
    sbit LCD_D6_Direction at TRISC6_bit;
    sbit LCD_D7_Direction at TRISC7_bit;
    // End LCD module connections

    char look(int a)
    {
    switch(a)
    {
    case 0:
    return ’0′;
    case 1:
    return ’1′;
    case 2:
    return ’2′;
    case 3:
    return ’3′;
    case 4:
    return ’4′;
    case 5:
    return ’5′;
    case 6:
    return ’6′;
    case 7:
    return ’7′;
    case 8:
    return ’8′;
    case 9:
    return ’9′;
    default:
    return ‘.’;
    }
    }

    void main()
    {

    unsigned int v,vp,ip,i,w;
    char *volt = “00.0″;
    char *current = “0.00″;
    char *watt = “00.0″;

    TRISA = 0xFF;
    Lcd_Init();
    Lcd_Cmd(_LCD_CLEAR);
    Lcd_Cmd(_LCD_CURSOR_OFF);

    do
    {

    ADCON1 = 0×00;
    v = ADC_Read(2);
    i =10;// ADC_Read(3);
    i = (i*4.89)/0.47;
    v = ((v*4.89)/20)*120;
    w = v*i;

    if(v!=vp || i!=ip )
    Lcd_Cmd(_LCD_CLEAR);
    vp = v;
    ip = i;
    volt[0] = look(v/10000);
    volt[1] = look((v/1000)%10);
    volt[3] = look((v/100)%10);
    //Lcd_Out(1,1,”Voltage = “);
    Lcd_Out(1,1,volt);
    Lcd_Out(1,6,”V”);

    current[0] = look(i/1000);
    current[2] = look((i/100)%10);
    current[3] = look((i/10)%10);
    //Lcd_Out(2,1,”Current = “);
    Lcd_Out(1,9,current);
    Lcd_Out(1,14,”A”);
    //Delay_ms(250);

    watt[0] = look(w/10000);
    watt[1] = look((w/1000)%10);
    watt[3] = look((w/100)%10);
    Lcd_Out(2,1,watt);
    Lcd_Out(2,5,”W”);

    } while(1);
    }

  • samiul.bd

    The Image here.

  • Preethi Shivanand

    thank you :)

  • aneetha
  • http://www.electrosome.com/ Ligo George

    Try changing to :

    watt[0] = look(w/1000);
    watt[1] = look((w/100)%10);
    watt[3] = look((w/10)%10);

  • http://www.electrosome.com/ Ligo George

    The complete project files are shared above..
    You can download it above..

  • samiul.bd

    Sir, would u pls explain this lines

    volt[0] = look(v/10000);
    volt[1] = look((v/1000)%10);
    volt[3] = look((v/100)%10);

  • http://www.electrosome.com/ Ligo George

    It is to convert the integer voltage to corresponding string… You can do it in many simpler ways…
    If V = 546000
    then volt[0] = ’5′
    volt[1] = ’4′
    volt[2] = ‘.’
    volt[3] = ’6′
    so… volt = “54.6″

  • Balanici
  • pra

    sir this download is not starting.i click download button my account is automatically logout. please solve thi problem

  • http://www.electrosome.com/ Ligo George

    Download the above program… and go to mikroc project settings…
    Then change the device 16F877A to 16F883…. then rebuild the project..
    Then you will get the new hex file corresponding to your pic..

  • http://www.electrosome.com/ Ligo George

    Sorry for the inconvenience caused..
    I think the problem is solved now… It was caused due to our server migration..
    Try now..

  • dharitri

    select the ädc”in library manager………………..

  • dharitri

    can we use 12mhz for pic16f877a?

  • http://www.electrosome.com/ Ligo George

    Yes… it can work up to 20MHz..

  • Muf

    Hi Sir,
    I’ve built this ammeter exactly as you show here on this website. However, after connecting it to Vdd [no voltage on input], the display shows no data. [I expected 0V at least. I also checked the trimmer for contrast but in vain].
    What fuses should be set when uploading the *.hef file into the chip ???

    After burning the PIC I have this error – Fuse Error : 0×2007, Good : 0x3F79, Bad : 0x3F7A.
    I am using the K150 chip programmer and the fuses are set like this : WDT-disabled, BODEN-enabled, CPD-disabled, Debug-disabled, Code Protect-disabled, PWRTE-disabled, LVP-disabled, WRT enable-enabled, Oscil-XT
    I can read the chip after burn and the code is inside, but verify goes wrong.
    ROM ends on line 538 with number 0008 [after it just 3FFF]
    Can you help me with this , pleeease ???
    Thanks a lot …

  • http://www.electrosome.com/ Ligo George

    Sorry, I am not familiar with your programmer..
    Verify that you are using PIC 16F877A and it is selected properly in your programmer settings..
    Note that PIC 16F877 and PIC 16F877A are different microcontrollers..

  • Muf

    Yep, I AM using 16F877A chip and it IS properly selected in my programmer [checked several times]. How about the fuses ? Do I have them set well ?
    Thanks anyway… :-)

  • http://www.electrosome.com/ Ligo George

    Usually we can write hex file to pic… just by selecting the microcontroller in programmer software….
    Sorry, I have no idea about your programmer….. try searching on google..

  • J S

    Hello Sir, thank you for all of your help! I would like to measure up to 70 amps, what kind of resistor would I need? Would anything else need
    to be changed in the circuit? Thanks!

  • http://www.electrosome.com/ Ligo George

    You should use low value resistor.. which is able to withstand 70 amps…. I haven’t any experience with such high current.. try searching on google…
    I thinks that it is better to use current transformer instead of resistor..

  • Gregory

    Gregory
    Hi Sir. How would you eliminate the leading zero when the voltage or current displayed is less than 1? For example: 250mA as displayed 0.25A is changed to .25A or 450mV as displayed 0.45V is changed to to .45V

  • http://www.electrosome.com/ Ligo George

    Just use your logic.. .or use mikroc is built in conversion funcitons like IntToStr() or FloatToStr() …

  • muf

    Hi once more… finally got it work !!! :-)
    But I have one more question : I import the *.mpcii file into microC 8 Pro for Pic. I can see the C code. I do NO changes and I build the project. I get 4 warnings of: “search path does not exist (c:users…defs; c:users…usesp16; f:electronicsembeddedvoltmeter; and f:electronicspower supply” – the first 2 dirs ARE there, the 2nd two not – I dont have F drive !). But the build is compiled successfully.
    I have a new hex file and import the design into proteus 8 pro where the new hex is assigned to the PIC. But it doesn´t work – the display shows blinking letter V only (like Volts). I have many warnings of one kind repeatedly occurring – “PIC16CORE – PC=0×0421 Indirect write of 0×30 to address 0×0000 is itself an indirect write”.
    My hex is 70 bytes shorter and 35 words shorter than yours. Just mentioning once more – I do NO changes to your C code !!
    If I upload your hex, it works fine.
    What am I doing wrong ??? Any settings anywhere ???
    Thanks once more…:-)

  • http://www.electrosome.com/ Ligo George

    Import means?? You need to just open the .mcppi file with mikroc pro..
    If it is not working.. try creating a new project… and copy paste my code..don’t forget to set the microcontroller to 16F877A and clock frequency to 8MHz when you create a new project.

  • Anshuman Shekhar Tiwari

    Sir,
    I am trying to program the PIC16F887A using an ICD 2 programmer by simply importing the .hex file in MPLAB IDE and then writing the file to the chip , but my LCD display stays all blank ( all connections made according to the schematic provided ).
    Could you suggest a solution?
    Would appreciate a ton :)

  • http://www.electrosome.com/ Ligo George

    Did you tried adjusting the contrast adjusting potentiometer of LCD??

  • Anshuman Shekhar Tiwari

    By blank I meant that the LCD is powering up , but is all blank , doen’t display anything.
    And yes , I did try adjusting the contrast using the Pot , it was working.
    According to the code , I should atleast be getting “Voltage = ” and “Current= ” on the LCD , but I get nothing. The LCD just powers up all blank green.

  • http://www.electrosome.com/ Ligo George

    Then there should be anything wrong in your implementation.. . verify the code in the pic memory.. and connections..

  • tasos17

    hello sir if you would please explain why the use of Resistor R3? thanks in advance!!

  • http://www.electrosome.com/ Ligo George

    It will work perfectly without that resistor….
    It can be used to protect the microcontroller from over voltage/current…..
    If the input voltage is above 5.1V .. zener conducts… R3 will limit the current through the zener…
    Zener and R3 can be avoided if you are sure about input voltage and current range..

  • Andrius

    can i use pic18f14k22 for this build? or i need to make other hex file if i change mv?

  • http://www.electrosome.com/ Ligo George

    You should change the device to 18F14K22 in the MikroC Project settings and Rebuild the program..

  • bali

    sir why current does not display at lcd when the program is running in proteus?

  • http://www.electrosome.com/ Ligo George

    You should connect a load .. to flow current..

  • Hazem Zaqout

    Hello …
    i have a problem with my DVM, when i measure a voltage a cross battery , it give a half voltage of battery

    Note: i don’t use above circuit , My circuit is attached bellow

  • tina

    I can’t correct the error ,please i need a help !

  • aus

    hi… how to create assembly program using PIC16F877A from ldr port A to port B stepper motor..?

  • helpme

    hello sir, measuring voltage was very helpful.i am using 18f4550 and coding in mikroc. i would like to know if there is anyway that i can measure frequency using zcd or convert it to voltage. if there is anyway pls help me. thanks in advance.

  • karthik

    hii,,

    I can t able to read 5 adc ports at the same time…..
    I can able to read the values of 3 adc ports and displayed in lcd perfecty….help….

  • andrius

    hello, i cant find anywhere to buy 1N4733A diodes what other diodes that can fit here?

  • andrius

    i couldn’t find pic16f877A i using pic16f877 20/p if i specify it in microC and proteus it should still work? the pin layout practically the same

  • http://www.electrosome.com/ Ligo George

    Just change the microcontroller in mikroc pro project settings and in proteus..
    It will workk

  • Juan Oosthuizen

    Hi, this is an excellent example. I have a very newbie question though…I got the simulator running in Proteus but I don’t see any amps or volts on the LCD, it prints out 0.00 for both values. Now I read from all the comments that I need to add a load. So I have 2 questions how do I specify the voltage and the load on the existing circuit?

  • http://www.electrosome.com/ Ligo George

    Better to try in the real hardware…
    You may try using voltage sources and resistors in the proteus..