Current meter using PIC16F877A

DC and AC Current sensor using PIC16F877A



This post provides a simple digital current meter circuit using PIC16f877A microcontroller and ACS712. This code is written in C language using MPLAB X IDE with XC8 compiler. 

In this post, it is assumed that you know,

  • How to use ADC of PIC16F877A microcontroller. 
  • How to interface LCD with PIC16F877A microcontroller. 
  • How to interface ACS712 with PIC16F877A microcontroller.  


Figure 1 :Current Meter using PIC16F877A and ACS712




In this circuit PORTB pins are used to interface LCD with PIC167877A microcontroller. The output of current sensor is given on the RA0 (or AN0) pin.
Figure 2 : Current meter using PIC16F877A and ACS712
Calculation:
The ACS712 sensor read the current value and convert it into a relevant voltage value, The value that links the two measurements is sensitivity (you can find it on the datasheet) which – for 5A model – has a typical value of 185mV/A. The sensor can measure positive and negative currents (range -5A…5A), and power supply is 5V for the sensor, and the middle sensing voltage is 2.5V when no current. We are offering 5A and 20A version in our store. It’s DC and AC current sensing support! 
From the graph and the datasheet,
At zero current, Output Senosr Voltage = 2.5
Gradient of the graph = 185mV/A (given in datasheet as sensitivity)
So the equation of the graph is
Output Sensor Voltage = 0.185*Current + 2.5
Therefore current can be expressed as
Current = (Output Sensor Voltage – 2.5)/0.185
If the current flows in negative direction, current value will be negative.


Following is an example code which can be used for measuring current using the sensor. It will display the current measurement on 16*2 LCD

Example code:

Figure 3: Example code

Downloads:


Digital Current meter code using PIC16F877A was compiled in MPLAB X IDE v3.05 with XC8 V1.34 compiler and simulation was made in Proteus v7.10. To download code and Proteus simulation

Popular posts from this blog

Exploring USB Device Detection with Arduino and USB Host Shield

555 Timer Astable mode, Lt spice simulation, and real-time testing

PIC12F675 LED Blinking Code