Header Ads

How to make digital voltmeter (0-30)V use Microcontroller and Mickro C

In this tutorial we will learn how to make a digital voltmeter use pic microntroller. Here I am use PIC16F877A and LM16x2 Lcd display. PIC16F877A microcontroller has 8 channel analog input. In this project I am analog channel 0 for analog to digital conversion. You can watch the video or read the written tutorial below.




Voltmeter is a electronic device and it measure voltage between two terminals.

PIC16F877A microcontroller has 8 channel ADC(Analog to Digital Converter) module. ADC module has software selectable high and low voltage reference input to some combination of VDD, VSS, RA2 and RA3. The ADC module recived analog signal and it convert 10 bit binary numbers. It can measure (0-5)V DC




PIC16F877A microcontroller can be measure 0 to 5V . If measure high voltage we need to voltage divider circuit. In this project we measure the voltage 0 to 30V.

Voltage Divider Circuit

  • First of all let I discuss how do we measure voltage? Actually PIC’s ADC can measure 0V to +5V, but here our voltage range is 0V to +30V.
  • Hence we can’t feed the input voltage directly to the controller’s ADC pins. Instead of feeding directly, input voltage is reduced by a combination of voltage divider resistors.
Maximum allowed drop will be 5V

Voltage Divider Circuit



       5 = Vin(max)*R2/(R1+R2)

Here, 
      Vin(max)=30V; and assume R2= 22k ;
       5 = 30 * 22K(R1+R2) 
       R1+R2 = (30 * 22K)/5 
                   = 132000
                   = 132 K
        
      R1 = 132 K - R2  = 132 K - 22K = 110K



Actual calculate input voltage from voltage divider circuit.

PIC Microcontroller read voltage across the 22K resistor. So calculate voltage across 22K resistor by the voltage divider rule.

assume V22 voltgae drop across 22K resistor.
V22 = (Vin/(110K+22K)) * 22K
V22 = (Vin/(132K) * 22K)

This V22 is read to microcontroller's ADC module
Hence,
           The actual input
            Vin = (V22*132) / 22K
             Vin = V22 * 6


Circuit schametic of Digital Voltmeter


digital voltmeter circuit schematic

Mapping ADC Values to Input Voltage

  • PIC microcontroller ADC is a 10 bit ADC, that means the output of ADC can be vary from 0 to 1023 maximum while input varies from 0 to 5V.
  • That is when the input voltage is +5V then ADC value is 1023, when input voltage is 0V ADC value will be 0.
  • We have to map 0 → 1023 to 0 → 5; it can be done by multiplying ADC value with a constant K.

K= Maximum ADC Voltage / Maximum ADC Value
   = 5 / 1023 = 4.89 * 10^-3 = 4.89m

Vactual = ADC Value * 4.89m * 6

For example let's say ADC Value is 1023

Vactual = 1023 * 4.89m * 6
             = 30.014V.



Mikro C code for Digital Voltmeter 




Click the download button for source code:
download

No comments

Theme images by 5ugarless. Powered by Blogger.