Hello guys,
I need some help. I can’t understand why it's not printing out any value beside 0 on my serial monitor. So I use a Shunt resistor that has the resolution of 75mV for 50A. why the analog pin can't be read when connected to a resistor shunt? the data just reads 0 only...
The real problem is, when I convert this number to Amps, I always get 0.
by doing hand calculations, this formula gets me a value that make sense. Can somebody explain to me why I always get 0 at Serial.println(amps).
Thanks so much.
here the sketch code
const int inPin =A3 ;
const float SHUNT_CURRENT =50.0;//A
const float SHUNT_VOLTAGE =75.0;// mV
const float CORRECTION_FACTOR = 2.00;
const int ITERATION = 50; //can change
const float VOLTAGE_REFERENCE = 1100.00;//1.1V
const int BIT_RESOLUTION =10;
const boolean DEBUG_ONCE = true;
void setup() {
Serial.begin(9600);
Serial.println("Measuring Current DC");
analogReference(INTERNAL);//1.1V internal reference
delay(500);
}
void loop() {
printCurrent();
getCurrent();
delay(500);
}
float getCurrent(){
float averageSensorValue =0;
int sensorValue ;
float voltage, current;
for(int i=0; i< ITERATION; i++)
{
sensorValue = analogRead(inPin);
delay(5);
if(sensorValue !=0 && sensorValue < 100)
{
voltage = (sensorValue +0.5) * (VOLTAGE_REFERENCE / (pow(2,BIT_RESOLUTION)-1));
current = voltage * (SHUNT_CURRENT /SHUNT_VOLTAGE ) ;
if(i !=0){
averageSensorValue += current+CORRECTION_FACTOR;
}
delay(1);
}else{
i--;
}
}
//IGNORE_CURRENT_BELOW
averageSensorValue /=(ITERATION-1);
return averageSensorValue;
}//getCurrent()
void printCurrent()
{
Serial.println("Current:");
Serial.print(getCurrent(),2);
Serial.println("A");
Serial.println();
}
Moderator edit: code tags added