Go Down

Topic: Measuring Current/Voltage with arduino ? (Read 36 times) previous topic - next topic

tvdbon

Hi Guys,

Would it be possible to be measure voltage and current with my arduino using the analog input pins? I'd like to measure a voltage between 0-9V, and a current between 0 and 30mA. The numbers aren't too extreme so would this be possible without using any other special ic's ?

MikMo

#1
Mar 17, 2008, 11:19 am Last Edit: Mar 17, 2008, 11:20 am by MikMo Reason: 1
The arduino analog input pins can by default meassure 0 - 5V with 10 bit resolution i.e it will give you a number in the 0 - 1023  range.  You can scale the 0 - 9 V  voltage down  to "fit" in the 0 - 5 volt range with a simple OpAmp circuit or a voltage divider maybee.

I don't know about meassuring current with arduino. But it should be possible to actually convert a current to a voltage. Try to Google "current to voltage conversion"

Remember to consider your needed precision. How precise do yuor meassurements have to be?

tvdbon

Well, it doesn't have to be too precise but I would like to get values that make sense. I'll have a look for a current to voltage conversion. Anybody else have any ideas ?

Oracle

Quote
Hi Guys,

Would it be possible to be measure voltage and current with my arduino using the analog input pins? I'd like to measure a voltage between 0-9V, and a current between 0 and 30mA. The numbers aren't too extreme so would this be possible without using any other special ic's ?


The voltage divider suggestion will work to measure voltage.

For current, you would use a resistor as a shunt and measure the voltage across the resistor.

tvdbon

#4
Mar 17, 2008, 02:03 pm Last Edit: Mar 17, 2008, 02:08 pm by tvdbon Reason: 1
OK, so this is what I've got so far:

For my current input, I can basically use a resistor (as mentioned above) in the following setup:



From my calculations (V=IR) I get that at 27.7mA my output would be 5v. So theoretically I can just measure my output with the arduino analog input and then do some calculations to get the mA.

The voltage divider is easy enough :



Which means that I should get 5V out with a 9V input. To calculate Vin I use the following formula:

Vin = Vout/(R2/(R1+R2))

Am I correct with these assumptions or do you guys disagree with something. btw - I know the theory (supposedly ;)), but I'm still learning to apply this practically.

Jaguarjoe

With that 180 ohm resistor you'll be losing 5 volts of your total voltage available to the circuit. Can you afford to lose that much?

Your voltage divider will consume 50ma of current. This is way too much. Bump your resistances up by a factor of 10 and only consume 5ma. Also note that 80 ohms is not a standard value. 82 is though.

mem

I suggest using even higher resistors in the voltage divider. If you use two 4.7k resistors than the voltage range will be 0-10 volts. Dividing the analogRead value by 102 you will give you the result in volts.  (dividing by 102.4 is slightly more accurate but uses floating point which makes your program much bigger)

You want the smallest possible resistor for measuring the current, but as the resistor gets smaller the accuracy drops. If you use a 1 ohm resistor  then each unit of analogRead of the pin connected to the current sensing resistor is around 5ma.  A 5.1 ohms resistor gives  around 1ma for each unit of analogRead.

tvdbon

Quote
You want the smallest possible resistor for measuring the current, but as the resistor gets smaller the accuracy drops. If you use a 1 ohm resistor  then each unit of analogRead of the pin connected to the current sensing resistor is around 5ma.  A 5.1 ohms resistor gives  around 1ma for each unit of analogRead.


OK, so i've got something setup on my breadboard. From the calculations I should be reading 25.5 mA. I used a 4.7 ohms resistor for measuring the voltage from. At the moment the arduino board analog reading is jumping between 23 and 24, which is pretty damn close. How did you calculate that 5.1 ohms will give you around 1ma for each unit read. ie. how can I convert that value to get an even more accurate value. I'm guessing that using precision resistors will give me an even more accurate value ?

thanks for all the help so far everybody, I really appreciate it.

mem

#8
Mar 17, 2008, 08:58 pm Last Edit: Mar 17, 2008, 09:01 pm by mem Reason: 1
An analogRead value of 1024 equals 5 volts, so each unit  equals:  5  divided by 1024,  which is  4.9 millivolts.

By Ohms law, the voltage drop on a resistor equals the amps times resistance in ohms. Therefore 4.9 millivolts will be the voltage drop across a resistor of 4.9 ohms when the current is 1 milliamp .

Standard resistor values are 4.7 ohms or 5.1 ohms but you can get exactly 4.9 ohms using a 5.1 ohm and 120 ohm resistor in parallel.  Using this, the value you get from analogRead will be the current in milliamps.

tvdbon

hmm, I ran into a problem. I've got a circuit with a current regulator and a led. I'm measuring the current by adding the 4.7ohm resistor in series and measuring the voltage over it with my arduino. That part seems to be working fine, but now I also want to measure the voltage over the led using the same arduino. If I take a wire from ground to the one side of the led and and the other side of the led to another analog input to measure it, it seems to short out the led. I hope this made sense ...

Can I measure the voltage over the led with the same setup ?

mem

analogRead measures the voltage potential between a pin and ground. If you want to measure the voltage with reference to a voltage above ground, you could take two measurements, one on each LED lead and subtract the difference.

eustace

Just a reminder - measure your resistor and use it's actual value when calculating current - the difference between marked value and actual can be quite large.

BigMike

Quote
If I take a wire from ground to the one side of the led and and the other side of the led to another analog input to measure it, it seems to short out the led. I hope this made sense ...

Can I measure the voltage over the led with the same setup ?


Yes - you should be able to. Make sure both inputs are configured as inputs.

Mike

tvdbon

Thanks for all the help so far guys, but at the moment I'm a bit confused:

This is the original circuit :



So now I wanted to measure the current so I added the resistor and read the voltage value with the arduino analog input like so :



OK, that works nicely, But, now I also want to measure the voltage over the led : But obviously I can't just add another ground before the led and a an arduino pin after the led. So do I just set GND to starting ground and then read voltages at the different points with multiple analog inputs ? :



does that make sense ? Will my 'current measure resistor' still do its job that way?

Thanks again for all the help

mem

#14
Mar 18, 2008, 09:07 am Last Edit: Mar 18, 2008, 09:08 am by mem Reason: 1
Your ground got switched around between the first and second diagrams.

[font=monospace]

 +v via current regulator
   |
   |----- analog2 in (LED anode)
  _|_
  \ /    <- LED
 __v__
   |
   ------- analog1 in  (LED cathode)
   |
  [ ]  
  [ ] <- current sensing resistor  
  [ ]  
   |
    ------------ Ground
[/font]


analog1 value will be proportional to current

analog2 will be the voltage on the led anode

(analog2 - analog1) value will be the voltage across the diode

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview