DC motor won't work under load - Possible supply problem?

Hi all

I'm doing some learning with Arduino, and to test some concepts I've put a very simple circuit with a car toy DC motor.
I don't have any specifications for the motor, and don't have a clue on how to get them.

First the circuit (sorry for the atrocious ASCII):

                       o--diode----o
9V +---------|---------|-DC motor--|-o
            Light                    |
            Sensor                   C (collector)
             | ....Arduino magic..  B (base)
                                     E ----- GND

I'm using a transistor (2n3904) as a switch to turn on the motor. The base is connected to a digital pin that responds to a light sensor.

Both the Arduino and the motor are powered with the same 9V battery. When I shine a light on the sensor, the motor spins if there is almost no load (wheels off the table), but as soon as I put the car on the table, it stops. My guess is the 9V battery is not enough for both the Arduino and the motor, but I've tried this with external supply for the Arduino (serial cable) and got the same result.

When I feed the 9V directly to the motor, it works. I know there is a V loss on the transistor (around 0,3?), but I don't think this should be trouble...

Any ideas?

I'm using a transistor (2n3904) as a switch to turn on the motor. The base is connected to a digital pin that responds to a light sensor.

You might be overloading the output pin if your not using a series resistor between the output pin and the base of the transistor. Try a 500-1000 ohm resistor.

Lefty

Forgot to put it on the "diagram", but I'm actually using a 330ohm resistor between digital output and base pin, and 990 between base and GND (saw somewhere this setup, and adjusted the values until I got a response from the motor).

Maybe I should adjust these values? I have no idea how to calculate something like this...

I took the switch from here SECARS Homepage - SECARS, look at Figure 2.

I used the 9V as it was the cheapest / easiest to find, I'll look for something better...

As well as the 9v battery being unsuitable (unless it is an expensive lithium one), the 2n3904 transistor is not designed for switching the amount of current taken by a motor under load. Use instead a bc337 for a small motor, or an npn power transistor or mosfet for a larger motor.