Arduino multimeter

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,

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);                  
}

Should have added this to your other thread.

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

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.

digimike,

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.

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.

KenH,

How accurate do you wish to read the amps?

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

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

yes...no more than 1 amp

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.

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.

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!

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:

//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>

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,

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>

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

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

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

:slight_smile:

hello kenh.
ken you provide the schematic for this?

I'm using the big brother of this http://www.pololu.com/catalog/product/1185 in a project of mine where I'm measuring current consumed by a motor. Very impressed with it once I'd sorted the filtering out. Very simple to integrate into your circuit.

thanks

That is a nice sensor for low current - here is chip for half price from DigiKey:

What circuit are you referring to for a schematic? I can draw one up if you wish - pdf format? I can email it to you.

There's really not much to the voltage divider or current sensing. - I never drew up a schematic but drew up a PCB direct.

Ken H>

Hi,

You guys with experience in electronic and sensors and the like, you may be able to tell me if the following is doable...

I am operating few ceiling mounted video projectors. When I turn off the projector, the fan keeps running for a few minutes (2-3), to cool the lamp, before the projector goes to stand by. At that stage I should turn off the main power (if I leave them on standby I damage something in the power supply, been there, done that).

So I would have a sensor detects when the projector goes from working mode (with lamp on) to fan mode (with lamp off). At that stage, I'd start a timer for 5 minutes and cut of the main power at the end of the time (unless the lamp has been restarted).

I would include a push button to initialize the system and allow to turn on the projector within 5 minutes.

Advantage is that any time someone would stop the projector, the main power will be turn off automatically after the fan has finished operating: no forget to turn off the main power, no damage to the power supply.

The programming part, no problem, I know how to do it. I am more questioning about the feasability of the hardware part.

Clues and help are most welcome.

Bests,

Olivier

A couple of possile methods - monitor the current. The current = lamp + fan allows power ON with no time limit. Current = fan only starts the 5 minute timer before shutting power off complete. "IF" during "current = fan" phase it becomes "current = fan + lamp" then go back to power ON all the time.

Other method would be to put a light sensor to detect lamp is OFF to start timer.

Is that what you're looking for?

Ken H