Using an Arduino Mega. I have a motor hooked up exactly like the picture below. Using a BC548B transistor, 1N4001 diode, 220 ohm resistor and a 9V battery. I'm driving the motor in code by using PWM analogWrite to value 255. Weird thing is, if hooked up to USB (5V), the motor will only start to move after a certain amount of time, seems like it needs some initial "drive" to get started. If using the 9V battery it starts up quicker, but still not directly, as I would expect. Also, if I set analogWrite to some value less than 255, it will not move at all - is the transistor limiting? Can I change the resistor value to compensate? Thanks for any advice.

int motorPin = 3;
int interval = 10;
int walkingTime = 7.5;
bool walking = false;

void setup() {
  pinMode(motorPin, OUTPUT);

void loop() {
  delay(interval * 1000);
  if (!walking) {
    delay(walkingTime * 1000);

void startWalk() {
  walking = true;
  analogWrite(motorPin, 255);

void stopWalk() {
  walking = false;
  analogWrite(motorPin, 0);

Motor & Arduino hookup

  • First off, you need to ensure the transistor you use fits with the motor you want to drive; you did not mention any spec data about that motor, so it is not possible to answer your question. Second, a 9V battery is never adequate to drive a motor as it is very limited in energy (measured in mAh). Finally, changing the resistor value will certainly not compensate for anything power-related, 220 Ohm is a rather adequate value for this kind of usage.
    – jfpoilpret
    May 30, 2015 at 9:35
  • I don't think there is any diode with PN2222 reference, it seems you confuse with a transistor reference. Typical diode references are 1N100X (replace X with a digit).
    – jfpoilpret
    May 30, 2015 at 9:39
  • Although I don't think the problem is with your code, it might still be useful to post it also so that we can definitely remove any issue with coding.
    – jfpoilpret
    May 30, 2015 at 9:40
  • Sorry for the confusion, it's a 1N4001 Diode. The motor is packed within a plastic enclosure and I can't read any info on it but will try to use a multimeter to find out how much it draws and report back. Will update the question with the code now. May 30, 2015 at 11:33
  • It won't solve this problem, but you really should get a capacitor in there. The motor may have a high starting current, especially if there's a load on it. Adding a capacitor between Vin and GND on the breadboard will help dampen any large current draws being inflicted upon the board. 220uF, rated at 16V minuum is a good starting point. Better still, if the motor is going to be drawing quite a lot of current you should consider connecting the yellow wire of the motor and the blue wire of from the transistor directly to the + and - of the battery, respectively. Jun 1, 2015 at 3:16

1 Answer 1



Your transistor is the wrong way round.
Rotate it 180 degree (so that collector and emitter are swapped) and it should work.

There are much better transistors available for this job, but this one should work when correctly connected.

Swap, test, report back.

The blue wire goes from emitter (right hand lead) to Arduino ground.

enter image description here


The transistor is almost certainly "backwards" as above. More on that below, but first some comment on the actual transistor used and a superior alternative.

While it should work better than you describe, the BC548 is not a very good transistor for motor driving. It's maximum collector current is 100 mA. While you do not state the required motor current, within sensible limits a good guide is that the more a transistor can handle the better it will work, all else being equal. A 500 mA rated part would work better. An excellent pair of small transistor for "playing" are the BC327-40 (PNP) and the complementary BC337-40 (NPN). These have guaranteed current gains (effectively current amplification factor) of 250 and typically of 400. They are typically rated at 45V and 500 mA. The Fairchild versions data sheet here from Digikey have an absolute maximum 800 mA rating. While the part was originally a European one it is widely available in the US and Asia and is usually about the same price as transistors with substantially inferior specs. eg see Digikey pricing below for BC548B and BC337-40 in 1, 10 and 100 quantity. The BC337 costs 1 cent more per transistor in each case. The BC337 comes in 3 versions with suffixes -16, -25 and -40. This relates to the current gain. The -40 part has an average Beta or current gain of 400. This is better (higher) than most alternatives and costs little or no more than the lower gain -16 and -25 parts.

BC548B datasheet here
BC337-40 datasheet here

BC548B pricing
1 10 100 prices are 22 / 20 / 11 cents each.

BC337-40 pricing
1 10 100 prices are 23 / 21 / 12 cents each.

According to that the pinout is CBE (collector base emitter) left to right looking at flat front with pins down. There are occasionally variations between manufacturers (but should not be) but if the datasheet matches your transistor it is "in backwards".

Swap C & E by rotating 180 degrees and report back.
With C&E swapped it acts like an NPN withj very low current gain.

Note: Presumable where you saay digitalWrite you meant analogWrite?

  • Will try turning the transistor around later today and report back! And yes, I meant analogWrite instead of digitalWrite. May 30, 2015 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.