I've recently begun experimenting with AVRs and am keen to progress beyond making blinkies to making things move. I've tried to start with something easy, but it seems I'm already foiled! What I'd like to know is this: is it possible to drive both an AVR and a motor from the same power source and without them interfering with one another?

The schematic below illustrates my initial attempt at doing this. The ATtiny is generating a ~3kHz PWM signal (1/3 duty cycle) on pin 5, with the intent of supplying a time-averaged voltage of 3V to the motor via the power transistor. When I wire this up though, the motor just seems to cough and sputter. alt text

Thanks heaps in advance,


p.s. I'm just wondering about the fundamental possibility/impossibility of what I'm trying to do: I don't expect anybody to debug my circuit for me! :-)


It's possible, sure. Is the 9 V drooping a lot under load and dropping it out of regulation? Is the voltage on both sides of the motor what you expect? You might need bigger capacitors to keep the supplies "stiff", and make sure the voltage drop caused by the motor's current in the ground wire isn't affecting the AVR's ground.

  • \$\begingroup\$ Thanks: great to know I'm not barking up the wrong tree! The voltage seemed a bit high (closer to 5v than 3v), but it's difficult for me to say exactly what the voltages are in this circuit due to my crazy idea of using PWM to step the voltage down. When briefly subjected to a similar voltage outside of this circuit, however, the motor didn't sputter. Maybe the load is causing the AVR to reset, or the PWM signal needs to be explicitly filtered.. Anyway, thanks again. \$\endgroup\$ – Tim Apr 13 '10 at 5:25
  • \$\begingroup\$ I've just tried it with the PWM replaced by a solid HIGH and the sputter persists. It must be due to the drooping of the 9V under the load, as you suggested. \$\endgroup\$ – Tim Apr 13 '10 at 13:41
  • \$\begingroup\$ How is it a crazy idea to step down with PWM? That's what any switching amplifier or regulator does. You can easily figure out if it's droop of the 9 V by just measuring the input terminals of the regulator with a multimeter, with and without the motor running. If it's the switching of the output that's causing the problem, then filter it out or increase the PWM frequency. \$\endgroup\$ – endolith Apr 13 '10 at 19:29
  • \$\begingroup\$ What's the voltage across the motor itself? Is the transistor not able to source enough current even when fully closed? \$\endgroup\$ – endolith Apr 13 '10 at 19:35
  • 2
    \$\begingroup\$ If you remove it, nobody can benefit from it! \$\endgroup\$ – tissit May 18 '10 at 8:21

Not sure you need the diode in series with the motor the way you've shown. All it's going to do is drop some voltage and generate heat (unless it's an LED).

You probably do want a diode in parallel with the motor, oriented with the cathode toward the positive supply. The diode will clamp any high voltage excursions caused by inductance in the motor, so that the collector of the pass transistor will never see a voltage higher than one diode drop above the supply voltage.

Also, you should probably have a small capacitor with good high-frequency response tied directly across the motor, to cut down on EMI caused by arcing in the brushes. Usually 0.01uF or 0.1uF disc ceramics are used.

Larger transistors sometimes take a bit more drive, so consider the resistor from PB0 to the base of the TIP 122. Not sure what the specs are for the TIP 122, but you want to make sure that when the level on PB0 is at its high state, the collector should be very close to ground, not more than about 0.2V.

Also, how big is this motor, and how big is the battery? Nine-volt alkaline batteries aren't known for having a lot of current capability, so I'm assuming the motor is quite small. You should be able to take a wire and short across the collector and emitter of the transistor w/o harming anything, and if you do, the motor should turn.

  • \$\begingroup\$ Thanks for all of these helpful comments! As I mentioned in an earlier comment, the problem was actually a faulty breadboard, but the advice you've given is great to know. The intent of the diode was as you described, but obviously I got that wrong. I'll also add the decoupling capacitor in future. \$\endgroup\$ – Tim Jun 30 '10 at 23:45

I don't know why you placed the diode in series with the motor; it's not needed there. Which doesn't mean that it's completely wrong, it's just in the wrong place.
You use a diode to isolate the motor from the ATtiny, but you'll have to place the diode in front of the 0.22\$\mu\$F capacitor, and connect the motor directly to the 9V source. (By the way, the 0.22\$\mu\$F is way too small; make it a 500 times larger, so 100\$\mu\$F. Place a 1\$\mu\$F in parallel.) Now if the motor draws current it only can draw it directly from the 9V supply, not from the capacitor, so negative spikes won't reach the ATtiny's power pin.

You also have to place a flyback diode over the motor, anode to the transistor's collector.


I'm late, but I'd say:

Divide and conquer. You tried the motor without the controller, try the controller without the motor: put in a simpler dummy load (resistor).

Stop thinking and look! Did you measure the pwm waveform? Make sure you're getting what you're expecting. Maybe add a heartbeat led or something else to see if the program is running or if it's doing something like resetting spuriously.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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