We're going to take a look at using digital and analogue pins for reading inputs and controlling outputs, but first we need to create a circuit using a breadboard, an LED, a resistor, a button and some jumper wires. If this is your first time building a circuit, don't worry at all, we'll take a look at everything that's going on here, what these things are and how you can use them.
A breadboard is a very simple yet useful piece of gear. Its name originates from times when circuit prototypes would be made using a wooden board, typically, yes, used for cutting bread, with nails or tacks hammered in to solder to. This method has evolved into what we've seen today which is far more sophisticated in the form of the solderless breadboard. You can see I've got one on this Sparkfun Inventors kit, it comes with a nice plastic base, it's a half-size breadboard and has the Arduino right next to it so you can easily get prototyping.
A typical breadboard consists of a 0.1 inch space grid of holes in which you can place component leads which are 0.1 inch or 2.54mm. This is the most common format for through-hole components. Inside each hole is a spring-loaded metal contact which grabs the wire or lead. Strips of these holes are connected together to allow components to be connected. Almost every breadboard will have numbered rows of 5 holes which are connected together and every row is electrically isolated. Also, many of them have power rail strips where all of the holes in the rail are connected together which makes it really easy to power your circuit because you can break out that single 5V pin or the handful of ground pins that are found on an Arduino board.
So let's take a bit more of a look at how they work. So, a typical breadboard, a nice almost rectangular shape, will have a series of rows and each of these rows has 5 holes in them and they are all connected that way. So you can see on the breadboard here or in the image on the text area that there's 5 rows and they're all connected to each other. So if I put a leg of a component here, use the red one, leg of a component there, it's going to be connected if I put a leg of a component there, they're going to be connected because there is an electrical connection running through those holes. But this row is completely isolated from that row, they're not connecting at all. So if you wanted to connect these 2 rows together, you would first need to get a small jumper or a piece of wire or something like that and connect 2 of the holes together.
Now, another handy thing about breadboards, most full half mini sized ones are going to have a divider down the middle and this is usually 0.2 inches or 2 standard pitch units across and then on the other side you'll also find rows with 5 holes in them. And these are really handy for when you're using integrated circuits, op amps, timers, things like that because they perfectly straddle that centre divider and go into the first lot of holes there and you can put a pin there, pin there, pin there, pin there, say for a dip 8 package and every leg is now isolated from each other, really, really handy.
Now, another feature that most breadboards will have which is super, super useful is power rails and you'll see these running down the side here. Well, you'll see the grid, the dots. And again, these are spaced out into 5 sets of 0.1 inch pins or 2.54 millimetres as well that go, there's holes here as well and then there'll be a break and then another set of 5 holes and the beauty of this is that these are connected that way which means you can, as we were talking about before, you can take a 5 volt wire from your Arduino say, plug it into one of the holes here, they're usually coloured red and blue or red and black, something like that. So, you can take a wire, plug it in there, and suddenly every hole on that strip will have access to 5 volts. So, you can take a jumper wire from there over onto your circuit, and that's going to have 5 volts on it as well. Very handy. Likewise, the black line allows you to connect ground. There's also going to be one on this side, and these are again isolated from each other, so they're not connected. That's not supposed to run through that hole, nor that. So, you could have one voltage here and another voltage there. You might want to have a common ground, so you would run a jumper wire. Let's try black to make it all consistent over to there so that your grounds are the same, so you can connect both sides to ground. But you might have 5 volts here and then take the 3.3 volt tap from your Arduino board perhaps, if you have components that run on 3.3 volts. Really, really cool.
Be warned, something that tricks people every time. A half-size breadboard like this, the power rail is connected all the way down. However, a full-size breadboard, which is roughly double the length of that, will have a slightly larger break in the power rails in the middle. Now, this is where people get stuck. That is isolated. So, these run of holes and these run of holes are isolated from each other. You can use a small jumper wire. I think it's 0.2 inches or two spacings in that divide. However, you're going to have to jump that if you want power to run all the way down. Now, that's only on the bigger full-size breadboards, but just something to keep in mind.
Now that you know how a breadboard works, let's use it to build the first circuit of the workshop. Exciting stuff. We're going to be connecting an LED and a push button together, which we'll be using to go to the Arduino board for the digital read and digital write functions. In the next section, we'll be putting these into practice, but for now, let's get it working. So, we're going to draw up a schematic.
Now, a schematic is a fancy word for an electrical circuit in symbols. It's not a physical layout of how the circuit will look when it's on a printed circuit board, but it's designed to really clearly and easily show what is connected to where and how the circuit works. So, if you look at a circuit board like the Arduino, it's very confusing and hard to see where everything is going. It's doable, but only if you have a lot of time and patience. A schematic will really clearly outline everything.
So, we're going to take a look at our first circuit. Now, there's a few symbols that we're going to be using here. A resistor, and that is the schematic symbol for a resistor. Some jagged lines or squiggly lines. We're going to be using an LED. Now, an LED has the same schematic symbol as a diode for line there. However, it has two small arrows going outwards to indicate that it is illuminating light. And a button. Now, there's lots of different schematic symbols for a button, but generally we'll treat it as a standard switch, which has two contacts, usually shown open so that you can tell that it's a switch and just not another piece of wire. And then we're going to use lines to connect them all up to each other.
So, let's take a look. Move over to this side here. So, the first thing we need is our two Arduino pins. Let's do these in red. Now, this is going to be connected to pin 2 and pin 3 for our LED. So, I'm using pin 3 instead. Now, pin 3 is our LED. And the first thing we need is a current limiting resistor. Now, if you're not sure what an LED is, what a resistor is, what a button is, don't worry. I've included some links in the workshop written content to some more articles on all about LEDs, all about electronic components, and analog electronics crash course, so that you can get an understanding of how these things work.
But a current limiting resistor, simply put, is there to stop the LED drawing too much current and to give it the correct voltage. So, we have our current limiting resistor, then our LED, poorly drawn LED at that, and then that's going to go to ground. Now, ground is an example of 5 volts, as we were talking about before. When we say 0 volts, it's usually referred to as ground. Ground is the reference voltage where everything connects to. And that symbol there, the three lines, or it's also drawn as an upside down triangle or an arrow, is usually called ground.
So, if we draw another bit of circuit over here, it also has the ground symbol. It means that those two are electrically connected, usually on a ground plane on the PCB, or a really thick trace. So, that is our LED. We've got our current limiting resistor. We have the positive side of the LED, or the more positive side, which connects to a higher voltage. And the lower side of the LED, which connects to ground. Now, for our button, we're simply going to take this guy and connect it to ground as well. So, those two would be electrically connected. And that's all there is to the schematic that we're going to be using.
So, now let's take a look at putting it together on our breadboard. Alrighty, so now that we have an understanding of how the circuit works and how everything connects up, let's actually put that into practice on our breadboard and get everything connected up, so that we can move on to using digital inputs and outputs. So, there's an image of the wiring diagram and how you can connect everything up in the resources section of the workshop. And again, as mentioned before, I'm going to be using a Spark Fun Inventors kit, and every circuit in this workshop can be followed and built using one of these kits.
So, first up, I've got my Arduino Uno with a breadboard on the plate here. Again, you can use a different Arduino board or get that spaced nicely. You can use a different Arduino board, a different size breadboard. You don't have to use this particular one. The Spark Fun Inventors kit is a great place to get started. So, let's use a red LED, I think. Red is a good colour. So, we have our LED. Now, I'll position the breadboard like this, so you can see how I'm following the wiring diagram.
So, first up, you'll notice that the LED has two legs, one that is longer and one that is shorter than the other. And this is because one side of the LED has to be more positive than the other in order to allow current to flow. It's a polarised component. And an LED, or a diode in general, is a bit like an electronic valve. It only allows electrons to flow in one direction. But the LED allows current to flow, allows the electricity to move from one side to the other, and in the process, it will light up. Again, check out the linked tutorials for more information on this. But we're going to take the longer leg, or you can identify the negative leg. On the epoxy case, you can see one flattened side, one side that's a little flatter than the other. That is the negative side. So, I'm going to put this into the breadboard here. I'm going to use these two rows that are adjacent to each other. Make sure it's pushed down nice and securely, so it makes a good connection with the contacts.
Now, the next thing we need is a current-limiting resistor. Now, you can work out the value of these current-limiting resistors. There's only some simple maths and using Ohm's law. Again, LED's tutorials do that. But a really good safe value, especially when driving it from a microcontroller, is going to be 330 Ohms. There's a bag of them in the Spark Fun Inventors kit. And this is to stop our LED drawing too much current and burning out. So, let's fold the legs up on these. Guys, we're going to take that from our positive pin, our LED, over to there. And I'm going to grab out some jumper wires. So, jumper wires are just wires. They're just bits of wire with contacts on the end that are designed to plug in really well to 0.1 inch or 2.54 millimetres, again, to those sized connections on breadboards or on header pins, things like that.
Take your jumper wires. I'm going to use red ones for wiring up power and then darker colours for wiring up ground. And we'll look at some signals later. So, from the leg of the resistor, remember that that's connecting to our Arduino. Let's plug that into pin three.
Now, I'm going to take a blue wire, plug that into the negative leg of our LED, and connect that up to this negative power rail here. So, take a push button. These are nice. They've got a really good plastic cap on the top. So, they're easy to push with your fingers. Take a green one, for example, and I'm going to use that to straddle that centre divide.
Now, with the push button, you'll note that there's two sets of connections on it. You only need to connect up one of these. So, it can be really stable if it's mounted in a breadboard. So, we just need one side and the side that has both legs on it makes the switch. So, we need to short these together when we're pressing it, and then they'll be isolated when we're not pressing it. Press that in nice and firmly into our breadboard. Check that it's going in properly. Yep, fantastic.
Now, we need a jump wire. We're going to be connecting one leg of our button to ground, onto zero volts, and the other leg, we'll use a yellow wire. It doesn't matter what colour you use, it just helps you keep track of things. We're going to use a yellow wire to take that to digital pin two. Fantastic.
So, now we just need to connect the ground of our Arduino board up to the ground rail here of our breadboard. Alright, so now everything's connected up. It looks a little messy. There's jumper wires going everywhere, but if you look back to the schematic circuit that we drew before, you can see how everything connects up, and I'll put that in the section resources as well.
So, there you go, everything's connected up on the breadboard, and we have our circuit ready to go for using some digital inputs and outputs. If you have any questions on this, or you can't get your breadboard working, remember that we're here to help. So, post a picture of your breadboard, some information about the problem, post it in the comments there, and we'll get right onto it and help you get started with your first circuit.
Makers love reviews as much as you do, please follow this link to review the products you have purchased.