[MUSIC] So next what I want to do is I want to go back and talk about circuits a little bit more. We've been kind of going through all these list of components since there's different types of components we can use in circuits. But how do we actually hook them together? Well, I want to talk about a few example circuits that you can use that can kind of give you some intuition on how to build circuits. So let me run through these a little bit. Now when you're thinking about how to build circuits, you might seem like kind of a daunting task. How do I take all these components and hook them together? Well, if you're familiar with software, you've kind of experience this sort of problem before in the context to algorithms. You need to build some sort of system that kind of traverses a graph. Well, Dijkstra's has been invented to do that. And there's no dynamic programming and all these different algorithms out there. It's kind of a similar sort of thing with circuits. Oftentimes, we won't kind of sit down and build a circuit from scratch. Instead we'll kind of go online or look up a book and kind of figure out a good existing circuit and just kind of apply that. So that's a kind of a good approach to follow. So this isn't really about memorizing a lot of circuits. You don't need to do that to do IoT because you can kind of look up what you need to do and often you can kind of by these circuits prefabricated a lot of the time. That said, this is University of Illinois and we like to kind of give you deep understanding of stuff because we don't just train hobbyist. We kind of train engineers to really go out and build stuff for real and so it's important for intuition for you to kind of understand how circuits work. And so I am going to take you through a few circuits that are widely used and these are good to kind of build intuition. So you kind of know how to apply them and how they kind of work under the hood. And I'm going to do that by telling you about six particular circuits, which are useful to know about. And they're widely used in themselves. And they also kind of demonstrate useful concepts that are useful to know about. I'm going to kind of run through these six circuits now to kind of give you some intuition about them. So the first one is about kind of protecting your design from overload. And this is a kind of a tricky issue that really comes up a lot. If you take a battery or you take a voltage source and just kind of naively wire the positive to the negative end, you get what's called a short circuit. You get current flow that's unbounded, the electricity kind of goes faster and faster. It can overload that wire if too many amps go through a wire that's beyond its back it'll melt. It could cause a fire. So you don't want to do that. So a lot of circuit design is about printing too much current from going through your circuits. So there's different components in your system. And you might think if you kind of put a component in a circuit, it'll cause resistance which kind of reduces the current. And that's true, but the thing is some components don't have resistance or they don't have much resistance. Or they might have good resistance over kind of a certain range of voltages. But if you kind of apply too much voltage, they suddenly don't have resistance anywhere. And one great example of this is light emitting diodes. So LEDs have nonlinear resistance where you kind of apply voltage and you kind of apply a little bit more voltage and you got good resistance. You don't have a short circuit, but kind of once you hit a certain amount of voltage called the forward voltage limit. If you kind of go beyond that, suddenly resistance just kind of disappears and kind of like you can have lots of current go through. So if you have a circuit where you have a voltage source in LED, and then your voltage is too high, you'll get a short circuit. And so the solution of this is honestly pretty simple. What you do is you just take a resistor and you put it in series with the LED because resistors do have linear resistance. You can apply more voltage and more voltage and more voltage and they'll kind of stay there and keep resisting the whole time. I mean, at some point they'll get overloaded, but over a wide range of voltages they have linear resistance. And so you'll kind of put them in series of your design. So when you kind of think about your design, you're going to have a circuit or you might have a series of circuits. We kind of have like some sort of component network of kind of electricity coming out of your current source going through a bunch of different components in the kind of coming back. You want to make sure there's resistance on each of these paths. If there's not then you can get short-circuits and you want to protect against that. So that's kind of the idea behind this first kind of useful circuit are useful technique to know is kind of make sure there's resistance on each part of your circuit. And you can apply resistors to do that. Okay, so a second thing I want to talk about is protecting against noise in circuits. And when I talk about noise, I don't mean audio noise. It turns out you can have electrical noise when yoy design circuits where you can kind of have voltage that comes in. But oftentimes your voltage level is not perfectly flat. It kind of spikes up and down, you got a noisy motor in your circuit. That's kind of pulling voltage up and down or other sorts of noise. And that's bad for your components because components can kind of wear out or they can kind of malfunction when they don't have a nice smooth voltage source and so on. So can you design circuits that kind of protect against spikes or kind of smooth out this variation in electrical noise. And the answer is yes. And so what you'll see in a lot of circuits is people use capacitors to do this where they'll kind of take a capacitor and they'll connect it between the positive and negative terminals in your circuit. And capacitors don't have current that go through them. I mean, they have a little bit that can kind of look through, but so there's isolation between your positive and negative terminals. But what happens is if there's a voltage spike that goes into the capacitor, that charges the capacitor, and then it'll leak it out over time. So one thing you could do that kind of makes your circuits get some nice clean voltage coming in is to apply a capacitor between your positive and negative terminals like this. And oftentimes it doesn't really matter a huge amount what size of capacitor you use. If you don't really know what you're doing, you can choose something that's 1 microfarads or 10 microfarads. That's the unit they use to measure capacitance. If you're kind of just using low voltage logic. If you're doing something with kind of more voltage or more power, you can use a bigger one. But this is kind of another trick that you can use to get good clean electrical signals to your circuits. Okay, so another thing you have to be careful about is measuring inputs from a part of your circuit that's disconnected. So here I have a circuit where I have a little voltage source here, voltage is kind of coming in here and have a switch and then I have something here like maybe a logic gate or something and then voltage that comes out here. So if that switch is closed then voltage will come in and it will go through the switch and it'll go out the logic gate and then we'll measure it here. And so that's fine. But what happens if that switch is open? Well, you might think well, okay, so no voltage is going through so I measure a zero voltage. But it turns out that's not really true. The current would be zero, but voltage is about kind of the strength of the electrons sort of. So at that one point you're measuring whatever electrons just happened to be at the tip of that wire. They've kind of transferred off the air or the last person to touch it with a finger or something. So the problem is if you have a pin that's disconnected or line that's not connected to your ground or your voltage source is voltage is actually non-deterministic. And if you measure the voltage there can be anything. And so this will mess up your logic. So what you want to do is you want to make sure that every line in your circuit is tied to either the ground or the voltage source in some way. It can go through components, but you don't want to leave any parts of it disconnected because that makes your circuit non-deterministic. It'll behave in random ways. And so the solution is to use something called a pulldown resistor where you attach the line that gets disconnected to ground. So you can see in this figure on the right I have the voltage source. And the voltage source is connected through the switch, the voltage will kind of go through and then go out. But if it gets disconnected, then the line is tied to ground. So any kind of stray voltage on that wire will be sucked to the ground through the resistor. This is called a pull-down resistor because it pulls down the line to ground. If I can inverted the switch and put the switch down where ground is and put the resistor up and connect it to a positive source, then it would be called a pull-up resistor. So you can do that too. If you have a line that you want to default to high, then you can have a pull-up resistor that connects it to a voltage source. And the reason you use a resistor there is you don't want to short-circuit because you don't want to just connect. If the switch is on you don't want to connect the voltage source to ground. So the next thing I want to talk about is kind of getting the voltage level you want because maybe you're using a battery or something that's 1.5 volts or maybe you're plugging into a wall and you're getting 120 volts. Oftentimes the voltage that you have to work with isn't the voltage that you want because your components want a different voltage. So there's circuits that can help you change voltage from one level to another. One kind of circuit that useful here is called a voltage divider. And the way a voltage divider works is you kind of put a resistor in series with your voltage source. And resistors decrease the current, but they also decrease the voltage. So if I want a particular voltage level, I can vary the resistance. Another thing that you can use this for is for reading the values of sensors because what sensors do is they often work by changing the resistance of a particular component like a like photo resistors, for example. Photo resistors are resistors that change the resistance based on light. And it's kind of hard to read resistance. I mean, resistance isn't really a property of electricity. But since resistance affects voltage, we can design circuits that read voltage and we can use that to read the value of sensors. So if you're going to use a photo resistor in a circuit, you do something like this the circuit here. We read wire it in parallel with a voltage source and ground and then measure voltage before it goes in the photo sensor because that voltage will vary based on how much light is in the environment. And there's other examples of this. This is a circuit for a level shifter, which is another way to kind of change voltage levels. So these are some techniques that you can use to alter the voltage in your circuit. And you can kind of tune them to get the voltage you want. Another problem that comes up a lot is amplifying signals. Maybe you have some sort of data coming in on a line. Maybe it's analog data. Maybe you're measuring sound coming out of a microphone or maybe you're detecting network information data coming over a network. If you want to make it louder because it's kind of going through a noisy environment. You can't really hear it. Well, there's circuits that can amplify signals. And one component that's really useful here is called an operational amplifier or an op-amp. It's denoted by these little triangles. And you often don't use an op-amp directly, but you kind of build a little circuit surround the op-amp. And so what you can do is you can change the behavior of the op-amp based on how you hook it up to different resistors. So suppose you want to build a circuit that kind of takes your data coming in and amplifies it. That would be a non-inverting op-amp, the second one I've shown here. You have data coming in goes into an op-amp and you have some kind of resistors there. The value of the resistors determine how much your signal gets amplified. Maybe you want your data coming in and you want to invert the signal coming out that would be an inverting op-amp, the first circuit I showed here. You can also do things like kind of detect the difference between two different lines, you'd use a differential op-amp for that. Or maybe you want to kind of have a set of lines in it, some of their values together and amplify that, there would be a summing op-amp. In the equations beneath each of these show how you can vary the values of the resistors in the circuits to change how much the signal gets amplified. So what you can do if you want to amplify a signal you can think about how you want it to be amplified. What you want to be amplified and then you can simply build one of these circuits to amplify your signal. And this amplification problem comes up all over the place, and amplify audio or outputs of sensors or radios or things like that. Okay, so the next thing I want to tell you about are these things called transistors in relays. So these are little devices that connect like switches. In your house you might have light switches to turn on and off light. We often use switches inside a circuits too. And oftentimes we don't want these switches controlled by people. We want them controlled by other parts of your circuit. That's what a transistor is. And that's what a relay is. These are little devices that have three inputs. There's a voltage source and a voltage output and then there's a third line which acts as a switch. If voltage is applied to that third line, then it makes a connection between the two other lines. Otherwise, there is in the connection. And transistors and relays are different in some ways. Relays are kind of like really powerful resistors. They're designed for use with really high voltages, high amounts of current usually. So if you're doing something with high amounts of voltage or current user relay. Whereas if you're using small amounts of current or voltage user transistor. And here's some example uses of transistors. One example where they're used a lot is in terms of logic. Maybe you're building a burglar alarm and you want it to go off if the burglar alarm system is on in the first place. And in also if the burglar trips a trip wire. So if two things happen, then you want an alarm to go off a third thing to happen. So transistors are great for that because you can build end gates out of them. You can build logical ORS and Nots and all sorts of kind of different logic out of these gates. You can do that with relays as well. And you can also use it to control larger voltage that shown on the right here where I have a motor and is controlled by kind of a very weak current that's the logic of the system kind of 5 volts coming in. But I want that little 5 volt source to control this much bigger voltage source, and so you can use a relay for that. Where you can kind of have a certain amount of voltage come in and then have a much larger voltage go through the switch. So if you ever have kind of like an environment where you need to switch something on and off in a circuit, you can use these these sorts of circuits. You can use transistors and relays to do that sort of thing. So, okay. So I've kind of given a bunch of different examples of circuits that we can use. Hopefully these kind of give you some intuition about how you can kind of plug components together. And you should feel free to go farther with this. You can look up circuits online. If you ever need to solve some sort of problem, you can do a Google search and there's also big repositories of circuits online that you can kind of download and look through. The next thing I want to talk about is this concept of kind of how we do circuits in practice. Now when we kind of build circuits, for a hobbyist, we're just kind of messing around. We kind of sit down and kind of solder pieces together, put them on a breadboard kind of hook things together. And that's great, but there's limits to how small you can build these circuits because using these resistors and capacitors the kind of big and it cost money. So these are called discrete circuits. But there was a discovery that happened back in the 60s where we found out that we can actually draw circuits. If we can have this material, we can kind of like add circuits into them in really tiny ways in this massively decrease the cost of creating circuits. because we can print them in mass and we can make them really small and tight so we can make them very cheap and we can draw them out very quickly. We can fabricate very quickly. So this was a very powerful invention. And this invention was called integrated circuit because we're kind of taking the circuit. So we're kind of integrating them together in kind of like a small area using a single technology. Integrated circuits are great because we can kind of print circuits out really fast. But the thing is there's a really high initial cost to using integrated circuits. If I come up with a design for an integrated circuit, I have to create a photo mask,, and I have to kind of create a fabrication process around it. And that's really expensive, that can cost like a million dollars for kind of taping that out. And so after I do that, I can print them in mass. I can create them a really high volumes for low cost per print. But because there's such a high initial cost, you only do integrated circuits for things where you have very high production volumes. So if I'm going to create an end gate, there's a huge market for end gates. So there's a lot of integrated circuits for end gates. But if I have a very specific use or something that's kind of niche, I wouldn't use integrated circuits for that. So how do you integrate a circuits work? Well, there's a certain technology behind integrated circuits that make them practical. And this technology is called semiconductors. So we talked about conductors. Conductors are materials where you can kind of they allow electricity to flow through them readily whereas insulators have extremely high resistance. They don't like electricity going through them. A semiconductor is an insulator, but it's not a very good insulator is something where you can kind of mess with it a little bit and make it a conductor. And so in particular we could take a semiconductor and we can dope it. We can kind of shoot certain other kinds of atoms into it to write little wires into it, to make little strips of conducting material on on it. And so we can do this with extremely high precision. We have technology for doing that. So we can edge little tiny, tiny wires and tiny components on them. And semiconductors are amazing because you can build wires on them, but you can also build so many other things on them as well. Strangely enough you can build LEDs on them. You can draw a little light emitting points on these semiconductors. And you can you can draw sensors on them too. You can draw things that kind of change the resistivity with temperature and light exposure to gas. A lot of sensors are made of semiconductors as well. And luckily enough they have high thermal conductivity. So if they get hot, they are good at dissipating heat. It's really great luck that semiconductors exist and have all these nice properties. So what is a semiconductor? I'm going to talk about that a little bit. To understand how they work, you first have to understand that there are these things called atoms that we talked about. And I'm going to tell you a little bit about some of the properties of atoms and how they work because that helps you understand how semiconductors work. So first of all, there's different kinds of atoms. And these atoms differ in terms of how many protons they have. And when we kind of talked about atoms we list them out. And one kind of list we draw a lot is this periodic table sorted by how many protons these different kinds of atoms have. So hydrogen is a kind of atom that has one protons that's listed first in the upper left. And then helium has two protons in the upper right and so on. So we kind of list them out like this because it turns out that the number of protons in these atoms has a lot of effect on how these atoms work and how they interact with other atoms. So let's talk about this. In particular let's kind of pick a subset of these atoms to kind of talk about. So let's talk about silicon, for example. Silicon has the atomic number 14. So it has 14 protons. And it turns out the number of protons you have in the atom that you kind of want the same number of electrons to be there as well. So silicon has 14 protons. It also likes to have 14 electrons. So these 14 electrons kind of you can think of them as kind of spinning around in orbits. The thing is electrons aren't typically thought of as being on the sea orbit. Electrons kind of can be in different orbits where the inner orbits are really bound to the nucleus, but the outermost orbit are the valence electrons. Those are the ones that kind of like hopping around between different atoms. So when I draw silicon, the outermost electrons are the ones that really matter because those are the ones that interact with other atoms. So I'm going to draw silicon and kind of a simpler way. I'm going to draw it like this where there's a nucleus and there's some kind of inner electrons spinning around. But in its outermost shell, there's four electrons. So when we talk about material, if I have a piece of matter like a piece of steel or a big piece of silicon or something like that, what I have is I have a whole bunch of atoms that are sticking together. And when atoms stick together, their nuclei don't touch. But what happens is they kind of share electrons and that allows these atoms to kind of form bonds between each other. So if we talk about silicon, then if I have a material what I'll have is I'll have more than one silicon atom. I can take two silicon atoms and push them together and they'll stick together because silicon has four electrons in its outermost shell. But it wants to have more. It would actually enjoy having eight electrons in its outermost shell. So its outermost shell is not full of electrons. So silicon atoms like to stick together because they like sharing their electrons that kind of formed them together. So if I have a material formed out of silicon atoms, it's going to kind of be a set of them kind of hooked up together like this where they actually have eight electrons in their outermost shell is just four of them are kind of shared with their neighbors. So it turns out silicon is a semiconductor. And if I just have a plain semiconductor that's actually an insulator. Because if I have some electrons and I could try and push them into this material of silicon atoms. I try and push those electrons in, they don't want to go in because the Silicon atoms are happy. They have a whole bunch of electrons outside them anyway. They don't want more electrons coming in. So I can't make electricity flow across in just a regular semiconductor like this. Now, let's look back at the periodic table a little bit. I had silicon there, but let's look at some of these other atoms. Boron, it turns out has only three electrons in its outermost shell, not four. Silicon has four. And there's also a phosphorus which has five electrons in its outermost shell. So this introduces an interesting question. What if I kind of take the semiconductor and kind of dope it? I kind of shoot some boron atoms at it and kind of get some boron mixed in here. Well, if I take my semiconductor and I dope part of it with boron and then I shoot electrons through, something very different happens. Because I don't just have these shells completely full now, there's some little holes in there which will happily accept new electrons. So these electrons will jump between these holes. And so now I can get current that kind of flows across the surface of this material. That's what happens when you kind of dope it with boron. I I dope it with phosphorus, something different happens. With phosphorus now I have too many electrons in there and they want to get out. So what will happen is these electrons will still flow across the material because phosphorus likes to have more electrons. So phosphorus will kind of suck more in, but then they'll kind of be pushed out because there's too many in the outermost shell. So the Silicon atoms will kind of push him out. So this is how electron flow works with phosphorus. There are two very different ways to dope. One creates electron holes and one creates too many electrons. But they both allow current to flow across what was formerly an insulator. And so now what I've done is I've given you a way to print components on these materials because what I can do is I can take them and I can dope them in different ways. If I take them, if I dip them with boron, that's called p-type doping. I'm doping them in ways that kind of create these little electron holes. If I dope them with something like phosphorus that creates too many electrons, that's called n-type doping. So it's kind of different ways to dope. And this is the really weird thing. But if you kind of take a material and you dope it in two different ways and you kind of make those ways touch, then the boundary between those parts of your material has some really weird effects. Like the first figure over here, what I've done is I've created a diode where I have a little piece of material where I did with p-type silicon in a little type part over here where I dope it with n-type silicon. And then I connect it to a anode and a cathode, so input and output to kind of make electricity go through. And it's kind of weird but the interface between those two kinds of doping only allows electrons to go in one direction. So I can actually draw diodes by doing this. Similarly, I can create transistors as well where I can kind of n-type dope a piece, n-type dope another piece and then put a p-type doping in-between. And then connect positive and negative terminals to the two n-type parts and then have a controlling wire in between where five electricity flow into that p-type silicon. Suddenly that makes a connection it allows electricity to go through between the collector and the emitter pins. And so on I can make capacitors and I can make resistors. And in general I can draw a lot of electrical components just by taking the semiconductor and kind of doping it and kind of doing these different things. The next question is how you actually do the doping process, which I'm going to show you just so you know how it's done. It's done through a process of lithography where you can kind of draw my design onto a photo mask and then apply it to the silicon wafer. And there's kind of a chemical process that's used to do that. And it has a series of steps. And the way it works is I first get a piece of silicon very, very pure piece of silicon. And I melt it down and I kind of extract an Ingot from it, slice it up into little tiny thin pieces, and I take that piece your kind of lay it flat. And then what I do is I dope it. So I do p-type doping to that silicon and then I treat it and I put a layer of silicon dioxide on top of it. And then I apply a photoresistor to it. So a photoresist is something that kind of resist light, but can be kind of etched away by light. And so then what I'll do is I'll take my photo mask, which I created before which actually has my design take down inside of it. And then I'll play ultraviolet light. And what that does is that eats away the photoresist in certain locations. And then what I can do is I can apply an acid or some sort of substance that eats away the silicon dioxide in the exposed areas. And then now what I have is I have a material where the p-type silicon is exposed in certain places and not in other places. And so then what I can do is I can wash away the photoresist and then apply my ion beam. I can shine the phosphorus at it, shoot lots of little phosphorus atoms at there. And this will dope the Silicon in the exposed areas to be n-type doped. And then what I can do is I can [COUGH] do the same process again expose other places and I can do p-type doping. And then I can kind of keep doing that process and then when I'm done I can draw the wires on top. So I can apply the metal oxide layer on top. And so what I've done here in this particular example is I've drawn a single transistor. And this particular process of drawing the transistor, this particular design is called CMOS, which is one way to design circuits using these technologies. Okay, so this is kind of how semiconductors work. So I have kind of shown you how you can kind of take these different components and draw them in silicon using kind of the chemical process technique. And this is done by large fabrication facilities all over the place. So when you buy something you kind of know what the process is going on under the hood to build these technologies.