 # Arduino uno using resistor shunt problems

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.

amps = sensor_value *(5/1024) * (300/0.05)

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.

Please post a schematic of some kind and all of your code using code blocks </>

It is always 0.

Use `(5.0/1024)`

or

``````amps = sensor_value * 29.3 // magic number means (5/1024) * (300/0.05)
``````
1 Like
``````float averageSensorValue =0;
int sensorValue ;
float voltage, current;

for(int i=0; i< ITERATION; i++)
{
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--;
}
}
``````

Moderator edit: more code tags

Please edit your post and place your code inside the code tag. It's a button on the bar that looks like this </>
Then, try what @chrisknightley said because it's correct. You are performing integer division.

I tried to check the analog pin readings
why the result always 0?

As far as I can see from your code, the your Arduino is running at 5V.
`5000mV / 1024(10-bits) ≒ 4.88mV`

If this specification is correct, 4.88mV means a current of 3.3A.
The ADC goes from 0/1024 to 1/1024 for the first time with a 3.3A current.

What is the current flowing during measurement?

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++)
{
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();

}
``````

Can you tell us what current you are passing through your shunt resistor?

The Uno has a 10 bit A/D so each bit is 5V/1024 =~ 5 mv.

With a 75mv/50 amp shunt, 5mv is approx 3.5 Amps.

You can lower the range of the A/D by specifying the internal ref ~ 1.1 volts
this will make each step of the A/D ~ 1mv so you will not be able to detect < 0.7Amps

When I have to troubleshoot an issue like this, I output the RAW A/D converter value.

Current on BTS (base transceiver station).

I tried to check the analog pin readings
why is the result always 0?

Is the result of analogRead(A3) always zero, or is the outcome of your calculation in post #1 already zero regardless of the reading of A3? It's not clear from your post.

Did you in fact look at this? You didn't respond, but it's a relevant remark.

This is not a schematic of your setup. I know this because (1) you state above you use A3, and (2) there's no Arduino in the picture and no power supply for it; long story short: a COMPLETE schematic, please.

One more thing: in theory there's nothing wrong with having an Arduino directly measure the voltage over a shunt resistor. But personally I think it's kind of tricky to directly connect an Arduino to what is apparently a piece of high-power electronics without any apparent interfacing or protection.

Alright, actually one more thing still: you mention a "resolution" (wrong term!) of 75mV for 50A. But what is the actual range that you need to measure, and at what resolution? I.e. the 4.88mV step size of the Arduino, corresponding to a 3.3A step size as @chrisknightley pointed out, is that sufficient? It's a very low resolution measurement you're performing.

Frankly, this all sounds very haphazard to me. Hence the emphasis on providing a good and complete schematic so that the people here can give you some advice on how to go about this effectively and safely.

3 Likes