Built-in project · Arduino Uno R3

Motor current meter on an Arduino Uno

An ACS712 in a 6 V gear motor’s lead and a 16x2 I2C LCD: the current now and the highest seen, with the start-up surge a motor draws before it gets going. The whole build, an Arduino Uno and 5 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Beginner Runs in your browser. Free, and no account needed.

The parts retail for about $37. On Mokxi they're free.

Step by step, with the wiring and the common mistakes: Arduino ACS712 Current Sensor: Wiring and Code

Motor current meter · Arduino Uno R3live0.000 s 0.00x
Press Run, then hold the button
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// Motor current meter: an ACS712 5 A current sensor in a gear motor's lead,
// and the current on a 16x2 I2C LCD.
//
//   A0      the ACS712's OUT (its VCC on 5 V, GND on GND)
//   IP+     from the push button, on the bench supply's plus
//   IP-     to the motor, whose other lead goes back to the supply's minus
//   LCD     SDA -> A4    SCL -> A5    VCC -> 5 V    GND -> GND
//
// The ACS712's output is half its supply with no current and moves 185 mV an
// amp on the 5 A board. The motor's circuit never touches the Arduino's: the
// sensor measures the field the current makes, through the chip's insulation.
//
// Nothing flows until the button is held, so the sketch measures the zero at
// power on with ACS712's autoMidPoint(). Then it averages 50 readings at a time, which
// smooths the sensor's noise, and keeps the highest current it has seen.
// Hold the button and the peak catches the surge a stalled motor draws
// before it spins up; the running current is a few converter steps above
// zero, because one step on the 5 A board is 26 mA.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "ACS712.h"

ACS712 ACS(A0, 5.0, 1023, 185);
LiquidCrystal_I2C lcd(0x27, 16, 2);
float peak = 0;

void setup() {
  Serial.begin(115200);
  Serial.println("Mokxi Arduino Uno: motor current meter");
  lcd.init();
  lcd.backlight();
  lcd.print("Zeroing...");
  ACS.autoMidPoint();
  Serial.print("Midpoint: ");
  Serial.println(ACS.getMidPoint());
  lcd.clear();
}

void showLine(int row, const char *label, float mA) {
  lcd.setCursor(0, row);
  lcd.print(label);
  int whole = (int)(mA + (mA < 0 ? -0.5 : 0.5));
  lcd.print(whole);
  lcd.print(" mA     ");
}

void loop() {
  // For a fifth of a second, take quick averages of ten readings: quick
  // enough to catch the surge for the peak. The screen shows their average.
  float sum = 0;
  int n = 0;
  unsigned long began = millis();
  while (millis() - began < 200) {
    float mA = ACS.mA_DC(10);
    if (mA > peak) peak = mA;
    sum += mA;
    n++;
  }
  float mA = sum / n;
  showLine(0, "Now  ", mA);
  showLine(1, "Peak ", peak);
  Serial.print("mA: ");
  Serial.print(mA, 0);
  Serial.print("  peak: ");
  Serial.println(peak, 0);
}

Parts list

6 parts, plus the jumper wires and a bench instrument. The parts retail for about $37; on Mokxi they're free, and so are the instruments.

How it is wired

8 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.

  • Arduino Uno R3 pin 5V; Current sensor, ACS712 pin VCC; Character LCD with I2C backpack pin VCC
  • Ground: Arduino Uno R3 pin GND; Current sensor, ACS712 pin GND; DC motor pin 2; Bench power supply pin V-; Character LCD with I2C backpack pin GND
  • Arduino Uno R3 pin A0; Current sensor, ACS712 pin OUT
  • Arduino Uno R3 pin A4; Character LCD with I2C backpack pin SDA
  • Arduino Uno R3 pin A5; Character LCD with I2C backpack pin SCL
  • Current sensor, ACS712 pin IP+; Pushbutton pin 2a
  • Current sensor, ACS712 pin IP-; DC motor pin 1
  • Pushbutton pin 1a; Bench power supply pin V+

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.