Hi Im new to this forum and to ardunio as a whole, i currently have an adrunio uno that im making an amp meter to calculate the total amps i use throughout the day. The problem that im facing is that when i take voltage reading using a voltage divider to A0, the value changes a bit and doesnt become constant, for example if im measuring a 1.4V battery i will get reading from .8v to 1.6v.
Below is the code im using to calculate total amps its working but values still fluctuate alot.
when my real current is 3.5A, the arduino will measure it and it changes continuously between 2.5A and 5.5 Amps.

#include<LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);
float TotalAmps=0.0;
void setup()
{
analogReference(DEFAULT);
lcd.begin(16,2);

}
void loop()
{
{
lcd.clear();
float temp = analogRead(A0); //voltage across shunt resistor
float millivolt = temp * (5000 / 1023.0);
lcd.setCursor(1,0);
lcd.print(millivolt);
lcd.print(“mv”);
float volts = millivolt/94.78873; //divide by 94.7 the value of the op-amp gain

float Amp = volts/5.135135; //volts/value of resistor
lcd.setCursor(0,1);
lcd.print(Amp);
lcd.print(" A “);
float Ampsused = Amp/1000; //divide the amps to take the real amps charged during the loop
TotalAmps=Ampsused+TotalAmps;
lcd.print(TotalAmps);
lcd.print(” TA");
delay(3600);
}

}

Hi, welcome to the forum.

Do you have a protection resistor to A0 ? Could you add a 4k7 between the 'hot' side of the shunt and the A0 input of the Arduino board.

You could try the internal 1.1V reference for a better accuracy.

I think that (almost) no one uses the Arduino to measure the voltage over a shunt. The shunt should have a low value, and that results in a low voltage. That is too low for the Arduino for accurate measurement.
But the main problem will be the ground current from the shunt resistor, it will make it almost impossible for an accurate measurement of the voltage over the shunt.

Peter_n:
Hi, welcome to the forum.

Do you have a protection resistor to A0 ? Could you add a 4k7 between the 'hot' side of the shunt and the A0 input of the Arduino board.

You could try the internal 1.1V reference for a better accuracy.
http://arduino.cc/en/Reference/analogReference

I think that (almost) no one uses the Arduino to measure the voltage over a shunt. The shunt should have a low value, and that results in a low voltage. That is too low for the Arduino for accurate measurement.
But the main problem will be the ground current from the shunt resistor, it will make it almost impossible for an accurate measurement of the voltage over the shunt.

Thanks for your reply and help, sorry i forgot to mention that im using a non-inverting configuration op-amp with a gian of 94 , to amplify the voltage across the shunt. I have just tried adding 4k7 resistor i believe the the fluctuation is less, on a 3.6A load i got values between 3.2A and 4A.The thing is where i live we have very limited resources, do thing theirs a better way to measure and log current which is simple and accurate? Thanks again alot
**just a note i have logged the values for 20 minutes and it averaged the same as my logging clamp meter

With an OpAmp, the protection resistor is not needed.

For slow signals (like the current) I always use some averaging. For example the average of 5 or 20 samples wll improve it a lot.
The 5V voltage of the Arduino should be very stable, since that is used as reference when analogReference(DEFAULT) is used. The USB power might not be a good 5V.
Could you try with an external power supply of 7.5V or 9V ?

The accuracy depends on the circuit and the opamp. There are special opamps for high-side and for low-side current measurement. And maybe you have some oscillation going on, a single capacitor in the right place can avoid that.
Do you use a breadboard ? those have sometimes bad contacts. A bad ground could cause all these troubles.

Is the Arduino board a cheap clone ? Someone this week made a photo of his board, and the 100nF that is connected to AREF and GND was missing. That is needed for analogRead().

I still don't understand why the voltage varies so much, between 0.8V and 1.6V. Also the current between 3.2A and 4A is way to much variation. Something is wrong.

If you have a stable voltage for the Arduino, and solved any oscillation, and avoid cheap breadboard, then you might need to draw your circuit. You can draw it on a piece of paper and make a photo of it. You can also upload a photo of the circuit that shows the wiring.

P.S.: You don't have quote my message, since my message is already there You can use the Reply button or the Quick Reply text field. With the Reply button, you see the text "Additional options..." at the lower left below the text field, that is to attach a photo.

Thanks alot for all your help, i tried using a 9v supply but still with the same results, i have tried using the arduino as a normal voltmeter and readings are very accurate when the voltage is equal or greater than 2volts but less than that and i get a swing of around 50mv. Im planing on soldering the circuit in order to be sure of all the contacts. Do u think if i used and op-amp as an amplifier then shifted the result by 2V using an op amp that i will get a more accurate reading? http://www.ti.com/analog/docs/microsite.tsp?micrositeId=7&sectionId=560&tabId=2181 There is a pull down resistor R3 could it be taken to ground instead of -5V? Below i attached the schematic im using and a real life photo . Thanks Alot again.

but : link to Atmel Atmega 328p datasheet and you will see that 1.1 V ref is given between [1.0 V and 1.2 V] according to the batch.
In the datasheet Atmel provides a method to measure the Vref exact value.

An OpAmp at 12V ? Maybe you can keep that protection resistor to prevent 12V going into the Arduino.

In the schematic, I'm missing a connection from the battery to the Arduino GND.

A value that is not accurate for low voltages could be an offset due to ground current.
Or the OpAmp is not the right one for this.
Could you measure the input voltage at the Arduino pin with low current, to see if the OpAmp voltage can go low enough ?

A 9V battery is often not enough for a background light of a display. But I don't see a background light ?

The link is for the OPA335, to get the output closer to 0V. That is only for the OPA335 I think.
Sparkfun has a high-side current opamp : SparkFun Current Sensor Breakout - INA169 - SEN-12040 - SparkFun Electronics
If you select the "Hookup Guide", they also have a resistor at the output to GND. The INA169 is a special current shunt opamp.

I did find this : Let's Make Robots - RobotShop Community
That is without resistor at the output.

Hello,
I'm new to the forum. Sorry for my poor english .
I think the problem is the LM324 . This is not a rail to rail opamp and can not measure voltages close to the GND.
It is possible to use the inverting input. Place the shunt in series with R2.
Of course, the measurement is then inverted.

Actually, the LM324 -can- measure input voltages close to ground. The main limitation is that the output cannot go higher than 1.5V below the power supply voltage, and that isn’t an issue here.

From the datasheet:

Input Common-Mode Voltage Range Includes Ground

To the OP: What are you doing with the other three Op Amp sections? If you let them just float, they are likely to break into oscillation, causing massive amounts of noise and possibly even destroying the chip.

You should add a 10uF and 0.1uF capacitor from AVCC to ground, and AREF to ground.

Thanks everybody for your help, i guess im a little over my head in this. I have been doing a little testing using the arduino as a voltmeter, when using the code double temp = analogRead(A1);
double volt = temp * (5.0 / 1023.0); with a input of 100mv im getting a reading 0.09v-0.08v which is pretty good i guess And an input of 1.001V gave 0.98-0.97V. When using the code double temp = analogRead(A1);
double volt = temp * (5000.0 / 1023.0); With the same input of 100mv im getting a reading of 78.2mv to 92.86mv, which is alot of fluctuation When i added a 10uf capacitor to the input the reading became 83.09mv to 87.98mv which is better but still, with 1.001V input i got a reading of about 974mv. Adding a 0.1uf cap to Aref didnt have any effect neither did a 10uf cap.

I have changed the old op-amp (accidentally fried it) the new schematic is attached below i have connected to unused inputs to ground refered to in the link Perter kindly provided
I have tested the Op-amp as Peter_n suggested on low voltages and current, with an input of 5.9mv the output was 54mv. and at 2.3mv the output was 13mv (not functioning correctly), at 4.8mv input the output was 41.6mv, at 20mv input output is 0.205v, 90mv input 0.989V output. Sadly where i live i cant order anything online and am limited to local shops.

In conclusion the main problem im facing is getting an accurate reading off the arduino everything else is fine. Thanks again everybody

No, no, no, no, no!!!!!

So you are using Vcc for the reference? How accurate is it?

Yes the op-amp is working accurately, im thinking of just getting and ic with one in it. But the main issue is getting accurate voltage reading in general from the ardunio, with out the op-amp. once we can get accurate reading we wont have an issue when adding the op-amp.
Thanks again everybody

when using the code double temp = analogRead(A1);
double volt = temp * (5.0 / 1023.0); with a input of 100mv im getting a reading 0.09v-0.08v which is pretty good i guess And an input of 1.001V gave 0.98-0.97V. When using the code double temp = analogRead(A1);
double volt = temp * (5000.0 / 1023.0); With the same input of 100mv im getting a reading of 78.2mv to 92.86mv,

I don't see any difference here. Your posted results for code 1 has precision of .01v, but your posted results from code 2 has precision of .0001v.

Back to Polymorph's question: What is your reference voltage? How accurate is it?

And back to: your Op Amp is connected incorrectly. Why are you ignoring me on that?

Did you read the link I gave? It actually gives precisely the connection you show as one of the wrong ways to connect unused sections, and tells you why.

polymorph:
And back to: your Op Amp is connected incorrectly. Why are you ignoring me on that?

Im not ignoring you at all, I really appreciate all your help. Can you please explain more on how to connect it correctly? Do i have to use two power supplies? "Input Common-Mode Voltage Range Includes
Ground " from the lm324 datasheet can i use Vcc and ground to power the op amp, and connect as a buffer as showed but instead connect V+ve to ground? Thanks again alot

What you have put in your schematic is essentially

Joining the inputs to each other but leaving them otherwise unconnected has almost exactly the same, bad, effects.

We are not talking about dual power supplies, we are talking about the inputs! This is how to connect it correctly:

The simplest way to provide such an input is to connect to the midpoint of two high value (~½ MΩ) resistors in series between the supply rails.

I said it here:

Thanks again everybody its working much better after following Polymorph instructions on how to connected the unused op-amps, thanks alot sorry for being such a pain in the ___, i just couldn't get my head around it. My results are much more accurate and stable now.