In this Tutorial, learn how to interface ACS712 AC and DC current sensor module with Arduino to measure the current and power consumption of the load and display the current and power consumption on LCD display module, which can be also called as current monitoring system or power monitor. These sensor modules comes in 3 different capacities 5A, 20A, 30A which we are going to discuss them in detail below.
Table of Contents
Required components:
Product Name | Quantity | ||
---|---|---|---|
Arduino Microcontroller | 1 | https://amzn.to/3H4cKxZ | https://amzn.to/3638aTS |
ACS712 current sensor module | 1 | https://amzn.to/3v4ok8y | https://amzn.to/3EaJ9Dz |
LCD 16X2 module with or without I2C adapter | 1 | https://amzn.to/3BNSRup | https://amzn.to/363ki7F |
5V power supply (Micro USB or External). | 1 | https://amzn.to/3s1a8g3 | https://amzn.to/364yInH |
Few Connecting Wires | https://amzn.to/3H2BV4e | https://amzn.to/3J0WVu2 |
ACS712 current sensor module
ACS712 sensor module uses ACS712 IC which is developed by Allegro Micro Systems. This IC uses Hall effect principle to measure current. ACS712 IC consists of a low-offset, precise and linear Hall sensor circuit with a copper conduction path at the surface of the die.
This modules comes in 3 ranges:
- +/- 5A
- +/- 20A
- +/- 30A
You need to choose the right module according to your requirement, as higher the capacity of the sensor lower the accuracy. For better accuracy use 5A version as it can measure current of major household appliances. if you go for higher 30A version measuring the current vales of smaller loads will give very in accurate and deviated results. Refer the below table for the mV per Ampere measured by the sensors.
5A Module | 20A Module | 30A Module |
185mV/Amp | 100mV/Amp | 66mV per Amp |
For more details about the ACS712, Please refer ACS712 datasheet : here
ACS712 current sensor module Specifications
- Measures both AC and DC current
- Available in 5A, 20A and 30A modules
- 66 to 185 mV/A output sensitivity
- Very small in size
- Outputs analog voltage, so its easy to connect with most of the Microcontrollers.
Principle, pinout and working of ACS712 current sensor module
Principle: We already discussed this sensor uses the Hall effect principle.
Pinout diagram of ACS712 IC:
Pin Number | Pin Name | Pin Description |
1 & 2 | IP+ | +ve terminals for current sensing |
3 & 4 | IP- | -ve terminals for current sensing |
5 | GND | Ground Signal |
6 | FILTER | External Capacitor to set the bandwidth |
7 | VIOUT | Analog Voltage Output |
8 | VCC | Power Supply to IC |
Working of ACS712 current sensor
As you can see from the above image, the current to sensed is connected to the top 4 pins, 2 pins for positive and 2 pins for negative, when current flows with in an amount of magnetic field is produced across the copper conduction path which is proportional to the amount of current passed. This magnetic field is sensed by the integrated hall effect IC and outputs voltage through the VIOUT pin.
ACS712 current sensor module application circuit (On PCB)
From the above circuit image and module image, You can see i have arranged both the images with same IC pin sides, So, it would be easy for you to understand the placements of capacitors and resistors.
Here we have 2 capacitors Cbyp and Cf with 0.1µF and 1nF respectively, Cbyp is connected in series with +5v and GND, and Cf is connected in series with FILTER and GND. A 1kΩ resistor with SMD code 102 is connected to 5v and power LED.
When AC current flow is connected between the 2 plastic screw connectors the ACS712 IC sensor senses the magnetic field and generate and outputs analog voltage at OUT pin.
As per the manufacturers datasheet the AC side and DC output are separated with 2100 Vrms which protects the microcontroller and USB power supply from contacting with high voltage. But still take necessary precautions to protect you, your computer and microcontroller Arduino from 240V AC.
Interfacing ACS712 Current sensor with Arduino to display result over serial monitor
Circuit Diagram
From the above schematic diagram you can observe the OUT pin from the current sensor is connected to the analog pin A0 of Arduino. VCC and GND pins of sensor are connected to 5V and GND of Arduino.
On the other side one of Load wire is connected in series with the sensor as shown in the above image.
Source code:
After connecting all the components as shown in the circuit diagram, Copy and upload the below code to Arduino through Arduino IDE.
Under the rest condition (no load on sensor) when the VCC is connected to 5V from the Arduino, OUT pin on the Sensor outputs 2.5V. when the load is added the voltage increases or decreases by sensitivity values(185mV/A for 5A module, 100mV/A for 20A Module or 66mV/A for 30A Module).
Under DC load DC circuits have a unidirectional flow of current and like AC it is not changing the direction periodically. So its easy to measure it unlike AC which changes its directional flow periodically with a frequency of 50 or 60 Hz according to the country you stay. So in this scenario Voltage goes up and down according to a sine function while current goes back and forth. This means that we must measure the output voltage related with peak current.
// Tested and compiled with no errors // measuring AC current using ACS712 current sensor // The ACS712 works with high voltage AC so be careful ! // source - /www.circuitschools.com const int sensorIn = A0; // pin where the OUT pin from sensor is connected on Arduino int mVperAmp = 185; // this the 5A version of the ACS712 -use 100 for 20A Module and 66 for 30A Module int Watt = 0; double Voltage = 0; double VRMS = 0; double AmpsRMS = 0; void setup() { Serial.begin (9600); Serial.println ("ACS712 current sensor"); } void loop() { Serial.println (""); Voltage = getVPP(); VRMS = (Voltage/2.0) *0.707; //root 2 is 0.707 AmpsRMS = (VRMS * 1000)/mVperAmp; Serial.print(AmpsRMS); Serial.print(" Amps RMS --- "); Watt = (AmpsRMS*240/1.3); // 1.3 is an empirical calibration factor Serial.print(Watt); Serial.println(" W"); } float getVPP() { float result; int readValue; // value read from the sensor int maxValue = 0; // store max value here int minValue = 1024; // store min value here uint32_t start_time = millis(); while((millis()-start_time) < 1000) //sample for 1 Sec { readValue = analogRead(sensorIn); // see if you have a new maxValue if (readValue > maxValue) { /*record the maximum sensor value*/ maxValue = readValue; } if (readValue < minValue) { /*record the minimum sensor value*/ minValue = readValue; } } // Subtract min from max result = ((maxValue - minValue) * 5.0)/1024.0; return result; }
After uploading the code open serial monitor to check the values of current in Amps and Power consumption in Watts.
Calibration is more important in this sensor module because this doesn’t not give accurate results directly, it has some error percentage. This error percentage increases if we use Higher Amp versions as the sensitivity decreases.
Connecting LCD display to Current monitoring system
In this we are just adding a LCD display module to display the current and power consumption values on LCD display instead connecting it to a PC to check the values.
Here we are using a 16×2 LCD display with I2C adapter connected, which is easier to connect with inbuilt potentiometer to adjust contrast. If you still want to connect LCD display without I2C adapter refer the below article.
Circuit diagram
From the above circuit diagram you can notice every other connections except for LCD display are same as previous one. here LCD display module VCC and GND are connected with 5V and GND from Arduino.
SDA and SCL pins from the LCD module are connected to the A4 and A5 pins of the Arduino. That’s it for connection now its time to upload the code.
Source code for LCD display:
After connecting everything as per the above circuit diagram, Please copy the below code and paste it in Arduino IDE and upload it to your Arduino.
// Tested and compiled with no errors // measuring AC current using ACS712 current sensor // The ACS712 works with high voltage AC so be careful ! // source - /www.circuitschools.com #include <LiquidCrystal_I2C .h> const int sensorIn = A0; int mVperAmp = 185; // 5A version SC712 – use 100 for 20A Module or 66 for 30A Module int Watt = 0; double Voltage = 0; double VRMS = 0; double AmpsRMS = 0; // initialize the LCD library with I2C address and LCD size LiquidCrystal_I2C lcd (0x3F, 16,2); void setup() { Serial.begin (9600); Serial.println ("ACS712 current sensor"); // Initialize the LCD connected lcd. init (); // Turn on the backlight on LCD. lcd. backlight (); lcd.setCursor (0, 0); lcd.print ("ACS712 current sensor"); } void loop() { Serial.println (""); Voltage = getVPP(); VRMS = (Voltage/2.0) *0.707; //root 2 is 0.707 – dealing with sine AmpsRMS = (VRMS * 1000)/mVperAmp; Serial.print(AmpsRMS); Serial.print(" Amps RMS — "); Watt = (AmpsRMS*240/1.2); // note: 1.2 is my own empirically established calibration factor // as the voltage measured at A0 depends on the length of the OUT-to-A0 wire // 240 is the main AC power voltage – this parameter changes locally Serial.print(Watt); Serial.println(” W”); lcd_control (); } // ***** function calls ******* float getVPP() { float result; int readValue; // value read from the sensor int maxValue = 0; // store max value here int minValue = 1024; // store min value here uint32_t start_time = millis(); while((millis()-start_time) < 1000) //sample for 1 Sec { readValue = analogRead(sensorIn); // see if you have a new maxValue if (readValue > maxValue) { /*record the maximum sensor value*/ maxValue = readValue; } if (readValue < minValue) { /*record the minimum sensor value*/ minValue = readValue; } } // Subtract min from max result = ((maxValue – minValue) * 5.0)/1024.0; return result; } void lcd_control (){ lcd.print (AmpsRMS); lcd.print (" Amps "); //Here cursor is placed on first position (col: 0) of the second line (row: 1) lcd. setCursor (0, 1); lcd.print (Watt); lcd.print (" watt "); delay (100); }
After uploading the code the LCD display shows the out as,
If you have any doubt regarding this project please feel free to ask through below comments, or Our Facebook page “Circuit Schools”.
If you want to interface ACS712 current sensor module with ESP8266 or ESP32, refer the below articles.