What code should I use to measure correct current in my circuit?Pololu has given some sample code but I can't understand the idea and write my own code.Here is the code given:
VIOUT = (0.028 V/A * i + 2.5 V) * VCC / 5 V
pololu page
Here's one way, maybe not the best but give it a try.
void setup() {
Serial.begin(9600);
}
void loop() {
float aRef = 4.98; // AREF voltage measured with accurate volt meter
float amps;
amps = (analogRead(A0) * aRef / 1023.0 - (aRef / 2)) / 0.028;
Serial.println(amps);
delay(1000);
}
Guys who I bought it from gave me a peace of code:
current_sensor = analogRead(A8);
output_amp = (current_sensor/2 - (current_sensor*5.0/1024))/5.734;
amps = output_amp/1000;
but I'll try yours as well.thanks!