In this tutorial we will learn how to make digital voltmeter using PIC microcontroller. Here I am use PIC16F877A microcontroller and LM16x2 Lcd display. You can watch the video  and read the written tutorial below.

 

 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

 

Circuit Diagram

 

The A/D conversion of Analog input signal results in a corresponding 10 bit digital numbers.

0V     → 00 0000 0000
2.5V  → 00 1111  1111
5V      → 11 1111 1111

 

Calculation:

Resulation  = (5-0)/(1024-1)
                                 = 0.00488758
                                 =4.8875mV




Here,
       ADC read = 0 V                 (Microcontroller read)
      Actual Voltage = ADC read * Resulation
                              = 0 * 4.8875 mV
                              = 0V

Again,
           ADC read = 5 V
           Actual Voltage = ADC read * Resultion
                                   = 1024 * (5/1023)
                                   = 5.0048 V
                                   = ~5 V

 

 

MikroC pro for PIC provide a ADC Library which  comfortable work with the ADC module.

 

Project Code:

// LCD module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;

sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_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;
  char *volt = "00.0";
  CMCON = 0x07;
  TRISA = 0xFF;                        // PORTA is Analog input
  PORTA = 0X00;                        // PORTA is clear
  ADCON1 = 0x00;
  Lcd_Init();                          // Initialize lcd module
  ADC_Init();                          // Initialize ADC module
  Lcd_Cmd(_LCD_CLEAR);                 // Clear Lcd display
  Lcd_Cmd(_LCD_CURSOR_OFF);            // Cursor of the Lcd display
  Lcd_Out(1,1, "DEVELOPED BY");        // Lcd show "DEVELOPED BY"
  Lcd_Out(2,1, "MINA TECHNOLOGY");     // Lcd show "MINA TECHNOLOGY"
  delay_ms(2000);                      // 2 second delay
  Lcd_Cmd(_LCD_CLEAR);                 // Clear Lcd display

  do                                   // loop start
  {
    v = ADC_Read(0);                   // RA0 is Analog input
    v = (v*4.89) ;                     // 4.89 is Voltage Resulation
    volt[0] = look(v/10000);
    volt[1] = look((v/1000)%10);
    volt[3] = look((v/100)%10);
    Lcd_Out(1,1,"Digital Voltmeter");
    Lcd_Out(2,1,"Voltage = ");
    Lcd_Out(2,11,volt);
    Lcd_Out(2,16,"V");

    Delay_ms(500) ;                     // 500ms delay

  } while(1);                           // loop end
}

 

 

Download free source code

 

download