DC motor control with Arduino

Ok, so i had this running just a few days ago, but then when i tried to assamble it didnt work out for me. Now I cant even get this simple DC motor running from the arduino, or to be more precise; the motor will run at a very low speed. Connecting it directly to my two 1.5 batteries it will run at full speed, but when trying to control it from the Arduino it wont work for me.

Here is my setup:

and the code is dead simple:

`int motorPin = 9; void setup() { pinMode(motorPin, OUTPUT);}void loop() { analogWrite(motorPin, 255);}`

I'm sure this is just a simple newbie problem, but i used several hours testing different solutions without a result.

Thanks for the help, in advance :)

There is a BC547B transistor
There is a BC547B transistor in your diagram, is that the one used? If so, there is a good chance that it has been burned, as it is only rated to carry 100 mA. You have not mentioned what motor is being run, but many require more current than this.

The maximum Vcesat for a

The maximum Vcesat for a BC547 is 0.6V, which leaves 2.4V across the motor. That means that if the motor resistance was less than 24Ω and the transistor was driven into saturation (both very likely), you’d exceed the current limit and as robologist points out you’d end up with a crispy transistor.

You can fix this by either:

• Dropping an extra resistor in series with the motor (lame, wastes power).

• Adding more BC547’s in parallel with each other until the combined current tolerance is high enough (not very tidy, takes up a fair bit of space).

• Finding a new NPN transistor that will tolerate the full motor current.

My favourite choices for basic motor driver discrete NPNs are the BC327 (same size as the BC547, but handles 500mA) and the BD139 (a little bigger, takes up to 1.5A). You can either measure the resistance of the motor when it’s stopped and calculate the maximum current, or connect the batteries to the motor and measure the current directly. Don’t forget that the effective resistance of the motor will drop as it speeds up, so the maximum current flows when it’s stalled.

Thanks for helping me solving this mystery

Of course I wasnt aware of the maximum current on the NPN transistor. I measured the current from the motors with a multimeter while the battery was connected and it gave me about 150 mA if i remember correctly. Its a small Tamiya Dual Gearbox i’m using for this project. I guess i’ve burned 3x BC547 transistors doing the testing before i made this forum post.

I ordered a few H-bridges(SN754410) from sparkfun.com together with Qik Dual Serial Motor Controller. Also got a 613 pieces Electronics Starter Kit from bitsbox.co.uk, but none of which have arrived yet. The starter kit does have a few BC337 NPN transistors, I guess these would work with the motors i got. For now I might just have to put up an extra resistor in series with the motor since i only have two of these BC547’s left.

I’m very happy with the kind help I’m getting here at LMR and looking forward to post my first robot some time soon.

Motor Controller

I have the same motor controller and really like it. In fact I just ordered another one.

Cool. I’ll look at it. I’m

Cool. I’ll look at it. I’m much better at coding then I’m with electronics. But I always enjoy learning new stuff

Update: Looks great ericsky. I’ll make sure to send you a note if I use it/or extend it. Nice and clean code as well. See what the softSerial library is about as well i guess.

Source code
If you want to live on the edge, the version controlled source code is more up to date than the zip file. I have almost all of the controller’s functionality coded but I haven’t tested it yet.

The twin motor gearbox has
The twin motor gearbox has some difficulties with the motors as detailed on the Pololu website. Essentially the Mabuchi FA-130 motors are meant to be run at 1.5 to 3 volts, and even at these levels can draw a lot of current (2.1 A stall at 3 volts, higher to burn out at higher voltages). It is recommend to run these with Pololu Low Voltage Dual Serial Motor Controller, so they can be run within their voltage range. If you wnat to use the h-bridge you’ve ordered, it is recommend to replace the 3 volt motors with a pair of 6 volt motors.

As it turns out it might
As it turns out it might take a couple more days before I get to assamble the motor controller so i’ll probably look at it again, then. But always nice when people share their code which might have a general purpose value, as this.

I’ll look into it, and drop by a local RC store to see what they got. I sure wanted to use the motor controller I bought. The H-bridges i bought i just got since i thought they’d come in handy. I didnt expect to use these motors on my next robot project, bought the gearbox as it looked handy. I’m planning to do a 2-wheel balance bot during the summer, but so far I’ve just tried to figure out the basics. To do a balance bot I probably need motors which are quicker to respond.

Anyway. Thanks for the nice links. I was kind of expecting to meet all these issus, since when ordering, I just picked the parts I thought where the best. Probably should have made a forum post at that point

Edit. Just realized I must have fried my 4N35 optocoupler as well