Go Down

### Topic: [Solved]Read voltage across a resistor and use it as an input to an anlog pin. (Read 2292 times)previous topic - next topic

##### Feb 18, 2011, 08:25 pmLast Edit: Feb 20, 2011, 03:27 am by Sonia Reason: 1
I have a resistor connected to a circuit and i would like one of the analog pins to store the output voltage across the resistor (not a variable resistor, the regular kind). How can I achieve this? In the existing examples (such as the potentiometer one), the resistor had two pins connected to the power and ground pins in the Arduino board. I am unsure how to apply this in this case scenario. Any help would be appreciated. The voltage provided to the circuit is 5V.

Thanks
Natasha

#1
##### Feb 18, 2011, 09:09 pm
What is the rest of the circuit hooked up to?
Would be easiest if one side of the resistor was at ground - then could hook that up to arduino ground, and the other side to Analog input pin, as long was it was 5V or less, and do
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.

#### swetrack

#2
##### Feb 18, 2011, 10:11 pm

With a battery arduino gnd could have almost any potential. So do not stare blind at Arduino gnd as a fixed potential. However i would not recommend to "float" Arduino it is easy to make some mistake and if the I through R is AC avoid it.

Assuming it is DC and since circuit powers from 5V  i would find the circuit gnd and use two Ain and calculate the difference.

thank you

#### retrolefty

#3
##### Feb 18, 2011, 10:56 pm
Arduino analog input pins are single-ended ground based input pins. So unless the resistor you want to measure across has one end wired to it's circuit ground common and you wire a connection between that circuits ground and the arduino ground, you can not get the true voltage drop reading across the resistor.

External components like true differential op-amps can be used to perform such transformation magic suitable to be read by an arduino analog input pin.

Lefty

#### jackrae

#4
##### Feb 18, 2011, 11:10 pm
The following is based ONLY upon a situation where the resistors is not connected to the ground point of the circuit generating the current and providess a simple and cheap solution.

It is irrelevant what potential the resistor ends are with respect to circuit ground.  The point at which the current enters the resistor must be connected to the arduino ground and the end at which the current flows out goes to the arduino sense input.

This being the case the circuit ground reference must be and remain insulated from the arduino ground reference.

Note :  If the potential of either end of the resistor is relatively high with respect to true ground then you are working on a potentially hazardous system and you should not consider direct connection to the arduino.  If this is the case then you require a galvanic isolation module.

jack

#### swetrack

#5
##### Feb 18, 2011, 11:51 pm

It is irrelevant what potential the resistor ends are with respect to circuit ground.  The point at which the current enters the resistor must be connected to the arduino ground and the end at which the current flows out goes to the arduino sense input.

Note :  If the potential of either end of the resistor is relatively high with respect to true ground then you are working on a potentially hazardous system and you should not consider direct connection to the arduino.  If this is the case then you require a galvanic isolation module.

jack

Wow! wich way does the current flow? how should TS know? Do you know?
I learned that electrons flows from neg to positive charge, BUT the current flows from positive to negative. Anyway, we dont know how it flows in this cicuit. Sorry, but i dont think that is a good advice.

Also how could 5V be hazardous?

#### retrolefty

#6

Lefty

#7
##### Feb 19, 2011, 12:49 am
Hello all

Thank you for all the replies. I am sorry that I forgot to mention but the other end of the resistor is connected to the circuit ground (not the arduino ground). So from what I read above, I can have one end of the resistor connected to the circuit ground and the other end of the resistor connected to the an analog input pin. Then the input voltage that the analog pin is seeing is the voltage across the resistor. Is this correct?

Thanks
Natasha

#### jackrae

#8
##### Feb 19, 2011, 01:05 am
almost   you must also connect the circuit ground to the arduino ground.

in my previous posting i got the instructions about the arduino connection reversed.  sorry about that.

re how can 5 volts be dangerous  ::  you need to read the precondition.   if the resistor is connected to a circuit at 500 volts to ground, with 5 volts across it the other end will be at either 495 or 505 volts, depending upon current direction.  not all low level measurements are referenced to ground !

jack

#9
##### Feb 19, 2011, 06:00 am
Some earlier mentioned that if I am powering the Arduino with a battery (which I am), GND can be a floating value. So I should connect the Arduino ground to my circuit ground via a wire?

Also, if I am trying to read an opamp output via an analog input pin, how would that work (just out of curiosity)?  Does the same logic apply i.e I connect the Vout pin to to the analog pin and the GND to the V- pin in the op amp (the V+ is supplied with 5V DC through an external source).

Sorry for asking all these noob questions, I just don't want to destroy/burn the microcontroller, I have had that happen to me before.

Thanks
Natasha

#10
##### Feb 19, 2011, 06:36 amLast Edit: Feb 19, 2011, 06:43 am by CrossRoads Reason: 1
Sounds like you are getting the hang  of it!

Yes, the arduino ground connects to the ground of what you are measuring. If that is a single supply op amp than that is what you  connect to.
For example, an op amp like this, which runs from +5v and Gnd.

The arduino running on batteries is like a portable multimeter - you are measuring the red lead (Analog in) with respect to the black lead (arduino ground).
Only the arduino can't withstand negative voltage, while the multimeter can - so the black lead must be connected to the circuits ground and only positive measurements can be made.
If you have an op amp with +/- supplies, then you must be careful - perhaps adding a diode before the analog input pin to rectify the incoming voltage, at the loss of voltage drop across the diode.

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.