Go Down

### Topic: Is it possible to use Arduino as Ampmeter for 100mA only ? (Read 1 time)previous topic - next topic

#### hary

##### Apr 20, 2012, 09:24 pm
Hi.

I was wondering whether it is possible to use Arduino as Ampmeter for  about 100mA only .

I've seen some example with a shunt resistor so I wanted to play with mine and print on my LCD the current drain of the system (Arduino, lcd, and other stuff around.

I know it takes about 120-150mA but I can't get my project of printing it on the lcd (neither on the serial monitor). It always says 00.00mA !
I'm using a 0.48 Ohm resistor in series in the power line (two 1/4W ,  1 Ohm resistor in parallel).

Code: [Select]
` mesureUshunt = analogRead(A2);                         //prend l'intensité par résistance SHUNT 0.48 Ohm  mesureUshunt1 = map(mesureUshunt, 0, 1023, 0, 1000);     Icons = mesureUshunt1 / 475.953;                      //résistance de 0.47953565 Ohm//print different data on serial monitor for controlSerial.print(" mesureUshunt ");Serial.print(mesureUshunt); Serial.print(" Ushunt ");Serial.print(mesureUshunt1); Serial.print("  Icons ");Serial.println(Icons);//print current drain (Icons) in mA on LCDlcd.setCursor(8,2);lcd.print(Icons);lcd.setCursor(13,2);lcd.print("mA");`

Is my resistor to small , so it is the voltage I'm trying to measure with the analogpin ?

I'd like to be able to measure from 0 to 500mA.

I'm a beginner.

#### michael_x

#1
##### Apr 20, 2012, 10:38 pm
Quote
in series in the power line

where is that ?
I understand you want to measure Arduino's current itself.
Probably GND is above the voltage difference produced by your shunt ... you cannot measure negative voltages.
Or your shunt is outside the voltage regulator ...
Not sure if you can use an opamp to tie that "external" voltage difference show up as some value above GND.
I'd look into that direction, but perhaps there's a completely different approach ...

#2
##### Apr 20, 2012, 10:48 pm
0.1A x 0.48ohm = 0.048V.

Take a reading, A2, from one side, (say the higher voltage side)
and a 2nd reading, A3, from the other side (the lower votage side).
The difference between the 2 should be about 10. (0.048/ (5/1023))
Convert that 10 to a voltage reading:
float volts = (A2 - A3) *5/1023;
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### hary

#3
##### Apr 20, 2012, 11:05 pm
To michael_x :
Well, many thanks, I made a big mistake !
I put the shunt in between Arduino GND and power source (-)  after regulator.

And yes , I didn't notice but I find negative voltage on resistor ends !!!

I have to reconsider my schematics !

I'm trying this.
Thanks a lot.

#### hary

#4
##### Apr 21, 2012, 12:22 am
So I've changed the resistor and put it in between the + of the power supply and the 5V of the Arduino.

Voltage power supply = 4.98V (before the shunt)
5V of the Arduino = 4.95V (after the shunt)

Both A2 and A3 give me an analogRead = 1023 !!!!

I think there is a 5V reference problem.
The Arduino must think that the 4.95V supplied is 5V  => full scale of the ADC, so it gives 1023 for the after shunt voltage (4.95V) instead of 1013 !

And for the before shunt voltage (4.98V), of course, it can't give more than 1023 !

It must have something to do with AREF.
I guess, I should give AREF a proper external 5V reference, but where to get it from.

In fact, as I want to use a difference voltage, A2-A3, I need 4.98V<=AREF<=5V.

But If I would need to read a proper voltage, I must give the Arduino a proper and stable voltage reference, otherwise, the reading could fluctuate as the reference is not stable.
Am I right ?

Now,  have to figure out how to use the analogReference function.

#### michael_x

#5
##### Apr 23, 2012, 05:39 am
I thought a bit about my opamp idea, and at least according to my simulation in ltspice, it seems possible to have your shunt between Arduino GND and the neg. wire of your 5V power supply, run the opamp directly on these 5V, amplify the shunt voltage such that it is well above Arduino GND and can be measured.
In the attached ltspice schema, V2 controls Rl to simulate an Arduino current varying 100 ... 125 mA,
resulting (with an opamp gain of about 20 due to the ratio R2 / R1=R3 ) in a V(out) = 1.0  ... 1.25 V

Should be doable with any simple opamp...

But your idea of having a separate Vref for Analog Input and effectively measuring the difference between Vref and 5V sounds interesting as well.

#### Techone

#6
##### Apr 23, 2012, 06:21 am
@hary

CrossRoads idea is correct. You need to measure two voltage and calculate to get a current reading.  Since you measured is close to 5 V, well,  use a voltage divider for both reading points, and select the resistor for volatage divider : 47 K - four 4.7 K. The voltage should be around 2.5 V.

Quote
0.1A x 0.48ohm = 0.048V.

At 100 mA and lower, you get 0.048 V.  A single value read from analog pin unit is 1 = 0.004887585 has long the Vref is 5.00 V

Let take 0.048 / 0.0048 = 9.8208 <-- 9 analog value difference @ 100 mA.... Not much... in my opinion.

So you need to "amplify" this up. Lean about op-amps - Difference Amplifier : http://www.eng.yale.edu/ee-labs/morse/compo/sloa058.pdf and http://webpages.ursinus.edu/lriley/ref/circuits/node5.html#SECTION00055000000000000000

check it out.

Go Up

Please enter a valid email to subscribe