Trying to measure current draw of attached device!

So here's my issue. I've got the arduino Duemilanove outputting through digital I/O pin 4 through a 1k resistor to the the base of a transistor (emitter hooked to Arduino GND) to switch a motor on and off. The motor runs off 9 volts which is hooked + through the collector of the transistor, the motor is between the emitter and the 9volt -.

Because the motor has it's own set of logic, it doesn't always turn on, even when digital I/O pin 4 is high. I want to be able to measure whether or not it is drawing current through the analog pin 0 on the Arduino. Then I can tell whether 1) if the digital i/o is high and the motor is not on, thus not drawing power and 2) if it is on and drawing power, how much is it drawing?

My problem is that I set up a resistor between the motor lead and the transistor emitter, and attempt to measure the voltage drop across it (to convert current to voltage) and the transistor goes up in magic smoke. The GND of the digital I/O and the GND of the analog I/O seem to be the same.

How do I simply measure the current draw on this motor? When i use a multimeter it works fine. When I use the arduino as a voltmeter separately from the logic (just touching the leads on a 9-volt) it works fine.

Thanks! :)

and the transistor goes up in magic smoke

Yes it will do, that is what that circuit is designed to do. Current in the base causes current to flow from the 9V supply to ground (connected to your emitter) with nothing limiting the current, therefore a dead short and a molten device.

Do you have to have an 18V supply to your motor? If so why are you switching it at the half way point. Basically that circuit is screwed.

Never have loads in the emitter, that is not the way to use transistors in this context.

I drew that poorly, that's 9 volts +/-. So it's only a 9 volt power supply. Agreed, that circuit is screwed with the analog inputs. How do I fix it?

By the way, it works perfectly if I don't try to do the voltmeter reading on it. So remove the two analog connections. Then the grounds are not common, so no dead short. Also, the motor is tiny and takes a few milliamps, so current is not an issue.

it works perfectly if I don't try to do the voltmeter reading on it

No it doesn't the motor is still in the emitter and so will not get more than 5V across it.

Look at this:- http://www.thebox.myzen.co.uk/Workshop/Motors_1.html

Then put a small series resistor between emitter and ground and then take the analogue input from the emitter. The analogue and digital grounds are the same point on the arduino.

http://home.cogeco.ca/~rpaisley4/xCurrentMonitor.html

I personally use the ZXCT device.

You do not have a standard Digital Volt Meter, I assume?

I have a multimeter. I'm trying to get the arduino to monitor itself. So it sounds like my motor will work better if I put it on the collector rather than the emitter.

I looked at the ZXCT device, but it seems like there should be a way to do this without it. I guess the other possibility is to use an opto-isolator as described in Grumpy_Mike's post and then connect the GND and analog IN across a resistor in series with the motor.

Grumpy_Mike, I'll try the series resistor between emitter and ground and then put the analog input on the emitter. For some reason I think commoning the ground between the 9 volt power source and the arduino may still cause a problem. Thanks for the advice! I'll post how it works.

I would use a rigid common ground, control the motor from the high side (9V), using a npn / pnp transistor combination (or a p channel fet).

Between ground and motor add an appropriate shunt resistor; measure the voltage over the shunt into an analog input. I usually apply a RC filter in the ADC input to kill spikes and protect the input.

Current is measured against ground, so no complex conversions needed.

Success!

And add a freewheeling diode! A motor is an inductive load.

I think commoning the ground between the 9 volt power source and the arduino may still cause a problem.

No common ground will cause it to work, for an explanation see:-
http://www.thebox.myzen.co.uk/Tutorial/Power_Supplies.html

An opto isolator will not work for you for this application.

And add a freewheeling diode!

There was one in the circuit I pointed him at.

Hello, i can only comment from prevoius experience, the way i did it was to use a 1ohm 1 watt resistor in line with a load in my case a laser then when testing with a multimeter either side of the 1 ohm resistor millivolts = milliamps. i haven't tried this with arduino but i would imagine arduino gnd going to motor gnd and two of the arduino analog inputs either side of the resistor then compare the difference in the result giving you a voltage = amps

@Grumpy_Mike, yes, I got the whole common ground thing on the control transistor. I was just going to get that switch data over using an opto-isolator so the transistor is only powering an LED in the isolator. That way I can measure the voltage on the motor leads to my heart's content. I'm going to give all of the suggestions I can a try in a couple hours.

Thanks everyone for all the help!

Hmm, okay. So I did what I thought Grumpy_Mike was suggesting. The good news: No smoke or fire. The bad news is that the arduino analog input isn't registering any voltage. It's showing 0's. I checked across the 10k resistor with a voltmeter and also saw just 0's even when the motor was spinning and obviously drawing current. Since I don't get why this circuit would work, my guess is that I misunderstood it. I've attached an image of how I wired it. Help?

I also tried adding a 1k resistor between the motor and the collector and measuring voltage across that, unfortunately, that's too much impedance and the motor doesn't turn.

Thanks! :)

You still have the transistors emitter connected to ground. This shorts out any voltage developed across the current sensing resistor. Also you have the -ve end of your 9V battery connected to the emitter. This prevents any current flowing down the current sensing resistor.

So:- 1) Change the battery connector to the other side of the R. Make R a low value as you say at 1K there won't be enough current down it to turn the motor. 2) Do not connect the arduino ground to the emitter but to the same side of R as the -ve from your battery.

Okay, got it now. I'm using 2 x 10ohm resistors in parallel to make 5 ohms of resistance. It makes the motor turn quite a bit slower than a direct connect. The problem I'm having now, is that the voltmeter registers even when the motor doesn't draw enough current to turn, and the voltage readings are very low. So it's sitting there, but it's not turning, and the analog input on the arduino reads the same as if the motor were drawing current and turning.

I seem to have this catch 22 where if I put higher resistance, the motor doesn't turn at all, but if I don't put enough, there isn't a large enough voltage drop to measure. I'm beginning to think I need to just take a voltage reading across the motor leads with a separate circuit and then opto-isolate that and transmit it back to the arduino. Is that overly complicated?

Thanks again for all your help.

If you’re wanting to read low voltages only, lookup the analogReference(INTERNAL) function…