[Solved]Read voltage across a resistor and use it as an input to an anlog pin.

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

circuit1.jpg

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
input_value = analogRead(input_pin);
http://arduino.cc/en/Reference/AnalogRead

I agreee fully with CrossRoads.

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

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

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

jackrae:
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?

Now if you can make the following assumptions about your 'test circuit', one, it's powered by regulated +5vdc and two, it's ground is wired to your arduino's ground you can wire one side of your 'test' resistor to an arduino analog input pin and wire the other side of the resistor to another arduino analog input pin. You can then calculate the voltage drop across the resistor by subtracting the lower analog input reading from the higher analog reading and then you will know what the voltage drop across your 'test' resistor is. Again that only works with the prerequisite assumptions made in my first sentence.

Lefty

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

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

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

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.

Thanks a bunch!