I've programmed the Arduino Uno to generate PWM corresponding to the serial input values. And it works fine with an LED. I took the connection from PWM pin 3 (where I set the output) to the base of a BC548 transistor and connected the motor in series with an external motor power supply (Vcc) and the collector and the emmitter is grounded (to both Arduino's GND pin and the external supply's). The motor had a fly wheel diode, 4N4007, and a capacitor of 1 µF for protection.

But when I connect the motor and provide it with the PWM input, it works for a few seconds and then I see a few flashes in the rx and tx LEDs, and it stops working even with a serial input or reset. I need to turn it off and then on to make it work again. The same thing repeats when I connect the motor, but it works fine with an LED.

How can I fix that??

  • 4
    Welcome to Arduino.SE. It would be helpful for us to see your source code and a circuit diagram. Sep 17, 2014 at 18:34
  • 1
    A few questions: what motor model do you use (a link to a datasheet would be good to look at); have you put a resistor between Pin 3 and the transistor base? Which value? Does your program use Serial? Could you post the code (or the relevant parts of it if it is too long)?
    – jfpoilpret
    Sep 17, 2014 at 19:20
  • I second the resistor between pin 3 and the base of the transistor. The rest sound fine; you've even thought of the flyback diode, and connected the two grounds together.
    – Gerben
    Sep 17, 2014 at 19:54
  • 4N4007? Do you mean 1N4007? Oct 16, 2015 at 13:39

3 Answers 3


I think your Arduino resets itself because of connection or current overload. Also, please share your connection. What is the voltage of the external source? If it needs high power, try a MOSFET like this.


It's hard to know without an oscilloscope, but as a guess you might be seeing voltage spikes on Vcc at the reset pin due to inductive load dumps from the motor. Per Atmel app note AVR042, you might try a 5V zener diode from the reset pin to ground and/or a capacitor to snub the spikes.

  • In addition to the zener or a cap (that should be reasonably close to the motor) you can also use a flyback diode (which is a normal diode wired parallel to the motor) to suppress interference from the motor. See en.wikipedia.org/wiki/Flyback_diode
    – Dave
    Sep 18, 2014 at 13:52

You might also want to consider purchasing a simple and popular L293D motor driver chip. I teach basic Arduino classes and learning to use this chip is much easier than using transistors and diodes. The other advantage is the motors can go both forward and backward!

On the following link you can purchase one chip for under $1.00 USD and each chip will driver two motors both forward and backward.


  • This is not an answer to the question which was asked. Additionally, the L293/L298 are antiquated devices with high internal losses which really should not be used for new designs. Jun 4, 2016 at 19:36
  • Do you have an alternative design that would work better? Jun 6, 2016 at 16:57

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.