What happens if I connect something that needs more than 40mA to an output in arduino diecimilla?
Does it damage the arduino? Or does the arduino only supply 40mA despite the component needs more?
Also, do the 40mA limit apply only to the digital outputs or also to the power supply pins (5V and Grd)?
When I connect a circuit like this what is the current drawn to the arduino? And what is that 1K resistor for?
Yes, I know these are very noob questions. I have only a very basic knowledge about electronics and electricity and that's why I bought Arduino, so I could learn more...
40mA is the manufacturer's "absolute maximum rating", which means it's pretty much undefined exactly what will happen. The arduino does NOT limit the current to the 40mA max. The limit does not apply to the power pins (although there is in addition to the 40mA limit a 200mA limit for the whole chip (GND, 5V.))
In the transistor circuit you show, the current flows from the output pin through the base-emitter junction (along the direction of the arrow) and to ground, so it's limited by the resistor to less than 5mA.
Whoa, lots of questions. Let me try them in order.
- I would not connect something that draws more than 40mA.
- It might damage it to pull >= 40mA since that is the 'max' rating.
- The +5 output is generated by a 7805 voltage regulator, so it should be able to provide around 1-1.5 A. HOWEVER, it is not really heatsinked. I would not draw more than 500mA from this supply - and that might be pushing it.
- The resistor on the base of the transistor is to protect the transistor. Check out: Transistor Circuits for some good info on what this circuit means.
In the circuit in the drawing above, the motor is suposed to have it's own powersupply, it should not be powered from the Arduino board, but the motor powersupplys ground and the Arduino boards ground should be connected together.
Thank you all but I still have some questions about the transistors.
1 - I read the site bnasty posted and it was very helpful but I still don't understand that current gain thing. So, the transistor amplifies current?! I thought that it just worked like a switch when current was applied to the middle pin.
2 - How do I know the current I should apply to make it saturated? They say that "A safe rule is to make the base current IB about five times larger than the value which should just saturate the transistor", but which value is that? And they talk about 0,7v being needed to saturate it. Does this mean that every transistor saturates at 0,7v? What happens when I supply it 5V?
Sorry but I'm very confused with this.
A transistor can work in two ways, as an amplifier or as a switch. When a small current is applied to the base a largher current can flow between the collector and the emitter.
If the trannie is saturated it works as a switch. Don't worry too much about saturation and all that if you use the schematic above it works. But the transistor in that schematic (which is from Tom Igoes brilliant book Physical computing - highly recomended) is a darlington transistor a TIP 120 to be specifik.
If you want details look up your transistors datasheet at www.alldatasheet.com
The 1K resistor limits the current through the Arduino's I/O pin that is controlling the TIP120 (which is actually a Darlington pair, not a single transistor) -- in this case it will be something around 4.4 mA because the Emitter/Base voltage drop is 0.65 volts (5v - 0.65v = 4.35v; 4.35v / 1000 ohms = 0.00435 A). Note: I went and bought a TIP120 to measure the VBE -- the 4.4 mA is a more accurate estimate.
FWIW, the TIP120 has an internal snubber, so the diode (e.g. 1N4001) in the circuit above really should be across the motor (or other inductive device). Here's a link to a TIP120 data sheet: http://www.learn-c.com/tip120.pdf
A really good beginner's book is called "Getting Started in Electronics" by Forrest M. Mims; it introduces electronics principals in a manner that anyone can absorb. I suggest you get a copy as understanding some basic electronics concepts will help you create better projects with the Arduino and, possibly, prevent you from doing accidental damage.
Does it help to think of a "switch" as a special case of amplification? The small control signal is amplified to "as much current as I need" in the switched circuit.
Ok, I now understand that the on/off switch can be thought as an amplification of the control signal, so the small current applied is amplified acording to the voltage of the switched circuit.
But how exactly do I determine the ideal voltage and current I should apply to the middle pin of a transistor? Could you explain better where those values come from JonnyMac?
The transistor will have a drop across its Base-Emitter junction that is usually around 0.7 volts. The current through this junction controls the current through the Emitter-Collector junction (there is a specification called hFE which can be thought of as the amplification factor -- Base current (IBE) x hFE gives theoretical E/C current; once this is maximized the transistor is considered a switch). You control the current through the E/B junction via a series resistor into the Base.
A common NPN transistor is the 2N3904 (Intelligent Power and Sensing Technologies | onsemi). It's lowest hFE is 30 when driving 100+ mA through the E/C junction. If we want to make sure the transistor is maxed we can take its spec'd max E/C current (200) and divide that by hFE (30) to get 6.7 -- this is how many mA we should drive into the B/E junction for saturation.
So, we take 5 volts (control output from the Arduino), subtract 0.65 (VBE) to get 4.35. Using Ohm's Law (R = E/I) we take 4.35 and divide it by 0.0067, the answer is: 649. Now, 649 is not a common resistor value but 680 is, and that's close enough to be just fine. Or... you could use a 1% resistor ($) to get very close. Yes, you can use a smaller resistor, but then you're giving up extra current from an I/O pin that you might want elsewhere. Also, if your load on the Collector is less than 100 mA you should consult the spec sheet as hFE is higher at lower E/C currents -- if you're only switching 50 mA, for example, hFE jumps to 60 which means less current is required into the Base.
As ever, all engineering exercises come down to a series of choices.
HTH
PS: Get the Mims book -- it will really help.
Thank you very much. I think I now understand how transtistors work. And I think I'll follow your advice and buy that book so I don't explode my arduino.
One last question, imagine I don't add any resistor to the middle pin. How many current would be drawn? Would it be like a short-circuit?
It would be nearly a short-circuit and likely blow the output driver of the Arduino. You might still be able to use the pin as an input if it blows open, but if it fuses short (another possibility) to Vdd (5v) or Vss (ground) then the pin is toast. When in doubt, use at least 220 ohms in series with the I/O pin to protect it.
Microcontroller outputs are RELATIVELY robust. First of all, they're MOSFETs, which are somewhat less subject to damage from overcurrent conditions - as they get hotter, the "effective resistance" goes up, reducing the amount of current that they'll pass. Second, they're not "great" MOSFETs, so they have an effective on resistance (even under normal conditions) that is relatively high and will limit the current to somewhat reasonable values (this is why you see so many projects get away with driving LEDs directly from microcontroller pins with no current limiting resistors.) You can actually take some measurements and calculate the effective on resistance of the driver transistors; it'd be an interesting exercise for a mid-level electronics class.
However, none of that behavior is guaranteed; it can vary from part to part, vary based on supply voltage or ambient temperature, and vary significantly if you or the manufacturer change the part (eg from Mega8 to Mega168, or to an "A" version of a micro.) If you want to be safe, you MUST limit the current to less than the 40mA "max current" spec in the datasheet.
Thanks, now could you explain me the difference between a transistor and a MOSFET? This guy here: http://www.societyofrobots.com/schematics_h-bridgedes.shtml says the MOSFETS are mutch better then transistors. He also says it's better to amplify the 5V and I understand that's to make the resistance as low as possible so it does't get so hot. However he does't say to how much I should amplify the 5V. And by the way, how does a voltage amplifier work? Does it just increase the voltage? I didn't think it was possible, so with a voltage amplifier can I power a 9v motor with a 1,5v battery? :-?
How, in this case do I calculate the resistor value? Is it always 1k? He used a 1k and didn't even say how many voltage he was using to the middle pin...
mofets have their advantages. While a normal transistor is operated by CURRENT, a MOSFET is operated by voltage (and essentially zero current flows one the "gate" control pin.) So a mosfet doesn't need a resistor in the base lead to be driven by a microcontroller. On the other hand, there are other issues (many mosfets want more than 5V to turn on fully, for instance), and they tend to be more expensive. I'd say it's pretty much a tossup...
As for the amplifier question: think of an amplifier as working on a signal, rather than on "power." You can easily use a transistor to turn a 1.5V SIGNAL into a 9V signal for a motor, but you need a 9Vpower supply in there as well. (so for instance, the circuit you showed originally could control a 24V motor from a 5V arduino pin, but that wire labeled "to motor power supply" would need to go to 24V.)
1 - Ok, so in a mosfet i don't need a resistor because it uses no current. So why did that guy use a 1k one?
2 - And, I have many old motherboards, can I use their mosfets in a circuit like this? How do I discover their specs such as the voltage needed to completely turn on the middle pin and the maximum current and voltage in the other pins?
3 - Is a voltage amplifier like a transistor? Are there any differences?
I'll just stop asking noob questions and read the book Jonnymac told me when I have time. Just please tell me which transistors and resistors and diodes and whatever you would use to build an H-bridge to control a 9V motor (with it's own power supply) from the arduino. I don't want you to explain me anything more. I'll try to understand it later when I read the book. Just imagine you would build a circuit like this, and tell me which components you would use.
Thank you all.
EDIT: is it this simple http://www.toddholoubek.com/classes/pcomp/hbridge/Hbridgel293.html or is it better to build the H-bridge with transistors and all the other complications?
EDIT: is it better to power my arduino with 6 or 8 1,5V batteries? (9V or 12V?)
IMO, it's better to use an H-bridge chip IF your motor specs are within range of the chip, and you can get the chip at reasonable cost. For simple forward/reverse sorts of functions, I'd be real tempted to get something like These chips from eBay (9 drivers for $9, shipped...) Otherwise, you (as a "noobie") should find an existing H-bridge circuit and use the transistors and other parts specified in the design.
6 cells (9V) is better than 8 cells (12V) since the arduino regulator is "dumb" and will just throw away the extra voltage as heat, anyway.
FWIW, the TIP120 has an internal snubber, so the diode (e.g. 1N4001) in the circuit above really should be across the motor (or other inductive device). Here's a link to a TIP120 data sheet: http://www.learn-c.com/tip120.pdf
If it already has an internal diode, do I really need to add one across the motor? The internal one should do the same thing. Or am I wrong?
Can I use the components in the first picture I posted to make an H bridge? Is the resistor value correct? And is the TIP120 the transistor I should use?
I would use the diode, but put it across the motor (or other inductive device) as is typical in these kinds of circuits. That common design practice is used for good reason: it's a cheap and reliable way to protect expensive components (like your Arduino).
I used Google (a valuable tool) to search for TIP120 and H-BRIDGE and found the following page:
-- http://www.bobblick.com/techref/projects/hbridge/hbridge.html
... though I dare say the circuit is probably more involved than you want at this stage.
If your motor is very small, you could use the L293D chip as I did in this article I wrote for Nuts & Volts:
-- http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol7/col/NV137.pdf
EDIT: I see now that another L293D circuit was suggested; use that as it shows the connections/code for Arduino (mine was for the SX28 which I use most of the time).
Note that if you build an H-Bridge then you should NOT put a diode across the motor as in the circuit above. H-Bridges reverse current flow through the motor; in the circuit above current flows in just one direction.
The resistor value is fine; that was explained in excruciating detail in an earlier response.
Let me suggest that you resolve in 2008 to hit the books a bit. Really, electronics is not that difficult -- if a professional actor can do it (you don't see a lot of brain surgeons on the red carpet do you?), you can! Happy New Year.