Measuring Current by a shunt resistor in Proteus using Arduino

I need to measure the current through a load using a shunt resistor rated 75mV and 300A.
I have made the following circuit in proteus:

Screenshot 2022-04-20 173645

and the following code on Arduino IDE:
const int inPin =A0;//can change
int sensorValue;
double voltage, current;

void setup() {
Serial.begin(9600);
}

void loop() {
sensorValue = analogRead(inPin);
voltage = ((sensorValue) *5) / ((pow(2,10)));
current = voltage /(0.00025) ;
Serial.println("Current is: ");
Serial.println(current);
delay(500);
}

The value of the current that i get is very weird and not even close to the actual value.
Any help?

Don't use pow() for powers of two - that's just silly.

This section of the forum is for tutorials you are presenting.

Please remember to use code tags when posting code

The Uno measures in 5volt / 1024 = ~5mV steps.

Voltage across the 0.25 ohm shunt = 0.25 / (1000 + 0.25) * 15volt = ~3.75mV,
which is below the first step of the A/D.

So you can't measure 15volt / 1k = 15mA with this setup.
Resolution is about 20mA per A/D step.

You need an external A/D with a higher resolution, like the INA226.
Leo..

voltage = ((sensorValue) *5) / ((pow(2,10)));

There's no need to calculate the ADC range every time through the loop. :wink: There's no need for your software to calculate it at all... Just use 1023 or 1024. (I think 1024 is recommended but I don't remember why.)

You can use the optional 1.1V reference for about 1mV resolution, but that still might not be enough.

I don't know why you're getting 60mA. It might be a Proteus "quirk". I assume Proteus is simulating the hardware and software? I've never used it but I'm sort-of skeptical of software simulation.

You might want to print-out the raw ADC reading and the voltage reading.

And you can actually combine both equations (technically "expressions") in to one. There's no need to explicitly calculate voltage separately (although it can be helpful for debugging).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.