Current sensing with an Arduino

Current sensing is not quite as easy as voltage sensing. A popular sensor for current on the Arduino is the ACS712 And a typical version is shown above.

The ACS712 consists of a precise, low-offset, linear Hall sensor circuit with a copper conduction path located near the surface of the die. Applied current flowing through this copper conduction path generates a magnetic field which is sensed by the integrated Hall IC and converted into a proportional voltage. Device accuracy is optimized through the close proximity of the magnetic signal to the Hall transducer. 

The terminals of the conductive path are electrically isolated from the sensor IC leads and this allows the ACS712 current sensor IC to be used in applications requiring electrical isolation without the use of opto-isolators or other costly isolation techniques.

A sample sketch to test the sensor is shown here. The output voltage from the sensor is proportional to the current flowing in the test circuit and the Arduino reads this voltage and prints it out as current.

/*ACS712 Current sensing board
Gnd on sensor to Gnd on Arduino
Vcc on sensor to +5volts on Arduino
Out (or S) to A2 on Arduino
Connect the screw connections to the test circuit in series with the load

int VQ;
int ACSPin = A2;

void setup() {
VQ = determineVQ(ACSPin); //Quiscent output voltage - the average voltage ACS712 shows with no load (0 A)

void loop() {
Serial.println(" mA");

int determineVQ(int PIN) {
Serial.print("estimating avg. quiscent voltage:");
long VQ = 0;
//read 5000 samples to stabilise value
for (int i=0; i<5000; i++) {
    VQ += analogRead(PIN);
    delay(1);//depends on sampling (on filter capacitor), can be 1/80000 (80kHz) max.
VQ /= 5000;
Serial.print(map(VQ, 0, 1023, 0, 5000));
Serial.println(" mV");
return int(VQ);

float readCurrent(int PIN) {
int current = 0;
int sensitivity = 185.0;//change this to 100 for ACS712-20A or to 66 for ACS712-30A
//read 5 samples to stabilise value
for (int i=0; i<5; i++) {
    current += analogRead(PIN) - VQ;
current = map(current/5, 0, 1023, 0, 5000);
return float(current)/sensitivity;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s