This series of articles are the study notes of "Interfacing with the Arduino", by Prof. Harris, Department of Computer Science, University of California, Irvine. This article is the notes of week 1, lessen 1.
2. Lesson 2
2.1 Lecture 2.1 - Electrical Components
Now, you know, we understand V = I*R, Ohm's law and so forth, that relationship. But you're eventually gonna have to actually build these things physically. You're gonna have to take these components.
There are lots of different components. Eventually you're gonna have to take these and actually plug them together and make a circuit out of them. Now, typically, when you do that, you also have what's called a schematic diagram. And we're gonna show some of these. But, so you start off. Usually when, say you're thinking of a new design. What you do is you write,
you draw out a schematic. A drawing of what should be connected to what. Now this schematic drawing,
typically, it shows what components connected to what, what terminals connect to what. But it doesn't show exact placement. It doesn't show how it will physically look in the real world. It shows, though, how you would expect it to be connected electrically.
And given a schematic, you're going to have to get used to taking that schematic and implementing it. Meaning wiring some components together according to the schematic. So that's the type of stuff we're gonna cover right now.
2.1.1 Resistors
- Provides resistance to current flow
- Two terminals; no difference between them
- Band colors indicate resistor size
- Each color is a digit; scientific notations is used
2.1.2 Battery/DC Power
- Provides voltage via power and ground
Now, sometimes, you're driving something with a battery, but sometimes you're driving it without a battery. You just have a power source, maybe from the wall, or some arbitrary power source.
DC power. So, this is all direct current, DC. Just to note this, we're dealing only with direct current. So, to tell you what direct current is, there's direct current versus alternating current. Alternating current is when current goes back and forth. The electrons move back and forth. Like coming out of the wall I believe we got 60 hertz. Yeah, I think its 60 hertz coming out of the wall. Which means 60 cycles a second, so the current goes back and forth 60 times every second. That's alternating current;
alternating current is good for transmission. Meaning it loses less power in long distance transmission. That's why we have alternating current in our houses and things like that because you going to transmit it from wherever the power station is, and it transmits there.
But direct current is what we use in our devices in our houses. So there's always this conversion from AC to DC, to DC, direct current, into our devices.
- Don not create a short circuit
One other note, never create a short circuit. So short circuit, actually specifically a short circuit between power and ground, short circuit is when you accidentally connect two wires together. If you were to short power to ground, so if you took power and ground and wired them together by accident then power, what happens is between those two points, you got, let's say power is five volts. So you've got a five volt difference between ground and power, but their resistance is zero. If you have a conductor, if you've run a wire, you've got effectively no resistance. Now if we were to go back to Ohm's law V equals IR, right so I = V/R. V divided by R.
If R is close to zero then I is infinite or approaching infinity. So what that means is if you short power and ground you get a rush of current and something smokes.
2.2 Lecture 2.2 - Diodes
2.2.1 Diodes and LEDs
So another important component are diodes. We're going to talk about two different types of diodes. Just general diodes, there are several varieties, but we'll just talk about general diodes. Plus LEDs, which LEDs stands for light emitting diode. So that's also a diode, it just emits a light when current flows through it.
- Two terminals: anode and cathode
Now, an LED or any diode at all, has two terminals, an anode and a cathode.
- Current only flows in one direction, anode to cathode
One-way valve So the thing about diodes, the unique think about diodes is that they are semiconductors and current can only flow one direction through a
diode. So it's got to go from the anode to the cathode, it can't flow from the cathode to the anode. Now even that said, it can flow from the cathode to the anode, but only if you drive it with a lot of voltage. At the levels that we're using, current is only going to flow in one direction from the anode to the cathode. So it's like a one way valve in terms of water, right? It goes one way; it doesn't go the other way.
- LEDs light when current flows
So, if it's an LED, a light-emitting diode, then when current flows the light emits, and it gets bright. Otherwise it's dark.
2.2.2 Diodes Threshold Voltage
(1) Forward bias
Now, every diode has what's called a threshold voltage. So, let's take the picture on the left side. The forward bias, the one that's labeled forward bias. So notice that the anode is labeled with a plus sign and the cathode is labeled with a minus sign. So what that's saying is that in order for this diode to be forward biased, meaning a forward bias is when current is flowing through it. The anode has to have positive voltage with respect to the cathode.
- Anode-Cathode voltage must be above threshold
So the anode-cathode voltage must be above a certain threshold. So not only does the anode have to be positive with respect to the cathode, the difference between the voltages at those two ends has to be a threshold. Let's say 1.7 volts, but this is going to depend on the diode. So you'll have this threshold and if the voltage is below that threshold, then current will not flow. But once it gets above that threshold, then current flows and it's very little resistance.
(2) Reverse bias
- Reverse-biased: when anode is negative wrt cathode
On the right we've got reverse bias. Reverse bias, we took the anode and made it negative with respect to the cathode. In reverse biasing, we will get no current flow, typically, until the difference in voltage is so large that it overcomes the reverse bias. So eventually, if you drive enough current, if you push out voltage that if there's enough voltage that's between the cathode and the anode you will get current flow, but not at the levels that we're dealing with. You'd have to have a lot and we're not gonna do that.
So reverse biasing it, for us would be no current flow. Only in forward bias condition when the anode is positive with respect to cathode, and the anode-cathode voltage difference is above the threshold, only then will current flow for us.
2.2.3 Diode Current Limits
- Diode have a maximum current limit
Another thing about, another property of diodes is that they have a current limit. So it's a maximum current, and you should not drive them with more than that current. You can probably push it a little bit, but it will wear down more quickly. And if you drive too much current it'll just blow up and it'll never work again.
- Maybe 20mA
The LEDs in your kit, typical current limit is 20 milliamps. If you drive it with more, you push more than 20 milliamps through it, it will die pretty quickly.
- Do not connect an LED directly across a 5V supply
So, do not connect an LED directly across a five volt supply. So what I mean by that is there's the anode and the cathode. If you take the anode wired directly to five volts, the cathode wired directly to ground, you will have a circuit and current will flow. But a lot of current will flow, because that LED has very little resistance when it's on.
And remember V = I*R, So I = V/ R, and the resistance is low, so I will be very high. So that's the type of situation if you want to figure out the type of resistor that you want to put in there, in series with the diode, you have to figure out what the on resistance of the diode is, which should be in a data sheet. And then you say okay, that plus what size resistance would keep the current less than 20 milliamps? And you can solve for that, using Ohm's Law.
2.3 Lecture 2.3 - Switches, Potentiometers
So we're going to talk about a few more components that you commonly see in circuits that we have in our kits actually, switches and potentiometers.
2.3.1 Switch/Push buttons
Right here we've switches. Push buttons and switches. They're basically serving the same purpose.
(1) Switch
Now, on the left side of the screen, you see a switch. There are many different types of switches. Many different looks, but that's one right there. That's called a rocker switch, but there it is and you can see below it, you can see what its symbol looks like. It's basically just a door on the circuit.
(2) Push button
On the right is a push button, which, you actually should have a push button like that in your kit. Push button serves a similar purpose and its symbol is below. One note I should just bring up right now, the push button that we have there, that actually is very similar to the one you have in your kit. That thing has got four legs on it. It's hard to see. You can only see maybe three of them here, but there are four legs. So it doesn't really just have two terminals. This one has four. But two of the terminals are connected to each other. So the two on the left are connected to each other, and the two on the right are connected to each other. So when you press the button, the two on the left become connected to the two on the right.
(3) Function
- Closing the switch completes the circuit
Now the point of a switch and a push button, both of them, is really to complete a circuit, to close a circuit. So understand that if you've got a battery, let's say, and you got wires coming out of the positive and negative side. If those two wires are not connected, you don't have a circuit. No flow, no current flow. You gotta have a full path from positive to negative. So if you put a switch in between that path, if that switch is open, meaning it is off, right? Then the switch is open and the circuit is not connected. But if you close that switch or if you push that button, which is doing a similar thing, you push that button. Then that connects the two ends of the circuit, and it makes a complete path from positive to negative and you can get flow. So this is how pushbutton and switches are used.
- Voltage on both terminals is identical when switch is closed
Let’s look at this switch on the top left. That switch has got two terminals, right? One left, one right. And when you flick that switch, those two terminals are connected. So when the switch is off, the two terminals are not connected. When it's on, then the terminals are connected. When those two terminals are connected, their voltage is exactly the same.
2.3.2 Potentiometer
- Three terminals: top, bottom, middle
Now this is an interesting component. We've got one, there are many different looks for potentiometers. Now, this potentiometer has three leads in it. And notice it has a knob, hard to see, but it has a little knob that you rotate. All these potentiometers, they have something that you move, either like a rotary potentiometer, like this one, has a knob that you rotate. You can have sliders that go back and forth that do the same thing.
Now, it has a schematic symbol and you see that in the middle there. So it's like basically a resistor, with a little arrow in the middle. That's a potentiometer, that's its schematic symbol. And notice that schematic symbol has three leads also. The resistor has a top lead, a bottom lead, and then there's that arrow, which is a third lead. So the three leads in that potentiometer correspond to those three leads in that schematic symbol.
- Resistance between top and bottom terminals is constant
Now then, over on the right, that circuit that we have there with the two resistors and with the voltage in and the voltage out and all that. That is the circuit that I'm going to use to describe the behavior of a potentiometer. Because a potentiometer acts like that circuit. That's what I'm telling you. That circuit is called a voltage divider. So, remember the potentiometer has three terminals. And that circuit's called a voltage divider. Now if you look at that circuit,
at the top, there's this Vin, And
at the bottom there's ground. So those two, a V in and ground, those are two of the leads on a potentiometer. And then the middle,
that little arrow in the schematic, that is that V outright there. That's what you're actually measuring typically.
So the resistance from the top to the bottom, from one side of the potentiometer to the other, so from V in to ground, that resistance is constant no matter what you've turned the knob.
- Ratio of resistances changes
Now the total resistance from V in to the ground is going to be R1 plus R2, those two resistors add together. That sum is constant. So for instance, if you've got a potentiometer, it is a 10k potentiometer, 10 KΩ potentiometer. Then the sum of those two resistances from one lead to another is always 10 KΩ, but what changes is that V out right there. Because what changes is as you turn that knob, the ratio between those two resistors, R1 and R2, the ratio of their resistance changes. So if you turn the knob one way, R1 gets smaller and R2 gets bigger, even though the sum stays the same. So and you could turn the knob other way and the reverse happens, R2 can get smaller, R1 can get bigger.
- When changing resistance, which changes the voltage
Ohm's law, right? V equals IR. So we want to measure V at V out, that point V out in between those two resistors. That V goes I times R, now I is the same for both resistors, because there is only one wire that everything has gone through but the R changes, right? If you could make R get bigger and smaller, R2 specifically. The R2 is the resistor between V out and the ground, okay? That R is changing as you turn the knob. And since V equals IR, if R is changing and current is constant, then V is changing. So as you turn this knob, you're changing resistance, which changes the voltage that's perceived at V out.