Arduino UNO R4 - ACS712 Current Sensor

In this guide, we will learn how to use the ACS712 30A current sensor with the Arduino UNO R4 WiFi or Minima to find out how many amps a motor, a lamp or an LED strip really pulls. A voltage sensor tells you "how strong" the power is. A current sensor tells you "how much" is flowing. In detail, we will learn:

Arduino UNO R4 and ACS712 current sensor module

Overview of ACS712 Current Sensor

The ACS712 is a chip from Allegro that measures current with the Hall effect. Inside it, the current runs through a thick copper path. This current makes a small magnetic field, and a Hall sensor next to the copper turns that field into a voltage. The copper path has only about 1.2 mΩ of resistance, so it hardly changes your circuit. Also, the load side is isolated from the Arduino side (up to 2.1 kV RMS), so the measured circuit has no electrical link to your board.

The chip comes in three versions. They look the same, so check the text on the chip (for example ACS712ELCTR-30A-T):

Version Range Sensitivity
ACS712 5A -5A to +5A 185 mV per amp
ACS712 20A -20A to +20A 100 mV per amp
ACS712 30A -30A to +30A 66 mV per amp

This guide uses the 30A version. Its main specs:

ACS712 30A
Supply voltage 5V (4.5V to 5.5V)
Measured current DC and AC, -30A to +30A
Output at 0A about 2.5V (half of the supply)
Output at +30A / -30A about 4.48V / 0.52V
Sensitivity 66 mV per amp
Bandwidth 80 kHz
Total output error about ±1.5% at 25°C
Isolation 2.1 kV RMS

The output is "ratiometric". This means it follows the real 5V supply. If the supply is 4.9V, the zero point is about 2.45V, not 2.5V. That is why the code measures the zero point at startup, instead of trusting the 2.5V number.

ACS712 current sensor pinout

The module has a 3-pin header on one side:

  • VCC pin: connect to 5V of the Arduino UNO R4.
  • GND pin: connect to GND (0V).
  • OUT pin: analog output voltage, connect to an analog pin of the Arduino UNO R4 (A0 in this guide).

On the other side, there is a 2-pin screw terminal (IP+ and IP-, sometimes not labeled). It goes in series with the load: cut one supply wire of the load and put the terminal in between, so all the load current flows through the module. When current goes from IP+ to IP-, the reading is positive. If your reading is negative, just swap the two wires. A small LED on the module shows that it has power.

How good is the 30A version for small currents? The 30A version is made for big currents, so it is coarse for small ones. With the normal 10-bit reading (0 to 1023), one step is about 4.9 mV, which is about 74 mA. The Arduino UNO R4 can read its analog pins with 14 bits (0 to 16383), so one step is only about 0.3 mV. This does not remove the noise of the sensor itself: at 0A, the value still jumps by about ±50 to 100 mA. But together with averaging, it gives a calm and stable number. The module fits loads of about 0.5A and more, like motors, lamps, LED strips, heaters and chargers.

How the Voltage Becomes Amps

At 0A, the OUT pin sits at the zero voltage (about 2.5V). Each amp moves it by 0.066V, up for one direction and down for the other. So the formula is:

current_A = (Vout - Vzero) / 0.066

For example, if the zero voltage is 2.493V and the Arduino UNO R4 reads 2.559V, the current is (2.559 - 2.493) / 0.066 = 1.00A.

Wiring Diagram

The Arduino UNO R4 works with 5V on its analog pins, the same as the ACS712 output. So the OUT pin goes straight to A0, and no voltage divider is needed. The 12V side is separate: the 12V adapter feeds the 12V DC device (such as a DC motor, LED strip or lamp) through the screw terminal of the module.

The wiring diagram between Arduino UNO R4 ACS712 current sensor

This image is created using Fritzing. Click to enlarge image

See The best way to supply power to the Arduino Uno R4 and other components.

ACS712 Module Arduino UNO R4
VCC 5V
GND GND
OUT A0
Load side Connect to
Screw terminal IP+ positive (+) of the 12V DC power jack
Screw terminal IP- positive (+) wire of the DC device
DC device negative (-) wire negative (-) of the 12V DC power jack

※ NOTE THAT:

Safety first. Mains AC (110V/220V) is dangerous and can kill. If you are a beginner, practice only with a low-voltage DC load like the 12V DC device in this guide. When the module is used in a mains circuit, the screw terminal and the copper side carry the full mains voltage. Never touch the terminal or the wires while the circuit is live.

How To Program For ACS712 Current Sensor

  • Switch the analog pins to 14-bit readings (values from 0 to 16383):
analogReadResolution(14);
  • Turn a raw reading into volts:
float voltage = analogRead(A0) * 5.0 / 16383.0;
  • Find the zero point once in setup(), while the load is off. Read the sensor 1000 times and take the average:
zeroVoltage = readAverageVoltage(1000);
  • In loop(), average 200 readings to calm the noise, then turn volts into amps:
float current = (readAverageVoltage(200) - zeroVoltage) / 0.066;

Arduino UNO R4 Code - ACS712 DC Current

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-acs712-current-sensor */ // Arduino UNO R4 + ACS712 30A current sensor: measure DC current // Wiring: VCC -> 5V, GND -> GND, OUT -> A0 // Keep the load switched OFF while the board starts, so the zero point is right. #define SENSOR_PIN A0 #define VREF 5.0 // the analog pins of the Arduino UNO R4 work with 5V #define ADC_MAX 16383.0 // 14-bit ADC gives values from 0 to 16383 #define SENSITIVITY 0.066 // ACS712 30A version: 66 mV (0.066 V) per amp #define SAMPLES 200 // number of readings averaged for each result float zeroVoltage = 2.5; // sensor output at 0 A, measured again in setup() // Read the sensor many times and return the average voltage float readAverageVoltage(int count) { long sum = 0; for (int i = 0; i < count; i++) { sum += analogRead(SENSOR_PIN); } return (sum / (float)count) * VREF / ADC_MAX; } void setup() { Serial.begin(9600); analogReadResolution(14); // use the 14-bit ADC of the UNO R4 instead of the default 10-bit delay(1000); // give the sensor time to settle // Zero calibration: no current may flow through the sensor now zeroVoltage = readAverageVoltage(1000); Serial.print("Zero point: "); Serial.print(zeroVoltage, 3); Serial.println(" V"); } void loop() { float voltage = readAverageVoltage(SAMPLES); float current = (voltage - zeroVoltage) / SENSITIVITY; // volts -> amps Serial.print("Vout: "); Serial.print(voltage, 3); Serial.print(" V | Current: "); Serial.print(current, 2); Serial.println(" A"); delay(500); }

Detailed Instructions

Follow these instructions step by step:

  • If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
  • Wire the components according to the provided diagram.
  • Keep the 12V adapter unplugged for now, so no current flows through the sensor.
  • Connect the Arduino Uno R4 board to your computer using a USB cable.
  • Launch the Arduino IDE on your computer.
  • Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
  • Copy the code above and paste it into the Arduino IDE.
  • Open the Serial Monitor.
  • Click the Upload button to upload the code to the Arduino UNO R4. The board measures the zero point in the first second after it starts.
  • Now plug in the 12V adapter. The DC device turns on.
  • Check the results on the Serial Monitor.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno R4 WiFi' on 'COM15')
New Line
9600 baud
Zero point: 2.493 V Vout: 2.494 V | Current: 0.02 A Vout: 2.491 V | Current: -0.03 A Vout: 2.494 V | Current: 0.01 A Vout: 2.576 V | Current: 1.26 A Vout: 2.548 V | Current: 0.83 A Vout: 2.546 V | Current: 0.80 A Vout: 2.547 V | Current: 0.82 A Vout: 2.545 V | Current: 0.79 A
Ln 11, Col 1
Arduino Uno R4 WiFi on COM15
2

The first lines show the idle noise: a few hundredths of an amp, up and down around 0. This is normal for the 30A version. Here, the DC device is a 12V DC motor. When the motor starts, it pulls a short burst of current, then it settles at about 0.8A. If you slow the motor down by holding the shaft lightly, the current goes up.

※ NOTE THAT:

If the current reads about 0.5A or more with the load off, the zero point was measured while current was flowing. Unplug the 12V adapter and press the RESET button of the Arduino UNO R4 to measure it again.

Measuring AC Current

With AC, the current changes direction many times per second (50 or 60 times, depending on your country). So the OUT pin swings above and below the zero point all the time. One single reading means nothing, and a plain average is close to 0. Instead, we use the RMS value, which is the number a normal AC meter shows:

  • Sample the sensor for 200 ms. That covers 10 cycles at 50 Hz or 12 cycles at 60 Hz.
  • For each sample, take the distance from the zero voltage and square it.
  • Take the average of the squares, then the square root. Divide by 0.066 to get amps.
current_RMS = sqrt(mean((Vout - Vzero)²)) / 0.066

※ NOTE THAT:

Again: mains voltage is dangerous. Only measure a mains load if you know how to work with mains safely, keep the circuit unplugged while you wire it, and never touch the screw terminal while the power is on.

The wiring on the Arduino UNO R4 side stays the same. Only the load changes: the screw terminal goes in series with one wire of the AC load.

Arduino UNO R4 Code - ACS712 AC Current

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-acs712-current-sensor */ // Arduino UNO R4 + ACS712 30A current sensor: measure AC current (RMS) // Wiring: VCC -> 5V, GND -> GND, OUT -> A0 // Keep the load switched OFF while the board starts, so the zero point is right. #define SENSOR_PIN A0 #define VREF 5.0 // the analog pins of the Arduino UNO R4 work with 5V #define ADC_MAX 16383.0 // 14-bit ADC gives values from 0 to 16383 #define SENSITIVITY 0.066 // ACS712 30A version: 66 mV (0.066 V) per amp #define WINDOW_MS 200 // 200 ms = 10 cycles at 50 Hz, 12 cycles at 60 Hz float zeroVoltage = 2.5; // sensor output at 0 A, measured again in setup() // Convert one ADC reading to volts float readVoltage() { return analogRead(SENSOR_PIN) * VREF / ADC_MAX; } // Sample for WINDOW_MS and return the RMS current in amps float readCurrentRMS() { double sumSquares = 0; long count = 0; unsigned long start = millis(); while (millis() - start < WINDOW_MS) { float diff = readVoltage() - zeroVoltage; // distance from the 0 A level sumSquares += diff * diff; count++; } float voltageRMS = sqrt(sumSquares / count); return voltageRMS / SENSITIVITY; } void setup() { Serial.begin(9600); analogReadResolution(14); // use the 14-bit ADC of the UNO R4 delay(1000); // give the sensor time to settle // Zero calibration: average many readings while no current flows float sum = 0; for (int i = 0; i < 1000; i++) { sum += readVoltage(); } zeroVoltage = sum / 1000; Serial.print("Zero point: "); Serial.print(zeroVoltage, 3); Serial.println(" V"); } void loop() { float currentRMS = readCurrentRMS(); Serial.print("AC current (RMS): "); Serial.print(currentRMS, 2); Serial.println(" A"); delay(300); }

Detailed Instructions

  • Keep the AC load switched off.
  • Copy the code above and paste it into the Arduino IDE.
  • Click the Upload button to upload the code to the Arduino UNO R4.
  • Wait for the "Zero point" line in the Serial Monitor, then switch the AC load on (for example a small heater).
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno R4 WiFi' on 'COM15')
New Line
9600 baud
Zero point: 2.496 V AC current (RMS): 0.06 A AC current (RMS): 0.05 A AC current (RMS): 2.31 A AC current (RMS): 2.28 A AC current (RMS): 2.30 A
Ln 11, Col 1
Arduino Uno R4 WiFi on COM15
2

With the load off, the RMS value is not exactly 0. Noise always makes a small positive number after squaring, so a value under about 0.1A means "no current".

Video Tutorial

Function References

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!