A single power supply for an Attiny84 and two motors

Hey guys, another question for you geniuses on the forum.

I'm making a small robot controlled by an attiny, driven by two 3v motors. (Their no-load current consumption is 0.2 - 0.4 amps) The whole thing is going to be mounted on a 2x AA battery pack, to supply power and hold everything together. I have the attiny controlling the motors with NPN transistors with an external 5v power supply for the attiny. I've even gotten the whole thing running (on a breadboard) with just the onboard 2.8 - 3v power supply, but there comes my problem. I have the attiny turning the motors on and off at intervals of 1 second. The motors won't start though, at least not by themselves. If I turn them a bit, they'll keep going until the attiny stops them, and then when the attiny tries to turn them on again I have to help. The batteries can turn the motors easily without circuitry, and it works if the attiny has a 5v power supply, so what's my problem? Is the 3v (3v is probably a bit optimistic) output from the attiny to the transistors to low to start the motors? Because I want this to be a small robot, I don't really want to add any more batteries. In series and they would overpower the motors anyway. Can anyone offer any help? Thanks. Geekyd00d.

"Their no-load current consumption is 0.2 - 0.4 amps" What do you mean with no-load current?

However, 0.4 amp on AA batteries does a huge voltage drop, I guess output voltage is around 2.5V when motors are on. Remember transistor do have a voltage drop too, maybe your motors are just receiving 2V, you should check with voltmeter.

Anyway, I didn't understand if you run attiny and motors from 3V together or you have a 5V supply to Attiny and 3V to motors.

Post a circuit diagram -- it seems likely that your transistor motor driver is not capable of providing the required startup current for the motors (which is the stall current). I agree with the previous poster that you are asking a lot from 2 AA batteries.

You should consider using a logic level MOSFET instead of a transistor since MOSFETs have a smaller voltage drop than ordinary transistors.

Hey guys, did a bit of reading last night - ohm's law. Using it, I fixed my problem! The robot only used to work when the attiny was running off of a 5v supply and when the motors had their 3v. When I moved the attiny onto 3v, the lowered voltage reduced the current available for the attiny to output to the transistors bases. So today, I lowered the base resistors values from 330 ohms to 22 ohms, which upped the current to the transistors base, allowing more power through to the motors. Thank you ohms law! Thank you to you guys as well for answering my question. When I said no-load current, I meant that I had the motors running with no load on them, they were free to spin while I measured the current. Also, MOSFETs are kinda out of the question because I wanted to just use parts I have. One last question though: will the lowered resistor values affect anything badly? Or will my "fix" run with no problems? I've had it running for 30 seconds with no heat or magic smoke, so I think I'm alright, but I'm not sure. Thanks, Geekyd00d.

You should not exceed 20mA from the ATtiny pin.

22 ohms @ 3.3V = 150mA, too much!!

20mA @ 3.3V = 165 ohm resistor

Thanks tylernt, but I've already soldered my circuit board up with the 22 ohm resistor. The operating voltage is probably closer to 2.8/2.9 volts because its being run off two AA rechargeable batteries. So it'd be 2.9 volts / 22 ohms = 131 mA. How badly could this damage my attiny? I've been running it for a while now with no problems. The only thing is that the outputs are on for a second, off for a second, and so on. What if I increase the resistor to 40/ 50 ohms, which would give a current of around about 64mA. Would this still be way too much over the 40mA it says in the datasheet? Thanks, Geekyd00d

Atmel, the people who make the chip, say that damage WILL be done above 40mA. They don't say how much damage or how long it will last under those conditions. So, your guess is as good as mine.

Why do you want so much current? If 20mA is not enough to drive your NPN transistors into saturation, you need better transistors, such as a ZTX1049A for example. Or you need to chain two transistors together -- pin drives one transistor with a 20mA base, which drives a second transistor with a 150mA (or whatever) base, which drives the motor.

Thanks for the reply, tylernt. The reason the transistors need such a high base current is because they're for high current applications, but they're the only ones I have that can drive the motors. I'm gonna try a darlington pair-type setup like you said as I have no other transistors that can drive the motors. I'll use low power transistors as the amplifier for the high power ones. I'll report back if it works/ doesn't work. Thanks! Geekyd00d

Actually, the darlington setup I tried didn't work too well. I've included a picture of how I set it up. (The professional looking picture) What about NOT connecting the transistors collectors? Like the hand-drawn picture? I've tried it out and it's worked really well, but I wan't to check BEFORE I solder everything up this time. Thanks, Geekyd00d

Oops, forgot to attach pictures! Sorry for posting on my own thread so much!

Having the first transistor's collector connected to VCC as in the hand-drawn circuit is fine, but I see two other problems.

First, the 100ohm base resistor on the first transistor is still too low. You are asking it to supply 30mA, which is technically within spec, but when you exceed 20mA the pin voltage drops -- you're getting rather less than 3V out of that Arduino pin. It may work now, but you may not saturate the transistor when the batteries aren't fresh (==heat). Using 150ohm will ensure the voltage stays within spec.

Second, there is no base resistor on the second transistor. The only thing limiting current is the fact that two AA batteries (especially alkaline) can't source infinite current -- the short circuit is dragging the voltage down which drags the current down as well. This is bad news for battery life. What part number are you using for the second transistor so we can check the datasheet? Also, what is the locked rotor or "stall" current rating of your motors? We need this info to determine a safe base current that will still saturate the second transistor.

Thanks for the quick reply! I can change the base resistor for the first transistor, thanks for pointing that out. Secondly, here's the datasheet for the second "bigger" transistors. They're a bit overpowered for what I'm doing but they're all I have to hand. http://docs-europe.electrocomponents.com/webdocs/0f9a/0900766b80f9a3ad.pdf The stall current of my motors is about 1.2 Amps. (I just held the motor from spinning and measured the current flow) What information do we need from the datasheet? Will you show me so I can do this myself in the future? Thanks, Geekyd00d.

If you look at the Static Characteristic chart on page 2, we want Vce (Voltage drop from collector-to-emitter) to be as close to zero as possible to reduce the amount of power wasted as heat inside the transistor.

So, your motor has a stall current of 1.2A (I'm assuming you're using one transistor per motor here). Let's give ourselves a wide, 100% error margin -- assume the transistor will be asked to conduct 2.4A in a worst case scenario. Looking at the Figure 1 datasheet chart, it looks like 100mA base current will just saturate the transistor for a 2.4A collector-emitter load, so a 30ohm resistor on the second transistor will probably work there. I consider 2.4A to be a generous error margin, so no need to drive the base harder than that for a 1.2A motor.

Incidentally, since you only need to switch a 100mA load with your first transistor from your Arduino pin, driving the base to 20mA is probably overkill (depending on which transistor you're using). If you're using a venerable 2N2222, for example, the datasheet shows that a 15mA base only has a 0.3V Vce(sat) for a 150mA collector-emitter load. You're not going to get much closer to zero than 0.3V for Vce(sat), so a 200ohm resistor on the Arduino pin should work. If you're using something better than a 2N2222, you may need even less base current.

Please note that when you switch a motor off, there will be an inductive voltage spike that "kicks back" into your transistor. MOSFETs can sometimes handle this spike on their own (they have a strong body diode), but BJTs aren't as robust. You'll want to add a "flyback" diode rated for at least 10 times the voltage, or at least 30V in your case. If you scroll down to the bottom of this page:

https://learn.sparkfun.com/tutorials/diodes

a flyback diode schematic is shown.

Thank you so much! Not only have you solved my problem, but you've shown me how to do stuff like this in the future. I was thinking about a diode, but I wasn't sure if I needed one. Thanks. Thanks for the hundredth time, (deserved) Geekyd00d.

I’m just paying it forward… someone did me the same favor a while back. :slight_smile: