# Measuring amperage

Hi ,

I have a rx27-1 , 5w r1j resistor connected up in series on the negative rail of something which i want to measure the current of.
I have measured the resistor as 0.5ohms on my less than good multimeter, it will only give me one decimal place.

I also have a voltage divider set up to measure voltage at the source, I have chosen r1 as 5k and r2 as 2.2k. That part is accurate to one decimal place according to the again less than great lab supply.

My amperage however seems to be up to 0.5a lower than the reading on the lab supply,
my code is the following:

``````float amps;

float Aread;
float maxamps;

float vin =0;    /////////////////the 1024 value seen by the pin/////////////////
float vpin=0;   /////////////////convert 1024 to real voltage at the pin//////////
float vout=0;    /////////////////convert votlage at pin to voltage at source///////////

void setup() {
pinMode(A0,INPUT);
pinMode(A3,INPUT);
Serial.begin(9600);
}

void loop() {

Aread= analogRead(A3);
Aread=(Aread/1023)*5;
Aread=Aread/0.5;

Serial.println("AMPS");
Serial.println(Aread);

Serial.println("VOLTS");
Serial.println(vout);

vin=analogRead(A0);
delay(20);
vin=(vin/1023)*5;
vout= vin * 3.15;
//vout = vin / 62.9;
if(Aread>maxamps){
maxamps=Aread;
}
Serial.println("MAXamps");
Serial.println(maxamps);

}
``````

Could anyone shed some light on what might be going wrong?
The arduino is being powered over FTDI at 5v, there is no connection to any other power source for the arduino,
Its ground is connected to the other side of the shunt resistor, the other side being the opposite side to where the analogue pin is connected.

I want to be able to make a crude wattmeter for an Rc model, I plan to bench test some motors soon and would like to know the power they are using, and be able to graph it over time,
so obviously the second part of the story will be to add an SD card for data logging and then use that to graph, I have that already implemented on another project though so it should be easy enough to bring over to this one.

Its important that the readings be as accurate as possible because eventually I would like to use the same technique to measure the capacity of a battery during discharge.

thanks in advance

``````  Aread=(Aread/1023)*5;
``````

Are you certain that you are using 5.000V as the reference voltage?

The arduino is being powered over FTDI at 5v, there is no connection to any other power source for the arduino,

That's no guarantee.

``````  Serial.println("VOLTS");
Serial.println(vout);

vin=analogRead(A0);
delay(20);
vin=(vin/1023)*5;
vout= vin * 3.15;
``````

Print the value of vout, and then compute it. What a great idea. I wonder why more people don't put the cart in front of the horse that way.

Where'd the 3.15 come from?

I have measured the resistor as 0.5ohms on my less than good multimeter, it will only give me one decimal place.

Even at one decimal place of accuracy, I'd question whether you could tell the difference between a half ohm resistor and a wire.

There are techniques to measure very low resistances with an ordinary multimeter - but sorry I have forgotten the link.

You haven't said what current is flowing. Unless it is large the voltage across a 0.5ohm resistor will be very low. 2 amps would only give 1 volt.

You may need to use the ADC's internal 1.1v reference.

0.5 ohms is rather large for measuring current. I have a 0.005 ohm resitor connected to my solar panels. I have not yet tried to connect it to an Arduino.

By the way what Arduino are you using. Almost anything other than an Uno has the ability to measure differential voltage and contains an internal amplifier which should be ideal for measuring the low voltage across a shunt resistor.

...R

Are you certain that you are using 5.000V as the reference voltage?

nope, All I am certain of is powering the arduino over ftdi at what is claimed to be 5v, hen i powered it by what is claimed to be 3.3v the results were different

That's no guarantee.

ok, how can I guarentee it?

Where'd the 3.15 come from?

The resistor bridge roughly divides 0-15v into 0-5v, so the 5v maximum read on the pin needs to be roughly multiplied by three to get the source voltage correct? It appears to work at least.

I have measured the resistor as 0.5ohms on my less than good multimeter, it will only give me one decimal place.

Even at one decimal place of accuracy, I'd question whether you could tell the difference between a half ohm resistor and a wire.
[/quote]

What does that mean to say? IE , should I increase or decrease the value of the resistor?

Robin2:
There are techniques to measure very low resistances with an ordinary multimeter - but sorry I have forgotten the link.

You haven't said what current is flowing. Unless it is large the voltage across a 0.5ohm resistor will be very low. 2 amps would only give 1 volt.

You may need to use the ADC's internal 1.1v reference.

0.5 ohms is rather large for measuring current. I have a 0.005 ohm resitor connected to my solar panels. I have not yet tried to connect it to an Arduino.

By the way what Arduino are you using. Almost anything other than an Uno has the ability to measure differential voltage and contains an internal amplifier which should be ideal for measuring the low voltage across a shunt resistor.

...R

I would like to be able to measure up to 10a or so, the idea is to use it to measure a brushless motor's power consumption.
As I understand it, I need to set it up so that at the maximum 10A the volts across the resistor are no more than the pin on the arduino can handle. Is this correct?

I am using a pro mini 328 5v, a cheapo china 1usd version, I am planning to move from breadboard to protoboard at some point and make a semi permanent solution, I will more than likely use a 328p DIN on the proto as I have one lying around, it will be a pro mini config though.

how do I set the internal 1.1v reference and will it affect readings over 1.1v?

ok, how can I guarentee it?

You can't. You have to actually measure the value.

ok, once I have the value, what do I do with it?

the voltmeter reads 4.95, surely thats close enough,

so back to the other question, how do i set the reference to internal 1.1v? and will it affect the ability to read higher amperages?

Doing so has caused the volt reading to be about 3v high , and the amps reads 0.03 when the supply reads 0.04, a good sign ,

but then seems to read about double the amps as it increases.

spruce_m00se:
how do I set the internal 1.1v reference and will it affect readings over 1.1v?

See analogReference(). You can switch between references programmatically, but you need to allow time for the ADC to settle. Read the Atmel datasheet.

You can also get external voltage reference chips that would give a stabilized higher reference voltage.

If you can get a non-328 DIP Atmega I would consider using it if it has the capability to do differential voltages.

10amps through a 0.5ohm resistor will "waste" 5v so it will not give you a true measure of the current drawn by your motor unless you increase the supply voltage to compensate - but then, what exactly would you be measuring?.

With a 0.005 ohm resistor the voltage drop would only be 50mV which would have little impact on the motor. But that low voltage would need to be amplified before an Atmega328 could measure it. (Hope all my maths is correct).

...R

5v waste is a lot,

I wonder if i can find a 0.005ohm resistor around here anywhere? here being my man cave.
If not I will take a look on ebay,

none the less, I will know the voltage going to the motor, so can still get some useful data, but I wouldnt be able to measure the motor on full voltage unless I increase the input,

plus i guess the voltage wasted is proportional to the amperage used , so would change as the motor revs up,

Can this not be compensated in code somehow? maybe a hall sensor would be a better way of measuring current in this application

Perhaps this would better done as a search by the OP But an Allegro ACS712 series hall effect current sensor might be a 'somewhat' better choice than attempting to use a sensing resistor... It requires nearly the same additional Op-Amp as would OP's attempt. is missing... But far more accurate... A TIL431 and a resistor and a pot for calibration make an excellent Vref source, Even considering the stated accuracy of the SAR ADC used in the 328P series of uControllers (+/- 2 counts, Typ).
The output of an ACS712 is Vcc/2 and changes as the current flow shifts from zero. Discharge is typically Vcc/2 + Vout and charge is Vcc/2 - charge depending on the polarity of the sense inputs which go in series with the load... This device can be used to sense either the positive or negative power supply lead. An LMC662 (dual rail to rail op-amp) can be the gain block to rationalize the output shift and the second op-amp can be used as a level shifter to convert a bi-polar output to a zero referenced output voltage.. Easily...
I leave the details to OP's skill with Google.. As I Know there are reference examples for both freely available from Google..
BTW Did the OP make even a small effort to search the Arduino site first..
This is not the first time this or similar requests have been asked here... The Answers are typically found in the General Electronics section and the answers are relatively simple... Once you "Search For Them"... I am happy to answer specific questions on methods and circuitry... Only if the OP has done his part in researching the question... The OP would learn little If I did the relatively simple engineering required... I'm not participating in this forum for anything else but what I don't already know...
If I can be of help with advice.. Great... But I don't consult for free and I will not do design work for anyone but myself.
This is a trivial issue and the answers can all be found in the "Op-Amp Cookbook".. It just takes some initiative from the OP to do the basic work... I'll be happy to fix bad circuitry But...

Docedison

BTW Did the OP make even a small effort to search the Arduino site first..

Thats the only way I know about how to use a sensing resistor. I had read about hall sensors also , but they are quite a bit more complicated to use by the look of it.

GOING BACK UP ONE POST:

if the voltage drops due to the wasted on the sensing resistor and the amperage increases, then why do I not notice the voltage drop in my serial print as the amperage increases?

I have measured 1A , which in theory would produce a 0.5v drop. However the voltage appears to stay solid.

spruce_m00se:
I have measured 1A , which in theory would produce a 0.5v drop. However the voltage appears to stay solid.

You need to show us a diagram of how things are connected and where you are measuring the voltages.

...R

I leave the details to OP's skill with Google..

Thanks, I am looking now,

http://embedded-lab.com/blog/?p=4529

this seems to do the job without an opamp. just with the hall effect sensor. Does that seem reasonable?

Robin2:

spruce_m00se:
I have measured 1A , which in theory would produce a 0.5v drop. However the voltage appears to stay solid.

You need to show us a diagram of how things are connected and where you are measuring the voltages.

...R

I have actually just taken the setup apart and started to transfer it onto a protoboard with an LCD display and SD card reader.
I have also now had to tackle the problem of powering the arduino as I in theory want it to run without being connected to the ftdi.
I have an adjustable regulator set to 5v that should be taking care of that.
I will also add a potentiometer and another 5V regulator in order to be able to use it as a servo tester at the same time.

I will post a diagram on sunday if I have some time to draw it up.

In the meantime I would be happy to progress towards a workable solution for the current sensing,

just picked up two of these on ebay

http://www.ebay.co.uk/itm/400607947036?_trksid=p2059210.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

one for the magic smoke testing and one for doing it properly, the only problem is that it takes about two weeks to get things as im currently living in dubai, grrr,r

Anyway, that gives me time to play with the sensing resistor and learn from that, and make my menu system and servo tester etc for the other parts of the project, plus I guess that the 5v regulators etc will all contribute their own little problems .

thanks for th e help. If anyone has any other input im all ears.

Yes it should I didn't really read the whole article but my suggestion Re: the op-amp as to leave the math to the op-amp and it's feedback (gain set) so as to produce a voltage that is equal to the amperage and to offset the bi-polar output to a single ended solution.
Thus it becomes a reusable solution that requires less code to convert for example the

ACS712ELCTR-05B-T

Which has a sensitivity of 185 mV/A to a number that is easier to use.
Since the part # mentioned is a 5A sensor (ideal I think) converting the output voltage from 185 mV to 0 to 5 A can certainly be done in code there is still the Output + mV/A still has a possible plus or minus output value and requires the use of floats extensively meaning larger code because first you must scale the output to the actual current first and then display that number... Which can be done with int's much easier when the ACS712 output is representative of the actual current...
Your requirements and what I read of your skills indicates to me that a small read about op-amp's would give you more options.
It will also make a re-usable device much easier to implement should you need one for another use or another project.
One op-amp 3 or 4 resistors and 2 pots makes an easy circuit to use..
I've taken the liberty of attaching data sheets on the three devices mentioned... The ASC712 device is relatively cheap from fleabay , in the 3 to \$5 dollar range and has a minimal loss due to it's sensing resistance.. The TIL431 is also in the same class (Vref and adjustable too).
The LMC662 is very easy to use and is relatively stable... The Dip part is under a dollar (or should be) so "Give it a play"...
There are example circuits on all the data sheets too.
If you get lost, I'll be watching this thread.. so after Mr Google post a question and I'll try to answer it as best as I can...
The 20A ASC712 device has a 100 mV/A output but it sort of is out of range for small (1 to 5A) due to the
ADC limitations and while it would work I feel that it is not the best choice.. I do hope this helps.. you and anyone else needing a solution such as yours..

Doc

ACS712-Datasheet.pdf (643 KB)

LMC662.pdf (481 KB)

TIL431C.pdf (1.78 MB)

spruce_m00se:
I will post a diagram on sunday if I have some time to draw it up.

A photo of a pencil sketch will be fine.

...R

today I am going to test the protoboard version ,

i will then make a sketch once I have realised what mistakes I have made etc