Hi
i am trying to use some ACS712 30A at 12v to measure the currents on a solar panel and the battery charger but I get totally unusable crazy erratic values. in most cases i only need 0-20 or 2-10A ranges.
so first is there a better sensor?
I was thinking of ina219 but insufficient range, or acs758lcb, I now also find the acs37800 interesting. I don't need very high precision. 0.1A or even 0.5A is good enough.
I tried a few ACS712 but values are crazy, i even get random negative values no matter what I do to remove the minus even unsigned int goes negative.. abs() goes negative, AxA/2 goes negative.. seriously.. something is nuts. it is running on arduino nano.
I try averaging many measurements (hundreds) but any current will give erratic values anything from 0 to 65000...
any help is welcome
Not sure from your post how you are using the ACS712 so I'll comment from experience with the 20 amp version. Running the ACS712 from 5v will give an output of 2.5 volt at 0 amps. It handles ac and + and - dc current. the range is 1.5 volts out = -20 amps and 3.5 volts out = +20 amp. I used the following code to test:-
/*----------------------------------------------------------------------------------------------SKETCH DETAILS
ADD THE SKETCH TITLE BELOW TO SETUP PRINT STATEMENT TO SHOW EXACT VERSION ON BOOT !!!!!
*/
#define title "NANO_ACS712_TEST_211216a"
#define notes "ACS712 CURRENT MONITOR "
#define devices "NANO, old bootloader."
#define codemine "ME"
//-------------------------------------------------------------------------------------------------------------
#include "LibPrintf.h"
float battVolts = 0;
float battCurrent = 0;
//-------------------------------------------------------------------------------------------------------------
void setup() {
analogReference(INTERNAL); // internal 1.1v reference.
pinMode(A0, INPUT), pinMode(A1, INPUT);
Serial.begin(9600);
delay(1000);
printf("\n........................................................................\n");
printf(" Title: %s\n Notes: %s\n Devices %s\n Code source: %s\n",title,notes,devices,codemine);
printf(".........................................................................\n");
}
//-------------------------------------------------------------------------------------------------------------
void loop() {
// battVolts = analogRead(A0); // 0.0186
int bi = analogRead(A1); // OFFSET IS 2V5.
float biOffset=717; //0.00A
float biConst=0.031746;
battCurrent=(bi-biOffset)*biConst;
printf(" Analog in = %i battCurrent = %f \n",bi,battCurrent);
delay(1000);
}
//-------------------------------------------------------------------------------------------------------------
Whoops.. I should have added that I used a 10k pot as a divider. Top of pot to ACS712, slider to analogue in and bottom of pot to ground. Just adjust the pot to keep the analogue in below 1 volt.
B.
Pin A3 on what...
Most of us know what an ACS712 is, but none uf us know which Arduino and code you're using.
Don't say it's a Nano without specifying it. Nano is a generic name for many different boards.
Also walk us through the solar setup. The solar controler could be a PWM type.
Leo..
ok so it is on an analog pin A3 on a arduino nano board, noname, with a Mega328p chip old bootloader.
I am also wondering if the current is not pulsed in some way.
exactly negative is totally impossible but i get negatives randomly...
here the demo code from the library: doesnt work.
//
// FILE: ACS712_20_DC_DEMO.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo to set the midPoint and the mVperAmpere.
// URL: https://github.com/RobTillaart/ACS712
#include "ACS712.h"
// Arduino UNO has 5.0 volt with a max ADC value of 1023 steps
// ACS712 5A uses 185 mV per A
// ACS712 20A uses 100 mV per A
// ACS712 30A uses 66 mV per A
ACS712 ACS(A3, 5.0, 1023, 66);
void setup()
{
Serial.begin(115200);
while (!Serial);
ACS.autoMidPoint();
}
void loop()
{
int mA = ACS.mA_DC();
Serial.println(mA);
delay(1000);
}
With that library, it will measure negative currents, so negative numbers are to be expected.
With nothing connected, what you are seeing is just random noise.
Try shorting the inputs together, you may see less random noise
Note in my code I use the arduino internal reference 1 volt. It's an old habit using a divider as a bit of protection. You can use the output from the acs712 directly, just comment out the "Analogue reference" line in the code.
B