What is the best way to setup the Arduino to measure current? I've tried using a shunt resistor going from ground to the load, and tried to measure the other side of the resistor, but I don't get any response in my analog readings. Any ideas how to approach this?
The way to do it is with a fairly small resistor between the load and ground. Since it's a series circuit, the current through the load and resistor are the same. You can use the analog input to measure the voltage across the resistor and ohms law to calculate the current.
It sounds like this is what you're doing. For starters, try measuring the voltage across your resistor with your meter and see what you get. If there is current flowing, there has to be a voltage across the resistor, so once you confirm it with your meter, you can look into how you're doing the analog reading.
I would expect it to be easier to use one of those hall-effect current sensors that permits the measurement electronics (arduino/etc) to be electrically isolated from the power being measured. Allegro Microsystems has some nice products in that space; setting one up is on my "to be done, eventually" list...
The series resistor approach is easy if the voltage drop across the shunt is within range of the analogRead. I found this works well for measuring servo current drain accurate to 10ma using a half ohm shunt (two one ohm resistors in parallel).
Current in ma can be read without floating point as follows:
unsigned int ma = (analogRead(shuntPin) * 256L)/ 26L ; // 1/2 ohm: 1024 = 5v so I in ma equals value * 9.8
note the intermediate calculation uses long math because for large currents 256 * analogRead can overflow an integer, but the result when divided by 26 is within an unsigned int up to about 2.5 amps. At higher currents the voltage drop through the shunt is high and westfw's approach is preferred.
I would expect it to be easier to use one of those hall-effect current sensors that permits the measurement electronics (arduino/etc) to be electrically isolated from the power being measured.
Problem is that you only get a signal of about 50mV per amp of current so it's great for a high power circuit but not for low current stuff.
I would expect it to be easier to use one of those hall-effect current sensors that permits the measurement electronics (arduino/etc) to be electrically isolated from the power being measured.
Problem is that you only get a signal of about 50mV per amp of current so it's great for a high power circuit but not for low current stuff.
I may be wrong but that sounds about the same as the resulution I am getting with my 1/2 ohm resistor as per the post above yours. It is certainly good enough for measuring the current drain of somethin like a servo.
No it's 10 times smaller than your system. E = IR so 1 amp * 0.5R gives 500mV per amp.
So that makes the hall device more than good enough for that kind of measurement