Measuring Current with the ACS712

Posted on 25/07/2017 by Adam

I wanted to dust off my Arduino IDE and throw some code together to test my battery bank which as usual I’ve posted on YouTube. I’m not so sure I’ve got the current measuring code quite right though.


Zero Reading Code

[code]
// LCD5110_Graph Library Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
//      SCK  - Pin 8
//      MOSI - Pin 9
//      DC   - Pin 10
//      RST  - Pin 11
//      CS   - Pin 12
//
#include <LCD5110_Graph.h>

LCD5110 myGLCD(8,9,10,11,12);

extern uint8_t SmallFont[];

void setup() {
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
}

void loop() {

  myGLCD.clrScr(); // Clear Screen buffer
  myGLCD.print("0:",0,0);
  myGLCD.printNumI(analogRead(A0),11,0);
  myGLCD.print("1:",42,0);
  myGLCD.printNumI(analogRead(A1),53,0);
  myGLCD.print("2:",0,12);
  myGLCD.printNumI(analogRead(A2),11,12);
  myGLCD.print("3:",42,12);
  myGLCD.printNumI(analogRead(A3),53,12);
  myGLCD.print("4:",0,24);
  myGLCD.printNumI(analogRead(A4),11,24);
  myGLCD.print("5:",42,24);
  myGLCD.printNumI(analogRead(A5),53,24);
  myGLCD.print("6:",0,36);
  myGLCD.printNumI(analogRead(A6),11,36);
  myGLCD.print("7:",42,36);
  myGLCD.printNumI(analogRead(A7),53,36);   

  myGLCD.update();
  delay(1000);
}
[/code]

Battery Evenness Tester Thingy Code

[code]
//Battery Evenness Tester Thingy by .

// LCD5110_Graph Library Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
//      SCK  - Pin 8
//      MOSI - Pin 9
//      DC   - Pin 10
//      RST  - Pin 11
//      CS   - Pin 12
//
#include <LCD5110_Graph.h>

LCD5110 myGLCD(8,9,10,11,12);

extern uint8_t SmallFont[];

float I0 = 0.0;
float I1 = 0.0;
float I2 = 0.0;
float I3 = 0.0;
float I4 = 0.0;
float I5 = 0.0;
float I6 = 0.0;
float I7 = 0.0;
int ZeroRead0 = 515;  //Adjust according to zero point reading
int ZeroRead1 = 515;
int ZeroRead2 = 514;
int ZeroRead3 = 513;
int ZeroRead4 = 511;
int ZeroRead5 = 512;
int ZeroRead6 = 513;
int ZeroRead7 = 512;

void setup() {
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
}

void loop() {

  I0 = (analogRead(A0) - ZeroRead0) / 102.4;
  I1 = (analogRead(A1) - ZeroRead1) / 102.4;
  I2 = (analogRead(A2) - ZeroRead2) / 102.4;
  I3 = (analogRead(A3) - ZeroRead3) / 102.4;
  I4 = (analogRead(A4) - ZeroRead4) / 102.4;
  I5 = (analogRead(A5) - ZeroRead5) / 102.4;
  I6 = (analogRead(A6) - ZeroRead6) / 102.4;
  I7 = (analogRead(A7) - ZeroRead7) / 102.4;

  myGLCD.clrScr(); // Clear Screen buffer
  myGLCD.print("0:",0,0);
  myGLCD.printNumF(I0,2,11,0);
  myGLCD.print("1:",42,0);
  myGLCD.printNumF(I1,2,53,0);
  myGLCD.print("2:",0,12);
  myGLCD.printNumF(I2,2,11,12);
  myGLCD.print("3:",42,12);
  myGLCD.printNumF(I3,2,53,12);
  myGLCD.print("4:",0,24);
  myGLCD.printNumF(I4,2,11,24);
  myGLCD.print("5:",42,24);
  myGLCD.printNumF(I5,2,53,24);
  myGLCD.print("6:",0,36);
  myGLCD.printNumF(I6,2,11,36);
  myGLCD.print("7:",42,36);
  myGLCD.printNumF(I7,2,53,36);   

  myGLCD.update();
  delay(250);
}

[/code]