As we all are playing with electronics and micro controller, we all know what is voltmeter. It is a meter which is used to measure volt. Today we will make a voltmeter using PIC16F877a. But the voltage measure limit is 40V. One important thing is micro controller can not tolerate more than 5V in it's input pin. So what we will do? We will make a voltage divider circuit, so that input pin's voltage doesn't exceed 5V.
To do this we need following software:
1. MikroC pro for PIC (student verison)
2. Proteus 8 professional
3. PicKit 2
MikroC pro for PIC will be used for writing and compiling the code. Here we will use C language for programming. Proteus 8 professional will be used for the simulation and finally Pickit 2 will be used for burning the hex file in the PIC16F877a IC.
To do this project we need following components;
1. PIC16F877a
2. Resistor 18k and 2.2K
3. 20 MHz Crystal Oscillator
4. Breadboard
5. Wires
6. 5V DC Power source
7. Soil Moisture Sensor
7. Soil Moisture Sensor
8. 16*2 LCD
9. header for connecting LCD
10. 10K potentiometer
CODE
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D4 at RD2_bit;
sbit LCD_D5 at RD3_bit;
sbit LCD_D6 at RD4_bit;
sbit LCD_D7 at RD5_bit;
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD5_bit;
unsigned int k,j,i;
char *l,*m,n[7],o[7];
void main()
{
int t;
ADCON1=0x04;
PORTA = 0;
TRISA = 0X01;
PORTB = 0x00;
TRISB = 0x00;
LCD_Init();
ADC_Init();
LCD_Cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1,1, " ABDUR ROUF ");
LCD_Out(2,1, " VOLTMETER ");
delay_ms(2000);
LCD_Cmd(_LCD_CLEAR);
while (1)
{
t=ADC_Read(0);
k = t;
k =k*0.458; //k*0.458;
j = k/10;
i =k%10;
inttostr(j,o);
inttostr(i,n);
l =ltrim(o);
m =ltrim(n);
if(j<=9)
{
lcd_out(1,1,"***Voltmeter***");
lcd_out(2,1,"Volt:");
lcd_out(2,8,l);
lcd_out(2,9,".");
lcd_out(2,10,m);
lcd_out(2,12,"V");
}
else
{
lcd_out(1,1,"***Voltmeter***");
lcd_out(2,1,"Volt:");
lcd_out(2,7,l);
lcd_out(2,9,".");
lcd_out(2,10,m);
lcd_out(2,12,"V");
}
}
}
Schematic
Schematic 1
Schematic 2
Schematic 3