Pages: [1]   Go Down
Author Topic: Is it possible to use Arduino as Ampmeter for 100mA only ?  (Read 614 times)
0 Members and 1 Guest are viewing this topic.
France
Offline Offline
Jr. Member
**
Karma: 1
Posts: 85
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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 control
Serial.print(" mesureUshunt ");
Serial.print(mesureUshunt);
Serial.print(" Ushunt ");
Serial.print(mesureUshunt1);
Serial.print("  Icons ");
Serial.println(Icons);

//print current drain (Icons) in mA on LCD
lcd.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.

Any advice welcome.
I'm a beginner.
Logged

Germany
Offline Offline
Faraday Member
**
Karma: 59
Posts: 3071
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ... 
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27357
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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;
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

France
Offline Offline
Jr. Member
**
Karma: 1
Posts: 85
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ! smiley-red

To CrossRoads :

I'm trying this.
Thanks a lot.
Logged

France
Offline Offline
Jr. Member
**
Karma: 1
Posts: 85
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Germany
Offline Offline
Faraday Member
**
Karma: 59
Posts: 3071
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


* opamp_GND.PNG (41.68 KB, 1182x589 - viewed 12 times.)
Logged

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@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.
Logged

Pages: [1]   Go Up
Jump to: