 Okay, we're going to be using the Raspberry Pi for some home automation. But the first thing we need to do is learn how to use the GPIO pins. And the simplest thing to do is to make an LED turn on and off. So I've got myself a little red LED here. I've got a breadboard to work things out on. And then I've got my Raspberry Pi here. So first thing I'm going to do is I'm going to take my LED and I'm going to take the long lead and I'm going to connect that to a GPIO pin. So I'm going to put this in the board here and I'm going to, and I'm assuming that you already have the basics idea of how a breadboard works, but the rows this way connect. And then the edge rows are usually for power that way. We're not going to be using those. We're going to go be directly from the board here. I'm going to go to the one, two, three, fourth pin down along the inside here, which is GPIO pin four, not because it's the fourth pin down, we'll get a chart in a moment. And again, I'm going to connect that to this longer lead here. So with this in the breadboard and I'm going to connect this to the longer lead there. Now I'm going to take another cable and actually before that we're going to have to put a resistor in here. You want to put a resistor to lower the power going back to the board. You don't want to damage the LED or the board by putting too much power through it. They recommend using a 270 ohm resistor. I don't have one of those right in front of me. I'm using a 470 ohm resistor. So my LED is not going to be as bright as it would be if I was using a lower ohm resistor, but we'll still get the LED to come on and off. So I'm going to connect that there. This is not directional sensitive, so it doesn't matter which lead goes where as long as we're connecting it to the shorter lead of the LED there. Oops. Next, I'm going to take my Raspberry Pi here and I'm going to go to the next pin down from where I just am and that's a ground pin. There's a couple of ground pins. Again, we'll look at a chart in a moment and I will connect that to here. So now when we turn on GPIO pin 4, which is this blue wire here, it's going to send power to our LED. It's going to come through the LED, turn the LED on, then the resistor is going to lower the amperage and the voltage that's going through here and then it's going back to a ground on the board. So as we turn this pin 4 on and off, we will be getting the LED to turn on and off. So let me jump over to my computer here and start recording here. Okay. Oh, it probably also be good if I plug power into the Raspberry Pi. So let's go ahead and do that. So plug in there. Give it a moment to boot. I am running a version of Raspbian on here but it doesn't really matter what we're doing today. Pretty much everything should be the same on most other distros as well. Let's go ahead and look at this chart here real quick while we're waiting for the Raspberry Pi to boot. So again, we connected what's labeled as pin 7 here, which is GPIO 4. So don't get confused that it's pin 7 but it's GPIO 4. We connected that to our LED and then through our resistor and then back to pin 9 here, which is ground. You can also go to the ground up here or there's another ground here. There's a few grounds. Don't think it matters which one you use. So basically we're going to turn this GPIO 4 on and it should light up the LED. So going back here, I'm going to SSH into the Raspberry Pi and we need to do one or two things before we start turning the LED on and off. There's nothing you need to install. We're doing this with a shell script so you don't need any Python modules. What we're going to say is echo 4, this is saying that we want to use GPIO pin 4. So we're going to put that into a file. So where it's going to be system, class, GPIO, export. So we do that and it says device busy, which means I've probably already done this. So let's move on to the next step. You probably won't get that. If you get that, I wouldn't worry too much about that. It should still work. We're going to say echo out. So now we're saying that we want this pin to be an output instead of an input. The GPIO pins can send signals and receive signals. We want this to send a signal so it's going to be an output and again that's going to be under system, class, GPIO, GPIO pin 4 and we're going to say direction. So we're saying look at the GPIOs, look at GPIO pin 4 and set its direction to out. So let me real quick here, turn my lighting off so you can see the LED a little bit better with the power plug that we did in the previous tutorials. So we've enabled GPIO pin 4 which it said was busy probably because I've already had it enabled. And next we're going to say that we're setting it as an output. Now we can just turn it on and off and we do that by writing to the hardware as if it was a file because in Unix and Unix like systems such as Linux everything is a file whether it's hardware or software. So 0 is off, 1 is on, we're going to say echo 1 and we're going to redirect that into a file called system class GPIO, GPIO 4 because that's the pin we want to do and we're going to set its value which is currently 0 because it's off, we're going to set it to 1. So if I hit enter you can see the LED comes up, hopefully you can see that in the camera fairly well. If I want to turn it off I can do the same thing, I can say but I'll say 0. So 1 is on, 0 is off, so on, off and we can put this into a loop. I can say while 1, so basically while true loop forever basically turn it on then I can say sleep 4.5 seconds, so sleep for a half a second and then I'll say turn it off and then I'll say sleep for another half a second and I'll say done to loop that. So now we should actually say while do. So we're saying we're going to do a while loop, we're going to loop as long as everything is true which everything is always going to be true and so it's going to loop until we kill it. What are we going to do? We're going to turn the LED on, we're going to wait a half a second, we're going to turn the LED off then we're going to wait a half a second and we're going to start all over again. So I'll hit enter here and our LED is now flashing and that is how simple it is to turn an LED on and off. Once you enable it and set it as an output you either tell it to 1 on or 0 off and of course you can put these into functions to shorten up or even scripts and this is what we're going to use to turn everything on and off. So again I can put that in the loop. So we can use this to turn low power things on and off like this. We can also use it to connect to a relay which will allow us to turn higher voltage, higher powered devices on and off. So what we learned today we can turn anything that has an on off switch or can be powered on and off or can be toggled on and off by a button press. It can pretty much do with what we just learned today and that's what we're going to be doing in the next couple of weeks. We're going to be unlocking car doors, we're going to be opening garage doors, we're going to be turning lights on and off, we're going to be controlling our air conditioner in our house in place of a thermostat all with a Raspberry Pi, all using pretty much exactly what we saw today with the Raspberry Pi and a relay switch. So I hope that you're looking forward to this, I don't think I can make it much simpler than this, be sure to check out the links in the description of this video for notes and as always I hope that you have a great day, I hope you visit my website FilmsByChris.com, that's Chris the K, as always there's links to that in the description as well and again I hope that you have a great day. Okay this is an introduction to FilmsByChris.com, I'm Chris, that's Chris the K, that's me right there, my daughter Ember and my wife Jennifer, we pretty much live in the swamps of Florida. I'm a firefighter by day as well as by night we work long hours but that's not why you're here, you're here about the videos I put up on YouTube. These videos are mainly about computers and programming which means most of my videos look something like this and if that's what you're interested in, great. If not, that's alright, I do videos on other topics too such as video editing, special effects, photo editing, 3D design and music creation. If you are one of my viewers and you enjoy my videos, my Patreon page is a place where you can go to help support my videos. So I ask that you take the time to go to my Patreon page and look at different levels of rewards you can receive for different levels of backing. There should be a link in the description of this video if you were watching it on YouTube, otherwise you can visit patreon.com forward slash metalx1000 and I thank you for your time and your support. Have a great day.