I'm new to hardware and I've been working on SparkFun's getting started projects (I'm on project 3 "transitors & motors") and I've uploaded a detailed JPG "step-labeled" photo with my wires, resistors, transitors, diodes, etc all connected.
So ... plugging some wires into a breadboard and copying directions & code and having something "work" is great. But I (like some other newbies -- from what I've read on the NET) are a bit lost on how the current flows through the whole circuit and the why resistors and diodes and components are in particular places in the chain (and physically on the board) and what they're doing. Initial questions that come to mind are "could i have moved this wire to a different column, row, etc?" "In what component order does the current flow?"
Lastly, being that I've uploaded a pretty detailed JPG of my components/wires connected -- could some nice souls who understand this shed some light on anything you deem worthy of explaining related to what's happening in the diagram -- especially any pointers related to the event chain.
- Thanks, Bryan
You bring up a good point. Does anyone new to electronics fundamentals really learn anything from just following a tutorial to build a simple circuit that does something? Or have they only demonstrated that they can follow detailed step by step instructions? The ladder is a useful skill but I'm of an opinion that only by going through a good tutorial or training manual (or formal classroom instruction) on learning fundamental electronics does one gain knowledge to understand what they are constructing and how and why the various components (and their values) interact with each other. If one first learns the fundamentals of say ohms law, then building practical hands on projects make good sense as real world examples to help apply the fundamentals acquired.
Too many arduino projects focus on just getting a project functioning rather then being a formal learning step in acquiring real knowledge of electronics. Also many electronic projects and circuits published on the web can range from complete rubbish and dangerous to very good and cleaver, and without good understanding of fundamental electronics it's hard for many to tell the difference and that can lead to lots of frustration and wasted time and funds.
Most good cooks can follow a recipe and create a tasty meal, but a real chef can create new recipes.
There are some 'professional' teachers and instructors that hang around here from time to time. It would be good to hear from some of them on this topic.
I fully agree, lefty. (Except I always thought the ladder would be very helpful in climbing SCNR)
Bryan not only followed carefully step by step instructions (could not find them, however, without link) ,
I understand he also created this step-labeled jpg. Really good, the step marks help in following the circuit. ( I would not have examined the picture otherwise ).
But, while learning fundamental theory (voltage and current), one usually also learns to get used to circuit diagrams, which very soon become much easier to read and understand than pictures in 1000x1000 resolution.
In your jpg, the most relevant part, the transistor, is the black speckle at the bottom, labeled "resistor", I assume ?
Impossible to tell if it's put in correctly, though ( Which highly depends on its name and type )
From your diagram, I believe the circuit you have made is what I have drawn in the attachment.
Lets work through what everything does.
The Motor and Diode
A motor is a device which converts electrical energy into mechanical energy. There are many types, but you have a small DC motor. For such a motor, if you apply a sufficient voltage, the motor will spin. Lets say that sufficient voltage is 5v, as that is what you are using in your circuit. If you connect +5v to the red wire, and 0v to the black wire there is 5-0=5V across the motor and so it will spin. If you reverse the red and black leads it will spin in the opposite direction as you now have 0-5=-5V across it.
The problem with these motors is they have some 'inductance' associated with them. The inductance comes from the fact that the motor is setting up a magnetic field which is what is moving the rotor. Now the voltage across an inductor is equal to its inductance multiplied by the rate at which the current flowing through it is changing. If you change the current slowly or not at all, the voltage is very low or zero. But if you change the current very quickly, the voltage is high.
Now consider what happens if you disconnect the supply from the motor instantly (pull a wire out of the breadboard). If the motor had current flowing through it, the current has instantly stopped as you pulled out the wire. This means that the rate of change of current is theoretically infinite. Based on that, the inductance in the motor suddenly has infinite voltage across it. Now infinite voltage sounds a totally daft concept, and thankfully it doesn't happen. Instead you get a very high voltage which causes a spark as current rushes through the air from one terminal of the motor to another. To protect the motor from this arcing, what we can do is put a 'freewheeling diode' or 'flyback diode' across the motor.
A standard diode acts like a one way street. Current can only from the Anode (A) to the Cathode (K), and not the other way around. If you connect the diode as shown in the diagram (ignoring the transistor at the bottom for now), can you see that current will not flow through it? (The anode is at 0V, the cathode at +5V, so it is reverse biased - in other words current wants to flow from the +5v to the 0v, but can't as that would require it to flow from the cathode to the anode). So normally in the circuit below, the diode wont conduct.
So how can we use this to protect the motor? Well, when the supply is removed, the inductor wants to keep the current moving so that it doesn't have infinite voltage across it. As such it drives a current which can now flow from the '-' terminal of the motor, through the diode (going from anode to cathode, the direction a diode conducts), and back to the '+' terminal of the motor. This current decreases as the energy stored in the inductance decreases, until eventually the inductor is discharged and the current stops. Hurray, the supply can be switched off instantly and the motor is protected from sparks.
Basically the transistor is a cross between a switch and an amplifier, and really how it works depends on what transistor type you have. I have drawn a BJT (Bipolar Junction Transistor), such as the 2N2222A or BC547 and many others. I am guessing you have the former as I found a page which references the tutorial I believe you followed.
The way a BJT works is that if a current 'B' flows into the base (and out of the emitter), a larger current 'C' flows into the collect and out of the emitter. These two currents are proportional to each other.So we can say that:
C = H x B
Where H is the 'DC current gain' of the transistor. This value depends on the voltages and currents you are using and is generally not linear, but lets for the say of simplicity say H=180. This is about correct for the value of current I will use below according to the datasheet.
Lets say that the motor requires 77mA to flow through it in order to run. Looking at the circuit, that means we need 77mA to flow from the +5v line, through the motor, and into the collector of the transistor. Based on what we have said about currents in the transistor, this means we need a current flowing into the base of:
B = C/H = 77 / 180 = 0.43mA
There is one more thing that you should know about BJT transistors and that is that in order for it to switch on, you need approximately 0.7V between the Base and the Emitter. That is where the resistor in the diagram comes in.
The voltage across a resistor is defined by 'Ohms Law' as:
V = I x R
Voltage = Current x Resistance.
For this circuit, we need 0.7V across the base, and 0.43mA flowing into it. As such we need a resistor which will converter a Logic 1 of +5v to the values we need.
If we want 0.7V at the transistor, that means the resistor has to drop 5-0.7=4.3V. Furthermore, we need 0.43mA to flow into the base, and in this circuit the only place it can come from is from Pin9, through the resistor and to the base. So we need 0.43mA to flow through the resistor.
Using Ohms Law we get:
R = V/I = 4.3/0.00043 = 10000 Ohms, or 10kOhms.
What happens if we put a logic 0 on pin 9. Well, you will have 0V at pin 9, which means there is 0V dropped across both the resistor and the transistor - think of it as a hill, to top of the hill is at 0V, the bottom of the hill is at ground (which is 0V), so the height is 0.
If there is 0v across the resistor, then you have:
I = V/R = 0/10000 = 0mA flowing into the base.
If there is no current flowing into the base, then there is:
C = 0 * 180 = 0mA flowing into the collector.
No current flowing into the collector means no current flowing through the motor, which means the motor is turned off.
I know I went through that kind of quickly, and there are a lot of words, but if you go over it a couple of times, having a look at the schematic attached, then feel free to ask about anything that is unclear.
(*Disclaimer: some of this post has been over simplified, but that is to make the overall concept of the circuit clearer)
(and physically on the board)
The physical location does not matter for these sorts of circuits, just as long as the electricity flows round like it was designed to. That is as long as the circuit is topologically correct the physical layout is not important.
In a circuit with two or mor components in seriese, current does not flow in one component before an other, if flows through them all at the same time.
Wow Tom -- thanks for being amazingly helpful and detailed with your explanation. That was exactly what I was hoping for. I read and the re-read what you wrote line by line, several times until I had an intuitive feel for what's happening.
Guess that leads me to wondering if anyone has suggestions for future kits/projects that combine this kind of theory and explanation with the kit/project itself?
Best - Bryan