Home / Home made Projects / Microcontroller Projects / Microcontroller based Digital ammeter using Hall effect sensor

Microcontroller based Digital ammeter using Hall effect sensor

In this article, we will discuss how to construct digital ammeter using microcontroller for DC currents We will explain, how to sense current in terms of voltage. Which pins of Microcontroller should be used for this purpose. How is schematic diagram made. Last but not the least! the code for this project is also provided


Current, voltage and power are three quantities in electric power system which needs to be monitored all the time. So the purpose of this article is to propose a methods which can be employed to measure current via microcontroller. However Microcontroller does not have any facility to measure current directly. The analogue inputs of microcontroller can only measure voltage and that is only up to 5V DC. Therefore an intermediate circuit needs to be developed which can which can translate the current into voltage so that it is readable to microcontroller. The method utilizes a special type of sensor which is called hall effect sensor.

Hall Effect Sensor

Hall effect sensor gives its output in terms of voltage that depends upon the current through it. In simple words it translates current into voltage.

Hall Effect sensor is based upon the law of electromagnetic induction  which states that current can produce magnetic field. So when a current passes through a coil, it can induce voltage in it. That induced voltage depends upon the current. So by measuring induced voltage, the current thought the coil can be determined.

For the detailed information on hall effect sensor, please refer to my article

Introduction to Hall Effect sensor.

Figure below shows pin diagram and connection configuration of Hall Effect sensor.

Hall Effect sensor

AC712 Hall effect current sensing IC comes in 3 different ranges

IC Name Range Sensitivity
ACS712-05B ±5A 185mV/A
ACS712-20B ±20A 100 mV/A
ACS712-30A ±30A 66 mV/A

Sensitivity means change in voltage per unit ampere current.  185mV/A sensitivity means that 185mV change in voltage will occur when the current changes by 1A. NOTE: These sensitivities are based upon the condition that supply voltage Vcc is 5V. It should also be noted that output voltage at 0A current is 2.5V that is Vcc/2. For different energizing voltage, the sensitivity and output at 0A will be different.

Schematic for Digital ammeter

To measure current by using microcontroller following components are needed.

  • Microcontroller (PIC18F2320)
  • Hall Effect sensor (ACS 712 30 A)
  • Capacitor
  • LCD
  • Variable Resistor
  • Power source

Above stated components are connected in the following way to measure DC current.connection diagram of digital ammeterHall Effect sensor should be connected in series with the circuit. Sensor is connected in such a way that current enters through pin IP+ and leaves through pin IP-.  Output voltage can be taken from Vout pin. IC is powered though Vcc pin where GND is connected to ground. Figure shows that Pin 6 (filter) is connected to ground via 1nF capacitor. The purpose of the capacitor is to filter out noise from the current.

To display the results, LCD is interfaced with the microcontroller.

Simulation results

In order to check the performance of the proposed digital ammeter, a DC source is connected in series with variable load. By using this arrangement, the current value can be varied. A built in ammeter is connected so verify our system.

Some of the results are shown in the figure.
simulation result 1Digital ammeter shows 16.7 A while actual value is 16.6A

Now the value of load is changed to alter value of current in the system.

simulation result 1

Now the current shown by our designed meter is 11.07 while its actual value is 11.1 shown by built in ammeter.


The program is written in C language and complied in MIKRO C.

float valueread, analoguevalue, dccurrent;   
  // Lcd module connections start 
sbit LCD_RS at LATB4_bit;  
sbit LCD_EN at LATB5_bit;  
sbit LCD_D4 at LATB0_bit;  
sbit LCD_D5 at LATB1_bit;  
sbit LCD_D6 at LATB2_bit;  
sbit LCD_D7 at LATB3_bit;  
sbit LCD_RS_Direction at TRISB4_bit;  
sbit LCD_EN_Direction at TRISB5_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; // Lcd module connections ends
  // copy above statments into your code for every project involving LCD
char txt[4]; // declare a char array
void main(){  
TRISA=0XFF;   // PORTA is input
ADC_Init(); // Initialize ADC module with default settings
Lcd_Init();                        // Initialize Lcd
Lcd_Cmd(_LCD_CLEAR);               // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
Lcd_Out(1,1,”Welcome to”);         // dsiaplay the welcome logo on the LCD screen at position ROW=1 COLUMN=1
delay_ms(5000);                     // keep displaying logo for 5s
Lcd_Cmd(_LCD_CLEAR);               // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
inputread = ADC_Read(0);  // Read analog value from channel 0
  inputread = ADC_Read(0);  // Read analog value from channel 0
  inputmeasured=(inputread*4.88)/1000; // converting digital value to analogue. Since the reference voltage is 5V and A/D converter is 10 bit (2^10=1024) therefore step voltage is 5/1024=4.88mV. To get analogue value from digital dividing it by 4.88mV
  analoguevalue= valueread-2.495;       //Hall effect sensor output is 2.5V for 0A. Therefore subtracting value 2.5 (2.49 due to small error introduced by IC resistance) to get the voltage due to current flowing.
  dccurrent= (1000*analoguevalue)/66; // sensitivity of ACS712 30A is 66mV (already explained above) so deviding voltage to get current.
  if (dccurrent<1 || dccurrent >30 ) // for out of range values.
  {dccurrent= dccurrent;}
  floatToStr(dccurrent, txt) ; //convert float variable value to characters to be displayed on the LCD
  lcd_out(1,1,txt);  // dsiaplay the current value stored character text on the LCD screen at position ROW=1 COLUMN=1
  Lcd_Out(1,11,”Amp”); // dsiaplay the character ohm on the LCD screen at position ROW=1 COLUMN=11
  delay_ms(2000);       // wait 2s before taking second value

The code is self explanatory. However if you have any further questions about code or digital ammeter please ask in comments.


About Syed Noman ud din

Syed Noman ud din is an Electrical Engineer and working in Industry from last 3 years. He writes technical articles for electrical and electronic engineers. He has also published several research publications in renowned international journals.

Check Also

Power Factor measurement using Microcontroller

The article will help the readers to use microcontroller for power factor measurement using a …


  1. chokri khalfalli

    please can you send the hex file or the full code in mikroC
    Project: Microcontroller based Digital ammeter using Hall effect sensor

  2. Hi he about measuring ac currents

    • Sorry for late reply
      If u can go through the articles
      power factor meter using micrcontroller &
      measure resistance using micrcontroller i am quite sure you will be able to make AC ammeter as well.
      The concept is pass the current through voltage divider circuit, meansure the voltage drop and calculate the current.

Leave a Reply

Your email address will not be published. Required fields are marked *