Hi. This is my first post on the Forum.
Im building an amp meter using arduino and this sensor: http://www.panucatt.com/files/datasheets/cs50_100_200a_datasheet.pdf
It´s a 100amp hall sensor and I made a sketch for read this sensor , although with no consistent results.I think the equation is wrong and I have no clue where to start .
here is the sketch:
const int numReadings = 200;
int readings[numReadings]; //numero de leituras do pino
int index = 0; // indice de leitura
int total = 0; // total de leituras
float average = 0; //media
int inputPin = A0;
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
lcd.begin(16, 2);
Serial.begin(9600);
for (int thisReading = 0; thisReading < numReadings; thisReading++)
readings[thisReading] = 0;
}
void loop() {
total= total - readings[index];
readings[index] = ((analogRead(inputPin)*(5.0/1024.0))-2.5)/.02; //thats where I think It´s wrong.
total= total + readings[index];
index = index + 1;
if (index >= numReadings)
index = 0;
average = total / numReadings;
Serial.println(average, 2);
lcd.setCursor(0, 1);
lcd.print("Amps ");
lcd.print ((average),2);
}
The equation i took from the .PDF datasheet.
The LCD displays weird measures, like 50 60 amps ( Im measuring 12.5a on my clamp meter) and when the amps get lower, the measures on display don´t follow this decreasement.What´s wrong?
Hi Magician,
If i declare int readings[numReadings]; as float, amps decrease 1 amp per second. (????). I noticed now that total must be float.
Il´l upload the new code and see what happens.
To make sure you are getting the right readings, make a single read on the analog port where the sensor is connected and output it in the LCD. If thats ok look at other code lines where the results gets changed.
If you suspect the Sensor is acting funky, measure the output at Vout with no load (it should be 1/2 of your Vcc) then apply a known current load(say 12Amps) Measure Vout then use the formula in the specsheet to compute for the measured current. If its too far off from your known current load then there maybe something wrong with the sensor. Contact me roy@panucatt.com
Your equation looks right to me, assuming you are driving the Hall sensor from the 5v regulated supply. I would declare both 'total' and 'readings' float instead of int.
Is the current AC or DC? As you are using a clamp meter to compare readigs, I presume it is AC. In this case your hall sensor will measure both positive and negative currents. To display the RMS current (as your clamp meter does), you need to sum the squares of the readings (instead of the readings) over one or more complete cycles of the 50Hz or 60Hz current, divide by the number of readings to get the average square, then take the square root of the average and display that.
Hi dc42,
It's DC Current. My fault was on variable declaration. It messed all up ( float is the correct declaration).Im measuring high currents on a 28v alternator. I've checked the results on arduino and my clamp meter and they are very precise now (15.3 amp read on arduino and 15.3 on clamp meter). Now I'm planning to build a voltage divider for voltage measurements, but that's another story .
Cheers from Brazil.
I hope this is not a dead post.
Im getting very accurate results woth this sensor.But when the amps decrease drastically, the sensor seems to hang on older values. After a drastically amp decrease ( 15 amps to 2 amps), my clamp meter measured correctly, althgough arduino hang on 15 amps. What should I do? Is 200 readings too much for average amp reading?
Thanks in advance. This forum helped me a lot on my little experiment.
Are you sure your Arduino is still running when the current sticks at 15A? Maybe it has crashed. You might want to have an LED blinking to show that the Arduino is still running.
Your totalising algorithm is subject to rounding error because you are doing the maths in floating point. I suggest you do the totalising using integer maths and only convert to float to do the average and the final calculation, like this:
const int numReadings = 200;
int readings[numReadings]; //numero de leituras do pino
int index = 0; // indice de leitura
long total = 0; // total de leituras
float average = 0; //media
int inputPin = A0;
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
lcd.begin(16, 2);
Serial.begin(9600);
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings[thisReading] = 0;
}
total = 0;
}
void loop() {
total = total - readings[index];
readings[index] = analogRead(inputPin) - 512;
total = total + readings[index];
index = index + 1;
if (index >= numReadings) { index = 0; }
average = ((float)total * (5.0/1024.0) / ((float)numReadings * 0.02);
Serial.println(average, 2);
lcd.setCursor(0, 1);
lcd.print("Amps ");
lcd.print ((average),2);
}
Thanks again DC42.
Im new into programming. Im studying it for about 3 months. Everyday I learn something new.This is a solution which I never find by myself. I´ll try the code and tell if everything was ok.