 • Worldwide Shipping

• 24/7 Customer Support

• FAQ
• Worldwide Shipping

• 24/7 Customer Support

• FAQ

# HUM: digital ammeter ACS712

You are a beginner with Croduino. Or electronics? A specific module caught your eye, but you do not know how to use it? Do not worry, HUM is here for you! How to Use Module (HUM) is a blog tutorials series by e-radionica where you will find all you need in order to begin working with your favorite module. Tutorials include: technical characteristics, work principle, instructions on how to connect module with Croduino and the basic code. Everything else is left to your imagination.

## INTRODUCTION

In this tutorial we will get acquainted with a very simple, but useful device for current measuring. It is easy to connect the module to a microcontroller, e.g. Croduino and using the specific formula we will get accurate values and print them out in the SerialMonitor or even LCD module.

• Voltage: 5V
• Maximum current: 5A, 20A, 30A
• Output characteristic: 185 mV/A, 100 mV/A, 66 mV/A
• Output: 1.575V – 3.425V, 0.5V - 4.5V, 0.52V - 4.48V
• Measures both positive and negative current!

## HOW DOES IT WORK?

In the middle of the module there is an ACS712 chip which contains the Hall effect sensor located near the copper wires. According to the Ampère's law, the current-flowing conductor creates a magnetic field around itself, i.e. the magnetic fields occurs as a consequence of electric charge motion. Hall effect sensor will detect it and convert that signal to a certain output voltage. The positive thing about this measurement method is the fact that the rest of electronics is isolated from the cramps to which we connect the conductor, therefore Croduino's operation is safer.
The module is supplied with +5V on Vcc and as always when there is no current passing through the wire, the output voltage (Vout) "sits" in the middle, i.e. 2.5V. This characteristic allows measuring both positive and negative current, i.e. it is possible to measure current in both ways. In the chip's datasheet we see the sensitivity of individual module versions:

Let's take for example a module whose maximum current is 20A. This module's sensitivity is 100mA which means that the output voltage, if 1A current flows through the conductor, will be 2.4V, if 2A then 2.3V, if 3A, 2.2V and so on. Therefore, for each 1A change of current, the output voltage changes for 0.1V, or vice versa, if the module's output voltage changes for 0.1V, we know that the current flowing through the conductor has changed for 1A. After we find out for how many volts did the output voltage change, with the known module sensitivity, it is easy to get the accurate value of current passing through the conductor, and how to calculate it using Croduino, we will see a bit later in the "Arduino code" section.

AC CURRENT MEASUREMENT
As we have already said, this sensor can measure both positive and negative current. Such a characteristic can easily be used for alternating current measurements (periodically changing currents of the sine wave). Let's first remind ourselves of what shape the alternating current signal is and which values are important in order to measure it.

What we should actually find is the effective current value, because it is an actual indicator of what this current can "do" and it is equivalent to DC current.
By definition, effective alternating current value (time-varying) corresponds to that of the constant direct current (time-invariant) which produces the same amount of heat on the same resistance as the alternating current in the same period of time. We can see that if we find the maximum value of voltage/current we can calculate its effective value  (Vrms = Vpk / sqrt(2)). A code that measures AC current is attached at the end of the tutorial.

## HOW TO CONNECT IT?

The module is easily connected to Croduino, GND to GND, Vcc to +5V and center pin OUT to A0 whose values we will read. At the other end there is a green block to which we connect a conductor whose current we want to measure.

## ARDUINO CODE

We do not need any libraries for this module, because the reading of current value actually comes down to output voltage measurement which we convert to digital values, using the ACDC converter.
As we have already said, when there is no current passing through the conductor, the module's output voltage will be in the middle of Vcc. So, if we bring 5V to the module, the output will be 2.5V (512) and that level is labeled "mid" in the code. This data is important because we need the difference in volts of output's detachment from the center, rather than just the reading of module's output voltage.
Croduino contains 10bit ADCs so the maximum value is 1023, which corresponds to 5V voltage. Its middle is 2.5V, i.e. 512. However, this is not always the case because the voltage regulator's output is not always exactly 5V, and therefore the middle is not 2.5V. In order to compensate for this error, it is certainly necessary to first check the middle, i.e. "mid". In order to check how much it is, comment the first "l=" in the code, and then uncomment the second "l=", upload and open Serial Monitor. After the correction of mid-point, upload this attached code and the amounts of current we measure will print out in the Serial Monitor.
First find the detachment from the mid-point in the ADC reading, then we will get the change in volts by multiplying it with the amount of volts of one count (5/1024) and finally dividing it with module's sensitivity (1/0.100). The formula may be easier to understand via measurement units.
Note: Change the sensitivity in the formula depending on which module you are using! For module whose max current is 5A, sensitivity is 0.185 V/A, for max of 20A it is 0.100 V/A and for max of 30A it is 0.666 V/A. DC CURRENT MEASUREMENT

```#define mid 510

float I;

void setup() {
Serial.begin(9600);
}

void loop() {
I = (mid - analogRead(A0)) * 5.0 / 1024.0 / 0.100;
Serial.println(I);
delay(1000);
}

```

AC CURRENT MEASUREMENT

```#define sensorIn A0
#define sensitivity 100    //module sensitivity that is used [mV/A]

double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;

void setup() {
Serial.begin(9600);
}

void loop() {
Voltage = getVPP();
VRMS = (Voltage / 2.0) * 0.70710678;
AmpsRMS = (VRMS * 1000) / sensitivity;
Serial.print(AmpsRMS);
Serial.println(" Amps RMS");
}

float getVPP() {
float result;

unsigned int readValue;             // the value read from the sensor
unsigned int maxValue = 0;          // max value
unsigned int minValue = 1023;       // min value

unsigned long start_time = millis();
//measures for one second
while ((millis() - start_time)  maxValue) {
//if the read value is higher than the previous max value
// set this value as maximum
}

// if the read value is lower than the previous min value
if (readValue < minValue) {
// set this value as minimum