Go Down

### Topic: Arduino multimeter (Read 18107 times)previous topic - next topic

#### bisctboy

##### Feb 13, 2010, 04:13 am
Had some help earlier that got me over the top to success with my arduino voltmeter. Now I need some help to add the ability to read the current flow. I have read several posts about basically doing the same thing to read current...voltage divider.

I am using (2) 10k resistors for voltmeter, can I use the same setup for this?

What would the code look like?

Is there a maximum ma value that I can read?

The posts I read about this were good to get me started in the right direction (I think?) but didn't do a whole lot to help me with code. I have attached the code below that I am using from the Playground for my voltmeter as reference.

Thanks,

Code: [Select]
`int inputVoltagePin = 0;               void setup(){  Serial.begin(9600);}void loop(){  // read voltage value  int voltage=analogRead(inputVoltagePin);  int valueVolts=voltage/102;  int valueHundrethsOfMilliVolts=((voltage % 102)*10)/102;  // send formated value to serial com port  Serial.print(valueVolts);  Serial.print('.');  Serial.print(valueHundrethsOfMilliVolts);  Serial.println('V');  // pause between readings  delay(1000);                  }`

#### digimike

#1
##### Feb 13, 2010, 05:15 am

Since you have the arduino acting as a decent voltage meter you can easily measure current. What you'll need is a shunt resistor. Whatever voltage source your reading will need to pass threw the shunt. You will then measure the voltage drop across the shunt. It will measure in mV. Move the decimal point over to the right one place and you have the amperage. Its been a couple years since i played with this so someone can correct me if i'm wrong. If i am its about translating the voltage read into amps.

.4V = 4A

#### KenH

#2
##### Feb 13, 2010, 05:36 am
How accurate do you wish to read the amps?  What range amps?  Do you wish to read zero to 1 amp?  or zero to 100 amps?  This is DC amps I expect?

There are a couple or 3 ways to do this - the slickest way is to use a ACS758 Current Sensor - that is a very slick chip.  I'm using one in a power supply monitor that reads voltage (0-15vdc), amps (.1 to 30 amps), temperature and sends a shutdown in alarm condition.

That chip is around \$5 USD or so, but has a built in shunt. Another option is a ZXCT1021 Current sensor that's only \$2.28USD from Digikey and requires an external shunt.  I plan to use one, and will range to 20 amps or so with it.  I plan to use 11.95" of #16 wire for a .004 ohm shunt to allow reading with the Vref pin at 1.2 vdc.

Those chips put out a mV signal per amp.... good info in the datasheet.

I was wondering what happened to the other thread - I lost it.  Glad you got the voltmeter running.  Since you mentioned using two 10K resistors I'd expect the voltage range is 0 to 10vdc?

Ken H.

#### bisctboy

#3
##### Feb 13, 2010, 06:28 am
digimike,

Quote
What you'll need is a shunt resistor. Whatever voltage source your reading will need to pass threw the shunt.

What is a shunt resistor and how do I make one? I am looking at reading 1 amp at the most (probably more like 500ma). After I make it, where do I put it in my circuit? Also, what would the code look like to solve for the math?

Thanks for your help.

#### billhowl

#4
##### Feb 13, 2010, 06:29 am
programing ADC to measure resistance
To measure a resistance you need to use Ohm's Law (E = I*R or R = E/I). So, apply a constant current (I) through the resistor and use the ADC to measure the voltage across the resistor then calculate the resistance.
Google will find tons of information on this.

#### bisctboy

#5
##### Feb 13, 2010, 06:37 am
KenH,

Quote
How accurate do you wish to read the amps?

As accurate as possible...within 25-50ma or better

Quote
What range amps? Do you wish to read zero to 1 amp?

yes...no more than 1 amp

Quote
This is DC amps I expect?

Yes...solar cels rated at 2.5V/600ma

If you could, please include some code that I can work with. I am a newbie to this. As a last resort I could order a chip from digikey like you talked about. I would just like to try to" build" it first.

Thanks for your help.

#### KenH

#6
##### Feb 13, 2010, 07:24 pm
ZXCT1021 Current sensor has a datasheet here http://www.diodes.com/datasheets/ZXCT1021.pdf

Take a look at page 6 - there is info on how to design a resistance into the PCB to work.. OR you can just order a .1 ohm resistor.... make it a 1% or even a 5% - you can measure the actual resistance and use that in calculations.

Read the datasheet - it has a LOT of info on what you need.  I MUST run now - can provide some code later.

Have fun,

Ken H.

#### bisctboy

#7
##### Feb 14, 2010, 02:20 am
Hmmmm...it sounds like I can't do this without ordering an IC or some special resistor. Bummer, I'm the kinda guy who likes to make things with the "banana's I have on the cart". Ok, so I have to get a couple .1 ohm resistors or the IC...No way to do this with a couple resistors I could get at Radio Shack?

What is a shunt resistor? This has come up a few times in my research...

By the way, thanks for the link to the datasheet. I poured over those when I built a solar power li-ion charger. There is a ton of info on those things! I built my own PCB and even soldered a few tiny sot23 IC's onto it. Talk about a sense of accomplishment when it actually charged the battery! This whole amp meter thing I'm trying to accomplish here is an add-on to that project. Hopefully some day I will be able to track the progress of the charger from my office on the web via my arduino. The li-ion charger is done, the heliostat is done, and the voltmeter is done. I just need to figure out this amp meter thing, add a couple of xbee's, and figure out ftp...

Thanks for your input, I appreciate it!

#### KenH

#8
##### Feb 14, 2010, 03:16 amLast Edit: Feb 14, 2010, 03:21 am by KenH Reason: 1
A shunt resistor is a low ohm resistor that allows you to measure the voltage drop across it.  Check Wikipedia for shunt resistor - I'll bet it has something good.

If you wish to use what you've got on hand, you can use 10 ft of #20AWG wire for the shunt resistor - that is .1015 ohms. You "could" in theory at least, bring the voltage from each side of the resistor (you'll understand more after reading Wikipedia) to a pin on the Arduino - subtract the difference to get the voltage drop and calculate the amps with the formula

I = V/R

simple, but works pretty good.

Here is some code to get you started:
Code: [Select]
`//Amp Reading section  for (int i = 0; i < 20; i++) // read the value on analog input for the number of spanamp, then devide by 20 to average.  ampV = ((ampraw * 5.0) / 1024.0);   //this calculates the actual input voltage on the pin.  You might wish to use a Vref of 1.2 volts to as internal to get better resolution.    amp = ampV/.1015 //this assumes you are using a 0.1015 ohm resistor.    lcd.setCursor(8,0);  lcd.print("A=");  lcd.print(amp, 3); with the new 0018 this allows 3 decimal places.`

Be sure to declare required items, but this should get you on the track.

If you do use 1.2 internal ADC reference, someone will have to help us.  You have already used the default of 5.0 vdc as Vref.  I am told you can use default of 5.0vdc for one section, then in the next section set ADC to use the internal Vref of 1.2vdc.  I've tried that but didn't get it to work.

Maybe someone will help us on that.

Ken H>

#### bisctboy

#9
##### Feb 14, 2010, 04:50 am
Thanks pal. You've fertilized my interest in this even more. Would the circuit for the shunt look like Vin-->resistor-->ground and then I would have to measure the 2 values at the "-->" via 2 different analog pins? I'm assuming the small resistor is providing the load? (silly question, I know)

I've got a couple questions about the code and the ADC comment but I need to wrap my brain around the above first.

Thanks,

#### KenH

#10
##### Feb 14, 2010, 04:58 am
No, the circuit would be V source - resistor - load with a pin connected between source & resistor and the second pin between resistor and load.

the resistor will create a small voltage drop - from zero to 100 mV with current from zero to 1 amp load.  "IF" you can stand the voltage drop (not likely in a solar setup) a 1 ohm resistor would give a 1 volt drop at 1 amp.  Would be good for testing.

The current sensor IC I mentioned before will provide a zero to 1vdc signal to the arduino pin with a .1 ohm resistor at 1 amp.

BUT a 1 ohm resistor would be good for breadboarding a test setup.

Ken H>

#### belphit

#11
##### Feb 14, 2010, 01:06 pm
For Solar cells charging a battery I have used the LEM sensors, such as the LTS-6NP these are good for up to 6A DC or AC and are vey accurate. They output 0.625V to 2.5 volts for full scale also they can be configured so that you do not need to interrupt your measued circuit as they use a current transformer, no shunt required. The other nice thing is that they can go positive and negative for the current flow so you can measure charge and discharge current with the same sensor.
You can download a datasheet at www.lem.com

Cheers

Peter B

#### KenH

#12
##### Feb 14, 2010, 03:51 pmLast Edit: Feb 14, 2010, 03:52 pm by KenH Reason: 1
Those LEM current sensors are really nice.  I especially like the current transformer aspect as the insertion loss is less - really ..  I just noticed the price.  \$17USD?  Ouch!!

I used solar on my sailboat since 1987, but never needed a regulator as we always used all the power available.  On those days when excess power was available the kids watched a movie 'n popcorn.

Ken

#### cr0sh

#13
##### Feb 24, 2010, 10:50 pm
I wanted to add something about shunt resistors (I've been researching them myself with the intention to use one to measure current usage from a homemade power supply I am thinking about building):

They are special resistors, with a low ohm range, but more importantly, they are made out of a special alloy that doesn't change resistance over a wide temperature range; for this reason, for a long time (until something having to due with quantum hall effect or something came along recently) they were used for "standard ohm" by NIST and other standards organizations.

This is important, since they are a resistor, and heat up (a little), and you don't want that to change things as you are reading them. I also remember that some had specs or whatnot on how long you could use them in a circuit before they would be damaged (almost like a duty cycle)...

I am not sure how you could "leave" one in a circuit, though, for continuous readings; how do multimeters do it? How does that IC (mentioned above) do it?

Also, is the only way to measure AC current with a coil? Or can you use a shunt for that? I am still trying to figure some of this out...

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

#### phaethom

#14
##### Feb 24, 2010, 11:05 pm
hello kenh.
ken you provide the schematic for this?

Go Up