A current sensor is a critical part of any load sense application.
They are used in metering applications, overload detention and protection, rectification and other applications.
This article will teach us how to use the ACS712 current sensor with Arduino.
We will cover the basics of current measurement and understand more details about the current sensor IC ACS712.
In the following sections, I will present connection diagrams, Arduino code for the current sensor, and more.
At the end of this article, you can also have the answers to the most frequently asked questions.
Let’s get started!
Components Needed To Build Arduino ACS712 Sensor Project
Hardware Components
- Dupont wire x 1 set
- Arduino USB cable (for powering Arduino and programming) x 1
Software
Makerguides.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to products on Amazon.com.
Basics of The ACS712 Current Sensor
In this section, we will understand more about the ACS712 module. We will understand the datasheet parameters, pin descriptions, and more.
By the end of this section, you will be confident to work with the sensor for current sensing applications.
When the current flows through the resistor, there will be a voltage drop. Hence, if you can measure the voltage drop, you can calculate the current flowing through it.
The ACS712 IC provides an analog output voltage corresponding to the current flowing through its sense terminals.
There are two ways of measuring the current. If you use a shunt resistor to monitor the current, you also add an inevitable voltage drop on the channel.
In this case, you don’t need a dedicated current sensor!
The drop in the voltage is the pitfall.
In the case of ACS712, you measure current indirectly. Instead of ohmic loss, you consider the magnetic field around the current conducting wire.
Every wire produces a magnetic field around it when you pass a current through it.
By measuring the strength of the magnetic field, you can calculate the current flowing through it. This is a nonintrusive way of current sensing.
For example, let us say that we are measuring 400 mV at the analog output of the sensor.
Also, assume that the sensor is optimised for the 5 A current measurement.
Follow the steps below to calculate the current:
- Note the sensitivity from the datasheet: 185 mV/A
- Measure the output voltage at the VIOUT pin of the sensor: 400 mV
- Divide the VIOUT voltage by the sensitivity to get the load current
400 / 185 = 2.16 A
Pin-out diagram of ACS712 IC
Here is the pin-out diagram of the ACS712 IC.
In the below table, you can find the pin details of the ACS712 IC.
Pin Numbers | Pin Name | Pin Description |
1 and 2 | IP+ | Current Sense Terminals. These two pins are shorted inside the IC |
3 and 4 | IP- | Current Sense Terminals. These two pins are shorted inside the IC |
5 | GND | Ground terminal |
6 | FILTER | You can connect the external capacitor to this pin. The capacitance value decides the bandwidth |
7 | VIOUT | Output signal (analog value) |
8 | VCC | Power supply pin |
Electrical specifications of ACS712 IC
The ACS712 IC can be powered from 5 V. Let us see a few critical parameters of the IC, which are very helpful for us while choosing the sensor for our applications.
Characteristic | Range | Remarks |
Supply voltage | 4.5 V to 5.5 V | A typical 5 V is recommended |
Supply Current | 10 mA | Current required by the IC to function. |
Power-on-time | 35 us | Consider this time in your software to avoid wrong measurements |
Sensitivity | See below table | Expressed in mV per A. |
Optimised Accuracy range | See below table | The minimum and maximum current the IC can measure |
The ACS712 IC comes in three variants:
- x05B → Current range of 5 A
- x20A → Current range of 20 A
- x30A → Current range of 30 A
The below table summarises the sensitivity and occurrence range of the three variants:
Parameter | x05B | x20A | x30A |
Optimised accuracy range | -5 A to +5 A | -20 A to +20 A | -30 A to +30 A |
Sensitivity (mV / A) | 185 | 100 | 66 |
You can use the above table to calculate the current based on the voltage you read on the analog output pin of the IC.
Let us have a look at the standard ACS712 current sensor module.
The main blocks present in the current sensor are as follows.
1) Two terminal connector block – Connect the load current terminals here.
2) The ACS712 Current sensor IC
3) 3 Pin Connector – The three-pin connector is used to supply power to the IC and monitor the output.
VCC | 5 V power supply |
OUT | Analog output of the IC. Connect this to Arduino ADC pin |
GND | Ground connection |
4. LED indicator – Power indicator LED
Applications Of The ACS712 Current Sensor
You can use the ACS712 Current sensor module that can be used in various applications. Let us see a few in the section below.
Also, you can share the application for which you are using the ACS712 current sensor!
- Over Current Protection – You can use the ACS712 current sensor to monitor the load current. If there is an overload condition, you can immediately use the sensor data to cut off the load supply to protect the circuits.
- Load Current Regulation – You can regulate the load current by monitoring the ACS712 sensor data continuously. The regulation allows you to extend the lifetime of the components without compromising on performance.
- Peak Current Detection – You can use ACS712 to detect peak currents. The circuit protection components need some time to react to the current overload. For Example, A particular load may consume more current for short durations. The circuit-protecting devices may not respond to these momentary surges. The ACS712 can help you to monitor such peaks.
- Power metering – You can use ACS712 to monitor and meter the power consumption. You can monitor individual appliance power consumption.
-> Read our article about How Easy Is It To Learn Arduino?
Step-By-Step Instructions To Connect The Current Sensor ACS712 With Arduino UNO
In this section, we will build a project using Arduino UNO and the current sensor ACS712. You will monitor the current using the analog input of the Arduino UNO.
The connections are easy to take significantly less time to complete.
Let’s get started with the hardware connections!
How To Connect The Current Sensor ACS712 to the Arduino UNO?
Below is the step-by-step connection guide to complete the Arduino and the ACS712 current sensor IC module.
In this project, you will connect the sensor output to the Arduino UNO.
Step 1: Start with the GND connections
You can choose any of the GND pins on the Arduino to complete the GND connections. It is a good practice to connect the GND pins first.
Step 2: Connect the VIOUT pin
The analog output pin of the current sensor idles at 2.5 V. Connect the VIOUT pin to pin A0 of the Arduino UNO. You can choose any of the analog pins.
Step 3: Complete the current sensor connection
The current consumption of the current sensor is less than 15 mA. The 5 V pin on the Arduino UNO can easily source the needed current.
Congratulations on successfully completing the necessary connections.
-> Read our guide about What You Can Build with Adruino.
Arduino Code Example For The ACS712 Current Sensor Project
In this section, you will find the Arduino sketch required to build a basic current sensing project. There are two codes presented below. The first code is for the 5 A variant. The second code is for the 20 A variant.
When there is no load connected, the current will be zero. The voltage on the VIOUT pin is 2.5 V. The voltage on the VIOUT pin increases with the increase in the current.
For the 20 A model, there will be a rise of 100 mV on the VIOUT line for every 1 A of the load current.
For example, if the load current is 5 A, the voltage on the VIOUT will be
2.5 V + 5 * 0.1 = 3 V
The complete Arduino code for the 5 A version
void setup() { Serial.begin(9600); //Start Serial Monitor to display current read value on Serial monitor } void loop() { unsigned int x = 0; float AcsValue = 0.0, Samples = 0.0, AvgAcs = 0.0, AcsValueF = 0.0; for (int x = 0; x < 150; x++) { //Get 150 samples AcsValue = analogRead(A0); //Read current sensor values Samples = Samples + AcsValue; //Add samples together delay (3); // let ADC settle before following sample 3ms } AvgAcs = Samples / 150.0; //Taking Average of Samples AcsValueF = (2.5 - (AvgAcs * (5.0 / 1024.0)) ) / 0.185; Serial.print(AcsValueF);//Print the read current on Serial monitor delay(50); }
The complete Arduino code for the 20 A version
void setup() { Serial.begin(9600); //Start Serial Monitor to display current read value on Serial monitor } void loop() { unsigned int x=0; float AcsValue=0.0,Samples=0.0,AvgAcs=0.0,AcsValueF=0.0; for (int x = 0; x < 150; x++){ //Get 150 samples AcsValue = analogRead(A0); //Read current sensor values Samples = Samples + AcsValue; //Add samples together delay (3); // let ADC settle before next sample 3ms } AvgAcs=Samples/150.0;//Taking Average of Samples AcsValueF = (2.5 - (AvgAcs * (5.0 / 1024.0)) )/0.100; Serial.print(AcsValueF);//Print the read current on Serial monitor delay(50); }
The Arduino UNO has six analog inputs. In the below line of code, you are reading the analog value straight from the VIOUT pin of the ACS sensor.
AcsValue = analogRead(A0); //Read current sensor values
The next step is to collect more samples and average them to remove the noise in the readings. In the below code snippet, the reading is done 150 times.
for (int x = 0; x < 150; x++){ //Get 150 samples AcsValue = analogRead(A0); //Read current sensor values Samples = Samples + AcsValue; //Add samples together delay (3); // let ADC settle before next sample 3ms }
Then you are computing the average value by dividing the accumulated sum by 150.
AvgAcs=Samples/150.0;//Taking Average of Samples
FAQs About The Current Sensor ACS712 and Arduino Projects
I have brought together a list of the most frequently asked questions about projects built using Arduino and current sensor IC ACS712.
If you have any other questions, please post them in the comments section. I will be glad to answer them.
1) How does the ACS712 measure current?
ACS712 passively measures the current. The IC uses the hall effect to monitor the current through the terminals.
The device consists of a precise, low-offset, linear Hall sensor circuit with a copper conduction path near the die’s surface.
The hall sensor in the IC senses the magnetic field generated due to the load current flowing through the terminals.
The sensor then provides the proportional voltage on the VIOUT pin.
You can use an ADC input pin to measure the voltage and compute the current.
2) How do I connect my ACS712 to the Arduino UNO?
You only need three pins on the Arduino Uno to complete the connections between Arduino UNO and the ACS712 current sensor.
- 5 V connection to power the sensor
- GND pin to complete the ground connection
- Analog input pin to read the voltage on the VIOUT pin of the sensor
3) What is the ACS712 current sensor?
The ACS712 current sensor is a low profile, with a small footprint and a sensitivity ranging from 66 to 185 mV per ampere.
The sensor provides you with proportional output voltage for both AC and DC currents.
The output of the current sensor has a positive slope when an increasing current flows through the primary copper conduction path (from pins 1 and 2, to pins 3 and 4), which is the path used for current sensing.
4) How accurate is the ACS712 sensor?
The output error is ± 1.5% from the datasheet. It is a typical value. The error can be higher.
In the image below, you can see that the error shoots up with the variation in the temperature.
Accuracy is divided into four areas:
- 0 A at 25°C. Accuracy of sensing zero current flow at 25°C, without the effects of temperature.
- 0 A over Δ temperature. Accuracy of sensing zero current flow, including temperature effects.
- Full-scale current at 25°C. Accuracy of sensing the full-scale current at 25°C, without the temperature impact.
- Full-scale current over Δ temperature. Accuracy of sensing full scale current flow, including temperature effects.
–> Check out our guide to the Top 12 Best Arduino Online Courses
Conclusion
In this article, we went through the basic working principle of the ACS712 current sensor.
We covered the connection guide, Arduino code example and some tips to improve the accuracy of the readings.
If you have any questions regarding the project, I will be glad to answer your queries in the comments section.
I will be glad to learn about your projects using the ACS712 sensor. You can leave a link to the projects in the comments section.
I am Puneeth. I love tinkering with open-source projects, Arduino, ESP32, Pi and more. I have worked with many different Arduino boards and currently I am exploring, Arduino powered LoRa, Power line communication and IoT.