Here is what these sensors look like for only $2. You won't attach any big cables to these terminals.
http://www.ebay.com/itm/5A-Range-Current-Sensor-Module-ACS712-Electronic-Parts-ZH/122101638970?_trksid=p5713.c100284.m3505&_trkparms=aid%3D111001%26algo%3DREC.SEED%26ao%3D8%26asc%3D20140905073823%26meid%3D9b416b9a19df4c9cb2225a45eea24b4e%26pid%3D100284%26rk%3D2%26rkt%3D7%26sd%3D122101638970I still do reckless coding and let the compiler figure it out. I often skip putting a colon at the end or a parenthesis and misspell/typo a variable. My mind goes faster than my typing. These sample programs are a convenient start to anyone's own requirement. I would be interested in anyone's take on the code explanations I have provided as to what needs further explanation.
I have a refrigerator that runs off a HF inverter. These inverters will lock out in an over/under voltage. situation. They only reset when power switch is turned off. Monitoring fridge current would allow you to reset the power in case of a problem. Otherwise you need timers to limit run time in the program.
The following can be used on AC and should approximate the RMS current if you sample fast enough or long enough. It turns every read into a positive number. These are added every loop. The number of loops is used as the multiplier for the current. Sensor noise is eliminated by changing the value at which data is accepted into the count. Second isn't a second in this example.
// ACS712-3
// This program reads a ACS712 HALL sensor on pin A3
// measuring AC current and adding to a count value
// serial outputs data every second & flashes LED
int second = 0;
int count = 0;
int ACScount = 0; // raw A/D of hall sensor
int offset = 530; // offset nominal for zero
unsigned int amptotal = 0; // accumulated current
int loopend = 25; // number of loops
void setup()
{
Serial.begin(9600); // setup serial
pinMode(13, OUTPUT); // sets the digital LED pin 13 as output
}
void loop() {
ACScount = analogRead (3); // read sensor on pin A3
if (count > loopend) // end count
{ // this bracket indicates start of actions
// when IF is true
count = 0; // reset count
second = second + 1; // increment second
amptotal = 0; // reset amp count
} // end of those operations
delay(1); // waits for a 1/1000 second or use program delay
if (ACScount > offset + 10)amptotal = amptotal + (ACScount - offset);
// add any positive number
if (ACScount < offset - 10)amptotal = amptotal - (ACScount - offset);
// subtract any negative number....which is an ADD
// every A/D read is added as a positive number
// by adding or subtracting to the nominal offset
// noise around zero is eliminated
// printout divide by 1000
// 25 loops is just a multiplier to make numbers come out
// SEND DATA TO SERIAL IN TOOLS
// Printing takes time. Comment out this in final working program.
// data every second
if (count == loopend)
{
Serial.print(ACScount); // raw A/D count
Serial.print(" A/D ");
Serial.print(offset); // offset
Serial.print(" offset current = ");
Serial.print((float) amptotal / 1000); // amps
Serial.print("A ");
Serial.print(" ");
Serial.println(second); // second
}
if (second > 32000) (second = 32000); // limit upper second count
count = count + 1; // increment count
}
This could also be done with the absolute function.......
ACScount = ACScount - offset // get any positive or negative number
ACScount = abs(ACScount) // get absolute value
// math functions can not be done inside abs function
if (ACScount > 10) amptotal = amptotal + ACScount;
// add any number greater than 10
// every A/D read is added as a positive number
// by suntracting the nominal offset and taking absolute value
// noise around zero is eliminated by ignoring values under 10