Arduino Bootcamp : Building Intermediate Projects | Lee Assam | Skillshare

Arduino Bootcamp : Building Intermediate Projects

Lee Assam, University Instructor, Software Developer

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
11 Lessons (2h 39m)
    • 1. Class Introduction

    • 2. Buzzer Sound Recall Game Project - Part 1

    • 3. Buzzer Sound Recall Game Project - Part 2

    • 4. Ultrasonic Sensor Alarm Project

    • 5. Digital Dice Project - Part 1

    • 6. Digital Dice Project - Part 2

    • 7. How Infrared Works with Arduino

    • 8. Infrared Repeater Project with Arduino

    • 9. How a Joystick works with Arduino

    • 10. Configuring an LED Matrix with a Joystick in Arduino

    • 11. Joystick Matrix LED Game Project


About This Class


This is a hands-on, projects-based approach to learning the Arduino platform catered to all levels of experience. In this class, you will build projects such as:

  • An Arduino car that can be remotely driven using a smart phone app

  • Your very own Arduino phone that you can make/receive phone calls with and send/receive text messages

  • Your own Universal Arduino Remote that can copy and playback IR signals from any electronic device

  • An Arduino Online Weather Station that connects to the internet to retrieve and display weather information based on your location

  • Arduino game projects using light, sound and joysticks 

  • Much much more...

No previous programming or electronics knowledge is required for this course! All electronics concepts and programming for each project will be explained step-by-step in detail.

You will quickly learn and become proficient with Arduino in this bootcamp by building complete projects from scratch. Here is the approach that is taken for each project:

  • A detailed background of all the electronics principles and operation of the electrical components for each project will first be discussed

  • The wiring of components and layout of the project will then be covered in the circuit diagram

  • Detailed step-by-step videos will then show how you how to wire up and assemble the components for the project

  • The code will be uploaded to demo the project and how it works

  • A detailed line-by-line code review will then describe how the software and hardware components play together

  • You will get the complete picture and it is a much better way to learn Arduino by creating full working projects from scratch!

Along the way, you will learn about and become extremely proficient with the following components and understand exactly how they work as they will be incorporated in projects:

  • Breadboards

  • LEDs

  • Active and Passive Buzzers

  • Switches

  • Potentiometers

  • Transistors

  • Ultrasonic Sensors

  • Seven Segment LEDs (single and four digit)

  • Infrared Receivers

  • Joysticks

  • 8x8 Matrix LEDs

  • Shift Registers

  • DC Motors

  • Servos

  • LCD Screens

  • Bluetooth Modules

  • Wifi and GSM Shields

  • And much much more...

The course is broken up into a Simple Projects section, an Intermediate Projects section and an Advanced Projects section allowing you to progress to or start from any level based on how comfortable you are with Arduino.

If you are new to Arduino, the first lessons will get you quickly up to speed on what the platform is and how to use it. You can then progress to simple projects which get you comfortable with basic electrical components.

For those already familiar with Arduino who want to take their skills to the next level, you can jump straight to the intermediate projects section. There, we will focus on making game-type projects using the Arduino and even an infrared repeater that can allow you to copy, store, and playback any IR signal, just like your own universal remote.

Next, for those that might be already comfortable with Arduino, there is an advanced projects section where we tackle projects like an online weather station, remote-controlled car that you can drive with a smart phone app, and a working phone that can make actual calls and send text messages and many more.

I have always believed that project-based learning is the best approach where you actually learn by doing and building something that actually works. This is the approach I am taking in this course. I will explain all the electronics principles involved with each project, show you how to wire up the circuits and give detailed line-by-line code reviews on how it all works. 


1. Class Introduction: welcome. Tired, we know Put camp wading through projects This is a hands on projects based approached Children in God we no platform. We'll take you from novels to professional. I am Leah some I'm an electrical engineer, professional software developer, university instructor but most importantly, electronic hobbyist. Being clean around and tinkering with the Arduino platform since its inception and even teach university classes about this course is meant to bring you quickly up to speed on Arduino. If you're not already familiar with it and make you a confident Arduino prototyping at the end of the course, you'll be able to undertake complex projects which really demonstrate the power of R. Reno. Here is how the courses designed if you are completely neutered. We know the first few lessons are meant to bring you quickly up to speed on what the platform is and how you use it. I will show you how to in store the Arduino i e, which is the program we used to upload software to our Arduino. I will even cover programming concepts that you need to know you can then progress to some simple projects which really seemed to get you familiar with electrical components and how they work. If you are already comfortable with hardly no one want to take your skills to the next level. We can advance to the Intermediate Projects section, where we will focus on making game type projects. For those confident doing folks, you can jump to the advanced section. They will be tackling some more complex projects. As an example, you'll make on online connected Weather Station that connects to the Internet to retreat for the information on will make a remote control car that you can control. Our smartphone app and open source for this course will incorporate them into complete projects, so you will have a better grasp on how to practically apply them toe ideas and prototypes. By taking this approach at the end of the course, you will have become extremely proficient in using all of the following components. You will have the confidence to incorporate them into any of your own electron ICS projects . This course is ideal for you if you are simply curious about Arduino and want to get extremely comfortable with the platform and want to create cool and exciting projects if you are maker or want to be an inventor or are electron ICS happiest? This is the course for you, especially if you are a student or a home schooler. It is a great way to get introduced to electron ICS. No previous programming, all electron ICS knowledge is required for this course. I will teach you all principles from scratch teach you to be a confident maker What he step by step through all the electron ICS principles involved in projects were making show you exactly how tow wire up projects, step by step and then I'll do a detailed line by line court review so you can see how everything fits together. It really is the best way to learn. Thank you for your interest in the world of r And I look forward to being your guide on this journey. Come join me in the Arduino boot camp. Let's work together, toe rip our Reno skills into shape. Can't wait to see you 2. Buzzer Sound Recall Game Project - Part 1: this project incorporates a lot of the concepts we have learned so far. We are starting to put together all our skills. We will be building a fun buzzer sound recall game. Essentially, you first have to listen to a sequence of notes as their plead led lights will also give a visual indication of the roots. Then you must play the notes back in the exact order. You heard them by pressing the appropriate buttons that correspond to each buzzer. If you get it right, you win. But if you get it wrong, the sequence will be played again for you to attempt again. Let's take a look at the objectives for project. By successfully completing the project, we will have mustered the following items. We will learn how to incorporate several different electrical components in one circuit. Ladies push button switches on buzzers. You will also be introduced to the concept of the bouncing and how it can be handled. We will be installing and using 1/3 party library toe handle the bouncing for our circuits , so you'll become familiar with how this can be accomplished. If you are ready to begin, let's get this project started Here are the parts we will need on our between A. You know, a USB cable. Our bread board 32 20 Wound resistors 33 30 Ohm resistors three ladies, preferably red, green and yellow. But if you don't have these, you can use any other colors that you may have. Three pies of buzzers. Three. Push button switches on connecting wires as he concedes. A lot of parts letter components, but we'll get it all. Wear it up. Let's let's address the concept of the bones. Switches are mechanical components that consist of moving parts. Let's see, we are measuring the voltage at a particular switch pit when you press the switch. The signal does not immediately go from high to low as you press down. The contact has made several times, and the voltage signal goes from high to low back toe high with sword. This process is known as the bouncy, and this happens a few times before the signal actually settles down. This is measured in microseconds or milli seconds, so it may seem like a short time, but it has serious implications into a tronics When we take readings. If we look at the in voltage waveform and try to capture it on Acela scope, which is a device that we can use to inspect bulging signals and where forms you'll see several peaks or bumps in the transition from high to low. The switch is actually making contact breaking, making contact again and breaking before finally settling down. It is, of course, very quick and cannot be seen to the naked eye. This has implications for when we take readings and and we know to determine the state of a switch to adjust for this or corrected weaken, do several different things. We can use components Norma's capacities sometimes to switch out this disturbance or more complex secretaries such as Schmitt triggers. We can also handle this and cool from a software perspective. This is, in fact, what we're going to do in our project so that we do not have to introduce any additional hardware toe handle that the bouncing errors that were introduced. We will use 1/3 party LaBrie called bouts to help us out. We need to do this because we need to be precise in determining what button is pressed on in what sequence for the playback for our game. Let's take a look at the circuit diagram for our project. As you can see here at E three parcel buzzers. We also have three ladies corresponding to those parts of buzzers for the ladies, they each happy to 20 whom resistor from the cathode or the short up in the ground. Here, in here, Onda for the animals of the led is the yellow is connected to pin 10 on the Arduino. The green is connected to pin nine and the red led is connected. The pen eat on the go for Feisal buzzers from the negative of the buzzers. They each have a 3 30 ohm resistor that is connected to grow. So here is one. Here's the 2nd 1 and here's the 3rd 1 And from the positive pin of the parcel buzzers also connected to pin 10 nine and eight on the wheel for switches. It's which has one terminal that's grounded and the other ends of the switch switch one which corresponds to our buzzer one and are yellow led. His connected have been 700 we know switched to which corresponds to the green led. The second buzzer is connected to pin 61 year deal and finally switch three, which corresponds the buzzer. Three on our readily is connected to Penn. Five. In your so quite a lot of wiring and components in the circuit, Let's see how it'll please together. Let's go ahead and wear for a circuit first. Let's put in a Peiser buzzers. Remember, for the price of buzzers. There's a positive spin, Andi, that you'll notice that positive symbol likes any positive pill of the buzzer. So a trick that I use when I'm connecting the piles of was is is just too gently put them in the circuit so that you can actually see where the pins are. Otherwise they cover up depends on you Wouldn't want to make a mistake connecting the wrong world. So he is the 1st 1 second buzzer and the third buzzer right next. That's Ah Connect the corresponding LTD's So for the buzzer on the left for going use the yellow led one in the middle will use the green when right we're gonna use the red has connect the 2 21 resisters to our ladies. So again, Legos, bagel from the cattle Cocteau to grown. I think that's the 1st 1 here is a 2nd 1 All right. Finally, your third would next. We could do the 3 30 wound resistors that come from the negative pin of the parcel buzzers . So gonna. All right. Remember, those also go to ground. So I'm gonna jump that connection there. That's the one that left as you see him slightly raising the bread board so I can see specifically Where about Pin is under the price of other Eric. That's the 2nd 1 And I know your sisters are crisscrossing here, but hopefully you get the idea. Finally, the 3rd 1 try also not to make your resistance touch. All right, so try to make that as clean as possible because he wouldn't want any interference. Great. So those are the resisters now will do the collecting wires. So from the, um, buzzer, we're gonna go to pin from a positive one. We're gonna go to Penn 10 or near Reno. So I make that year, right? And that actually is coming to the baby this week from the collection from Pinedale to be positive about Led. All right. Men grew from eight to be positive of the third maybe then we have to make a jumper to the buzzer. So along the same horizontal rule for the yellow led since that is joined, you're gonna go to the positive of this poser, and we'll do the same for the other two. There we go, to be positive here and then for the final brother can, making sure looking to see that the old lane up to the positive. All right, That was quite a little wearing there. So go ahead and push in our buzzers. No, just to make sure that you're in the air secure securely now will collect the push button switches. So here's the 1st 1 which corresponds to this buzzer in this led Here is the 2nd 1 which cars cleanse to be second on. Here is the third. It is here. Correspond city. But it's dead. Sorry. Switched. That corresponds to the third buzzer and the red led. All right, so the switch there will grounded. So that's connect those ground pins first. All right, now we're just gonna go from switches the other end of the respective peanuts. Only Arduino so far us. Which would I wouldn't go to Penn seven. Did you know. All right, for switch to it's been six. And finally the switch three. Medical it up in five on the Arduino. Okay, The very last thing we need to do is collect that ground will make that ground. Connections will go ahead and do that. No. So from the ground real of the bread board, we're going to go to ground on your and Riedel. All right, so that's it. 3. Buzzer Sound Recall Game Project - Part 2: Okay, let's go ahead and upload the code. Okay? So as you'll see the game first, please for notes randomly on its expecting you to replay those notes in order for you to win the game. Remember this particular pin, this particular button, I should say correspondence that this buzzer, this one corresponds to the 2nd 1 and this third button. Correspondence city, third buzzer here. So right now, I actually forgot one sequence, so I'm just going toe get this wrong, right? Somebody tried to play this back, and you'll notice that it tells me that it's wrong. So then it plays back the sequence, and I'm supposed to play, so I think I remember it. No. Go ahead and try it. You got it wrong. Okay, let me listen. All right. So it's all right. So if I won, the first light is gonna light up, and then it plays again. So it's another random sequence. Got it right. Let's go one more time. Okay. I got that one, right. You know, what I'll also show you is that you can increase the difficulty level of the game if you look at our cord on. We were to changing load sequence. So here we're playing with four notes. I can increase this. Let's go up to six. So I By changing the value of this ary, I'm able to make the game even more difficult. So instead of four notes Now I have to remember six notes. So when it gets uploaded, here is they're gonna play now. Six notes. All right, one more. There you go. All right. So you get the idea. This is crazy, addictive and lots of fun. So encouraging to play around with it. Change difficulty level. And you can play this with your friends and your family. So for this project, we will be using anything party library bones to which hopes us with the bouncing to figure out exactly when our switches pressed. So let's first download that their party library, and we will install it. And they are green. No, I d on. You'll see then, Weaken. Be able to use the library as part of our project in our code. So I'm gonna put the link to the library, Actually, in the resource is for the project. But if you just google the bounce too liberal for and we know there is a get hub link that you'll come across on those Fredericks This really have any labour for us? Um, let's go ahead and download that so you can download the zip file. I'm just gonna put that on my desktop here. So you see that when it's finished, I will unzip it, so know that it's unzipped. Here are the files for bounce the bounce library. Remember, For third body libraries, we have to rename it. So I'm gonna take off this master and the end the dash muster, Just leave bones too. And now I'm going to copy this into my Arduino folder where the other libraries are stored . So as you if you remember, if you recall if you go to your DWI No, and you look at your or file preferences on windows are doing no preferences on the Mac, it should show you where the location sketchbook location is. This is where in here there would be a libraries folder, and this is where it went to copy any of your third party libraries. Okay, so let me go back and copy that labour over a copy that bones to library and I am going to go here and my particular installation. It's in my adrenal Libraries folder here. I'm goingto paste that bounce library. No, I already have that installed. Um, but here's where you would just include any libraries that you use. After you do that, you'll want we start your ID. Reno. So go ahead and close it off. We started and we know I d Andi. Then you'll be ableto use the library. So let's take a look now on record for our project. First, we include that new bounce library that we install that their party library so we can use it. And on the top, we define all buzzer pins. So but the one has been 89 and brother to its benign was a three spin 10. And then we define our buttons right on pins 56 and seven. Next, as part of the Bounce Library, one toe in Stan, she £8 objects. So we created the bombs of one object, and we instance sheet that by calling the Bounce constructor from the Bounce Library that were imported, we included. So we have the bones the one amounted to, and the ones of three those are bouts objects. Next we have a note sequence and this is will determine the number off notes that we recall all we have to play back so you can play with this number to make the game more difficult. I think by the falls it should be set to four. But you could increase this or change it as you will the number of notes. We determine that by doing a size off note sequence that will give us this size of the memory allocated to note sequence and divide that by the size of one integer. Hence we get the number of notes so that allows you toe tweak this. And just by taking this one variable, it would this would the number of notes to play back will be calculated. The current note. This is a global variable. We set back to zero and the challenge plead, it's ah global Boolean variable. We set that the false. We'll see how we use those of a leader set up for issued forward. Here we do our pen mode button one. We used the input pullup resistors that we we didn't have to connect any resisters to our push button switches. So we do that for all three on here as part of the bouncer library we want to attach. But no one to that. The bounce of one object. So that's how we're able to associate the particular buttons with the the bones objects. Then we generate a random place sequence. So that's the function that's going to generate a random number for us. This particular line of code random seed on along zero, Aren't we know has ah, you know, sort of Ah ah, heck up in that if you with the generate around them number it remembers. That's every time you re lewd the you apply power to the sick it it would generate. It seems in this show random number. So to make that, you know, totally random for the very first time coming in, we can use this random seed function and we do arbitrary and all agreed on 10 0 which again , that's a random number that will be generated on that would give us a true true random number the very first time it let's take on a need generate Grandmother, please sequence function. So I'm gonna go down here, But So here we moved over from I starting at zero till the number of notes we get a random number between one and four Onda. We, um you know, we store that in the note sequence and the sequence array. So basically, hair were building up the number of notes away We're setting up. What? That play sequences B I's gonna be and we're storing it in this note sequence. A read. So let's check out our loop function. So now loop. We check to see if the challenge was played already. If it was not leaders yet, he said, charms played the truth. The current status zero. And then we played a sequence. So there's a handy place sequence function which takes in the note sequence, which we generated, and I'll go down to that place sequence. And so here's a pre sequence so it loops over that load. Sorry that was passed them on. It plays each note. So that's how you hear the tunes being plead. So for planeload, that function is Phiri straightforward. It just takes a vote. Onda, Um, it comes in here on If the note was one, that means it would be playing the first buzzer. So you do a tune for Buzzer one. Set the frequency of 2000 hertz and there's a delay. Then we turned It was off their laser shortly after notice to we put in the second buzzer and then three the third buzzer. Right, So this just please the corresponding buzzer. Also note that we set the frequencies at different levels. So that's where how you can hear a different pitch sound for each buzzer. So that's basically deeply note function. All right, so now we get back into, um, our loop function here. In order to keep track of the bouncer objects, we have to call the update function. This is just the start of documentation with that bounce library. Next we do have read. So now here's where we want to determine which switch was pressed. So basically, we store that onda. We check to see if the bonds of one dot fell. That means thief oost switch was pressed. We would clean what? One. Right. So that's when the user is involved or or doing the playback. So it playing out one and then we will verify Note, please. Correct. We pass it on one So that the user pressed one. We want to make sure. Oh, is that correct? Andi, I'll just quickly go to that. Verify if notice plead. Three come into that node sequence that we initially set up and we check to see. Is the current loot the order which you playback? Is that equally no dodgy Plead to the no that was stored. Andi. It continues on and on on literate over this function. Andi, when you reach the end, the end of the sequence if he noted that you have played is equal to the number of notes you done. Meaning you're at the end of the four cycle or the sex cycle home. However, money lutes that you had set up and then you would be a winner. So we call the winner function else. If you were wrong anywhere in this sequence, we call the loser function. So just quickly looking at the winner and loser functions for winner. We get that beep, beep, beep. Eso basically here. We want to make sure that we for three times set that tour Members of three. So we hear that. Quick. Beep, beep, beep, Onda. And you know we do that on, then we exit out. So that's the winner for the loser. As we mentioned, you get that beep. You know that one long beep. So here is where we use the tool function, the sound that. But once we do a one secondly, to let off two seconds, and then we start the process again. So quite a lot of functions. And here it's very modular and broken up. Our encourage you to, you know, take a look at the code and go through the different functions. But ah, you know, barring the bounce, a library that we pull them, that really helps us. It's as you can see, to determine if a switch was pressed. It's very straightforward to do that. We just check to see if you know the bounce about full. That tells us that if they switch was pressed, we don't have to deal with any timing issues or any false positives. We know that I'd switch was pressed. We can verify the notice correct and so forth. So that's our game on. That's the cool of you to summarize. In this project, you learn how toe incorporate a lot of basic components. And on our final project, we were also able to introduce 1/3 party library to help out our project. These are useful and help us to really focus on the unique problems we're trying to solve or do we know is open source and many open source libraries from those who have already solved common problems in the community exists that you can leverage just like are the bouncing library. If you build libraries as well, contribute back out, open source and contribute to the movement to This was a great project on By successfully completing it, you would have mastered quite a lot of skills. Let's keep the momentum going. 4. Ultrasonic Sensor Alarm Project: this project, we will be looking at a very useful component for your electron ICS projects. On ultrasonic sensor, we will be building an alarm circuit which incorporates a pie so Buzzer and Red and Green LTD's toe warn when an object has been detected or comes within a specified range of our sensor. When the object is to close, the buzzer will go off and the red led will be let sensor once no obstacle is detected. The green led tells us we're doing okay, let's take a look at the objectives. By successfully completing this project, we will have must in the following items we will learn what an ultrasonic sensor is and how it works. This specific ultrasonic sensor we will be utilising is a very common model the H C s r 04 which is very inexpensive. We will learn the penalty of the each C s. R 04 and how to connect it in a circuit. You will also be introduced to the pulse in function and how it is used in conjunction with the ultrasonic sensor to perform measurements critical to the operation of our circuit. If you are ready to begin Let's get this project started. Here are the parts we will need on and we know you know a USB cable of bread board free 3 30 whom resistors on each c s r 04 ultrasonic sensor red led on a green led A pies, a buzzer and connecting wires. That's this address how ultrasonic sensors operate, similar to the mechanism by which in bats used to navigate. Which is sooner. The sensor transmits a wave signal, which is referred to as a ping and waits for an echo of that signal to be received. If the we've comes into contact with an obstacle, it is reflected back, and once the reflection is detected by the sensor, a calculation can be performed using the time it took for the wave to return. This is how the distance between the sensor and the object can be derived. The pulse in function is used to measure the time between when a reform ascent until the time it is received. It actually accomplishes this by looking at the time a signal takes to transition from low to high or high to look. We will talk more about this function when we dive into the code. If you take a look at the Leo of the ultrasonic sensor, you will notice it has four pins. VCC is connected to fi bolts on the yard window and ground is connected to ground. Be trigger on EC. Opens are connected to other digital pins on the Arduino, and the readings from these are used as part of the measurement process. Let's take a look at the circuit diagram for our project, so you'll notice. Here is the ultrasonic sensor and there are four pins. VCC is connected to the Five World Real Wonder Bread Board Onda. We connect me fi bold, real doof eyeballs on the Arduino. Grown is connected to be grown riel on the bread board. On we connect that ground wheel on the Arduino. The trigger pin is connected to pin to on the Arduino, and the EC open is connected to pin 300. Reno our pies. A blizzard in negative end of the parcel buzzer is connected by a 3 31 resistor to ground, and the positive pin of our buzzer is connected to pin level on the Arduino. We have to allergies in our circuit for their red led the cattle or the short up in is connected by a 3 31 resistor to ground and the animal or the longer positive pin is connected to pin eight on your reno for our green led cathode is connected. Fired at 3 31 Resisted the ground on the positive Arnold pen is connected to Penn. Nine on the Arduino, not still worrying of our circuit. Okay, let's go ahead and wear upon a circuit. If you look out our ultrasonic sensor, you can see that it has four pins. BCC, which will be connected to five. Walter neared. We know ground which would be connected to ground. The trigger pin is going to be connected to pin to under Arduino and the echo pin is gonna be connected to pay three in your dream. No. So let's go ahead and wire this up in the circuit. When you connect your just sonic sensor, you want to connect the sensor and the receiver away. Only facing outside of the Brit Board that where we contest the actual obstruction. So go ahead and connect that Let's connect the ground rial to be ground. Any bread board first. All right, something that grown connection. And next I'll connect the five bold riel. So we go from five old's on the Arduino to the Five World Real That's where up the ultrasonic sensor Next. So first be grown Pin will go to ground when you're agree No next weaken wire up the BCC we go to five volts Then we have our pin trigger pin that goes to Penn to near Drina Our eco pin goes to pin three Then we can wear Popeyes a buzzer The positive on the pizzo buzzer goes to Penn in level under And we know we have a 3.81 resistor from ground or from the negative penalty passable They're going to ground so just make sure I'm just gonna one that resistor street The ground here now will connect our ladies It is a red already and a green led the negative car Foods of the ladies are connected to grown by a 3:30 a.m. resistor. So I'll connect those No, that's the 1st 1 on. This is the 2nd 1 and the finally we need to connect the positive of our ladies. So for the red, the award goes to Penn. Eight on neared. We know. And finally, for the green, be positive goes depend mine near Reno. Okay, that's Ah, complete steam wiring for a circuit. Okay, let's go ahead and upload the code. While that's uploading, I will open up the serial monitor. All right to your notice initially that I'm displaying the distance that an obstacle is closest to the sensor Onda. Initially, we have set the range to be two inches. So if an object comes within less than two inches of these sensor, that's when the buzzer on the alarm would go off. So right now, the green led is lit. That means our circuit isn't already or okay status. And now I'm going to start moving my hand towards the sensor. So here we go. If you take a look at the measurements, you will see that the distance is decreasing. So six inches Now my hand is at five inches, coming in four inches, and finally they still good. And now all right. You see, the alarm goes off so the red led will be lit and the buzzer will sound as soon as my hand is with less than two inches from the sensor. All right now, I'm going to treat the code and actually increased this to three inches. Go ahead and upload that. And now you'll see. We'll start moving my hand to what? To censor again and within six inches and coming closer. Five inches. I'm within four inches as I start moving it closer. The sensors should go off and we go. So once it's less than three inches, it goes off one final tweak. I'll change the range to five inches. So what that means is this. When my hand comes within five inches of the sensor, it should go off. So let's start. I'm bringing it closer. I want seven. Here it come, all right, so you will see as about five inches less than five inches. That's when the but I will go off all right. So as you can see, it's fairly accurate for longer distances, and you can play with that range setting to tweak the distance, the allowable distance of an obstacle from the ultrasonic sensor. Let's take a look at the code for our ultrasonic sensor circuit. Initially, at the beginning, we define our trigger. Pin was, too, since it's connected to pin to one yard. We know and the EC open has been. Three since it's connected have been 300. Reno. Next comes our Ellie deepens the green led. The Lord is connected to pin nine on the Arduino, and the annals of the red led is connected to Penn. Eight on the ad. Really? Finally, for our buzzer. The positive pin of our buzzer is connected to Penn 11. When they're agree. No, the next global variable. We declares the range. This is the maximum allowable range before our alarm is triggered. The initial setting is two inches. So what this means is, if you're obstacle comes within just mess of two inches from the ultrasonic sensor and the buzzer would go off in the red led will be let you can tweak and change this variable accordingly to experiment with different ranges for your project. Next, in our set up function, we have to do a few things. We first set up a serial communication speed, then we initialize thes sensor pins. The trigger pin is an output since this is the pin that generates the output pulse and the echo pin is an input. Since it reads the pulse that is reflected back off course. Our green and red led pens are defined as outputs. And initially, we would want to send a high signal to the green led Pinto. Turn it on. Onda, turn off our red led. Now we're ready to go. That's examining Luke. Function initially to take a reading. We have to generate a clean, high pulse. So to do this, we first generate E most signal we write sleuth to the trigger pin. We have a short early then be right high. Did he trigger pin have a delete off five microseconds and then we've right move again to that trigger pin so that would generate a clean, nice pulse which is sent out for us when that pulse comes into contact with an obstacle and is reflected comes back and what we need to do is measure the duration for that to occur. To accomplish this, we used the pulse and function passing in a echo payment, which we're taking your reading on. We want to specify that we're looking for that high. The low transitions we pass in high as the argument here we will take a little more in depth. Look at the documentation for the pulse and function shortly. Next, we want to calculate the inches and centimeters to our obstacle, so there are a couple of convenience functions we can use microseconds, the inches we can call that function passing indeedy oration that was taken from, ah, pulse in function or that was retuned from our post in function. And we can also determine the distance and centimeters by calling the microseconds two centimeters function passing in the duration. Next, we simply print those values out so we can see the distances. And that was what was displayed in all Syria and monitor. And here's where we have the actual logic to determine if our alarmist son, if the inches that was returned is less than a range, we know we should sound your alarm. So that's where we would turn the green, led off to Onley reality and give that son the buzzer by using our tune function. If we're all key on the inches that was return was greater than a range. We're good to go, so the led the green led would be set high. Red led will be turned off and there would be no alarm sounding from the buzzer last week in our program. These are the two convenience functions that do the calculations for us in microseconds two inches and microseconds, two centimeters. So, um, the calculations for these, if you require for the documentation there is a link here which explains, you know what the calculations are on their some documentation from the functions here. Let's take a look at the pulse in functions and going to Google that on here is the link. So essentially the polls in function reads a pulse. I have a higher lou on a pen. So if you are specify that devalues high. Paulson would wait for the pentacle high started time and then wait for it to go look. Hence its measuring the time that it takes for the reflection to come back from our obstacle. As you can see, there are a couple different variations of arguments that you can specify for the pulse in function. The 1st 1 just which is the 1st 1 is the one that we used. It simply takes in the pin value on devalue you want to track whether it's higher, low, you can also call the pulse in function, using a time out additional parameter and basically what that says is it's the number of microseconds toe wait for the post to be completed on. If that time load has reached, then the pulse and function would just return. Zero. To summarize. In this project, you learn what an ultrasonic sensor is and how it works. You were specifically introduced to the H C Azzaro four model, and the penalties were explained. So now you will be familiar with how to connect it in a circuit you will also introduced to the pulse in function and the important role it please in taking measurements for the ultrasonic sensor, This ultrasonic sensor is a very useful component and can be incorporated to beef up your world Barton Car projects for obstacle avoidance. You'll now know how to use it and interact with it. Using your Arduino. Let's move on to our next project 5. Digital Dice Project - Part 1: in this project, we will learn about seven segment displease on how to interface them with your Guido. These components are the visual lead that you can incorporate into many Arduino projects. We will be making a digital dice using a seven segment this plea on a button to roll the dice. Simply push the button and we will randomly get a value between one and six, which would be displayed. Justus. If we ruled, the physical base always will be a digital dates on after building it. You can even use it with your board. Gates. Let's take a look at the objectives By successfully completing this project, we will have must in the following writers. You will understand how a seven segment this works and how to connect a seven segments three in a circuit. Also, new understanding difference between a common a load on a common cattle. Seven Second display. If you're ready to begin, let's get this project started. Here are the parts we will need, you know you know a USB cable, A bread board 7 to 20 resistors, seven segment display. We will be using a common capital this, but if you have a common Another. This will also workers well. There may need to be slight wiring changes. A push button switch on and connecting wires lets loose address how seven second his work. If you look at these schematics for seven, segment this page, you will see that each segment or individual piece has the light of two. Discrete. Part of the final result has elector on a correspondent pin that is associated with it. If the Orient with seven segment this plea with decimal point at the bottom right, the pins a numbered one through 10 a show, one open to three for five and then on top 6789 10. If we look at the seven segment display in the more physical representation here has been 12345 and then in the top would be pin 6789 and 10. Now each been also corresponds to a particular segment on display. So let's take a look at Pyne. One, for instance, in one corresponds to segment E. So if we would apply, find pools where high wilted signal to pin run, then segment E would light up. Similarly, let's look up in two as you can see in two, corresponds to segment deep. If you want to apply a high voltage signal to pin too, the D segment would light up if ground zero volts is applied to pin to instead. Then the D segment would not be let get the picture met, saying we wanted this play the number two on the seven segment this plea. How would we accomplish that? Now remember to would look like this. Okay, so in order for it to to be displayed segments, e be g, D and D have to be lit. So this would mean that we would need to apply fi bulls or high vaulted signal two pins. Seven, which would correspond to segment A in six, which would correspond to second be in 10 which would correspond to segment G in one, which which would correspond to segment E and finally pinned to we should correspond to segment T. Let's quickly discuss the difference between common. I load with this common cattle. Seven Second this please for a common cathode, which we will be using for our project. The common pins, which are pins three a neat are connected to ground this means that in order to light a segment or turn it on, you need to apply a high voltage so that it current can flew into the led and then back into grown to tune in on for a common a nude. The reviews is true. The common pins free I need are connected to five foods or high, so it wanted to make any segment right up. You have to apply a ground zero Valls to the pins so that current and flew through the commons down through the led and down to ground to turn it on. So the difference between common and road and common cathode is the polarity of the common pins and the voltage you will need to apply toe light segments. The data sheet for your seven segment led will tell you if it is a common addled or common cattle configuration. Let's take a look at our circuit. Diagram for the first Circuit were simply connecting the seven segment display. Only there's a lot of wiring with this particular circuit, So first, let's start on the extreme left. We would connect our to 21 resistors in the circuit, and if we start on the extreme left been to on our Greenalls is connected to that first resistor and this the end of the resistor would go to Penn. Seven. Only seven segment this plea. Similarly, for the second resistance, it's connected to pin three on your agree No, On the other end goes depend six Only seven segment this plea. Next one been four, then ghost a pen for only seven Second display Next five, when you're in Reno, that goes to been to 27 seconds free Next, then six on the Arduino that goes to pin one 27 2nd this plea, then pin seven. When did we know A man of that resistance goes to Penn 9 27 2nd this plea. Then we have been eat on the adrenal, The other end, which goes to Penn 10 87 segments three and again, since we're using a common cathode pins three, a neat agro did and we connect that ground connection to their Guido. So that's the wine for are simple seventh segment display on me. Okay, let's go ahead and whereupon circuit first. If we take a look at our seven second display if we orient it with the decimal point to the bottom right, you'll notice the depends. This is would be paid one to 34 and five. And then this continues at the top with bins six. Several, 89 and 10. Okay, let's go ahead and put this in a second. I would recommend not to push this in all the way initially. In that way, we can actually see the pens when we are worrying up the circuit, because there's a lot of wiring in the circuit and we don't want to make any mistakes. So just gently pushing in and when we're done, where I would get pushing in all the way and recommend putting in your 7 to 21 resistors in the circuit initially. So go ahead and do that. It's one seven. Okay, so that started wiring. So from the first resistor, it goes to pin to on your Drina so mean a collection of the end of the resistor goes to the pin. Several only seven segment this plea, right, So at the top second resistor in 300 arena, the top of it goes to Penn six 27 segments plea third resistor and Foreign yard we know. Top of it goes to pin for seven segments, Clay. Next one goes to pin five on your demeanor. Top of a goose story pen to next one. Must have been six in the arena. Top of that guy was the pen One. Next one was to been several neared. Well, tough of him goes to Penn Line. And the final guy final resistor just open eight. When are we know and finish off with pin 10. Okay, so that's most of the wiring. Now we have to connect pins three and eight. So I'm going to put one jumper wire between pins, three on eight of the top here, and that has to be grounded. So I'm gonna connect. Okay, Worry here. And I'm gonna go to ground on your agree? No. Right. So now that that's complete, I'm just gonna push in my seven segment so it's fully in place, and that completes so worrying. Okay, let's go ahead and upload the code. Well, that's uploading. Open up the serial monitor. So as you'll see, there's an instruction. Enter a number between zero and nine. So let's go ahead. And, um, you know, started one. Some gonna enter one here, Press enter. As you can see, one lights up on our seven segment and I'm gonna cycle through. Gonna enter, too. Two was displayed. Three for five, six, seven, eight, nine and then zero. All right, so they happened. I was seven. Segment display is worried up correctly and were able to accept input from the user to display a number. When we get that input, we correctly display that only seven segment this plea. 6. Digital Dice Project - Part 2: All right, let's take a look at the code for our seven segment display. So at the beginning is where perhaps the magic happens. We have to a raise that we define the first of these segment pens, and this is the order that we connect the pins to the armed we know from the second segment display. Next, we have a bi tary That's the digits, and you'll notice that the re consists of the zeros and ones, and it's really the steet of the particular segments. So for the zero to me displayed, we're actually have to light up segments A, B, C, D, E and F for a one to be displayed, we actually have to light up segments. Be and see for two. It's a okay de e and G and civil salon. So we're defining the array of bytes, and the states of these ones correspond to the segments that need to be let to show up the particular number. Next, moving on in a set of function, we do a loop between zero and seven, and we set those pin moods as output. And we initially right Lou to those segment pins to tune all these segments off, so nothing will be displayed initially when we first applied power to our circuit. Then we begin the serial communication and display today. User enter a number between zero and night, so that's going to show up in our cereal and monitor. All right, let's look at the loop pollution. So basically, look function. We pool and wait to determine if we are receiving input from the user. And if that's the case, we extract that into the character of arable using serial dot reid on. We've seen this cold before where we check to see if it's between zero and nine. We converted into an integer by using this handy trick doing ch minus the character zero that's gonna convert it into an integer for us. And we want to assure the interview that was entered. So we call this convenience function of date display passing in the individual or the number that we have to display. So let's take a look at update display update. This pain just takes that one argument on it into makes a call to set segments. Passing in that value set segments is a level function on. This is where the magic happens. So you are looping here between zero up until several. Because, remember, it's less than eight. It's not included. And let's start with zero. We do a digital right Onda. We do segment pens I and that will be zero. So let's look at segment pins up here. So it's first going to right to this. Been then this spin and so forth, right, going up all the way to eight. And what we're going to write to that pin is the value from the digit Serie So digits. If when we're zero, it's going to be digits. If the value of past in let's say was one, it's gonna be digits one, and it's gonna loop through everything that we need to display a one. This was an example. This would be a one. So the first time through the loop, when an zero it's going to be, zero says, going to write a loo. Then when it loops again, it's gonna be a high, high, low, low Lu Lieu look. So by doing that, we're able toe loop through whatever number that was passed in and set the appropriate segments too high for that number to be displayed in our second circuit. The only condition will be making is adding a push button switch that will be used to perform leave rule on the device when the button is pressed. One end of the push buttons, which goes to ground and the other end, goes to pin nine on the Arduino. That's it. That's the only general make from the previous circuit. Or it's a long gonna make a slight wiring change to incorporate our push button switch. I'm gonna put that switching and circuit. This is for our dice, All right. One end of this switch goes to ground. He's ground on this side of the do we know. And the other end of the switch goes to Penn. Nine on your agree? No. So I mean that connection, right? That's it. They have it. That's Tony addition. We need to make in wiring for our digital days. Okay, let's go ahead and upload the code for our little dice. All right, so now if I want to roll for former rolling the dice, I just have to push only push button switch. So there you go. So my first rule was to Let's try it again. You got to again. No, I've got a six. No, I got a three and no thought you. So there you have it. Our digital days. By pushing the switch, we actually perform a rule by pushing on the switch. A random number between one and six is generated on That shows up on our seven second display. Let's take a look at the cool for our digital dice project. A lot of the court is the seem from the previous seven segment project. Initially at the top, we the final segment pins and again these air depends that connect from the Arduino 37 segment display. Next up comes our bi tary, and here is where we define which particular segments need to be turned on to display a corresponding number. This spent digits bite is a new addition to our code, and essentially it enables us to get that spinning animation when we push a button for rule . So initially, the A segment is let than the B, c, D, e and F. So it goes around to meet that animation. Here is where we define or button Ben so it's connected to pin you know, neared. We know. So this is new. This is an addition to our code. Set up looks the same. Initially we define or pin mood for our segment pins to be opens and we do a digital right to those two it to be low so that the seven second led will be turned off initially, nothing will be showing up. Then for our switch, we do a pin load button. Then on we initiate a we set up that input pullup resistor on off switch and we begin the serial communications. So that's our set up function. You know, Luke function. We simply do a pool. Basically, we check if digital read on the button pen is low. That means that they switch was pressed. That's the keys for this. We want to show that spinning animation so we call a convenience spin function on all spin does. It's simply loops over with a snarled dally. Onda lights the appropriate spin digits pins, so that's just to create that spinning ary. After we spend, we do a rule, so the rule would generate a random number between one and six, which equates to, you know, if you are physically rolling the dice and then we call update display passing in rule. This update display was the function that you have seen previously where it it, in turn, makes a call to set segments Onda again, depending one word was passed in we to a digital right. We loop over the corresponding arrays that we initialize, and we light the appropriate segments that the spirit in number that was passed in. So we've seen that previously. So this is the code for our digital dice to summaries. In this project, you learned about the details of the penalty of a seven second display. You also learned how toe wire up a seven segment display in a circuit you should know. Be clear about the difference between a common hallowed and common cattle configuration. You can use your digital dies for playing board games with their friends. Let's keep the momentum going and move on to our next project. 7. How Infrared Works with Arduino: In this project, we will build Ah hunde infrared. Repeat a circuit. Essentially, you will be able to record upto three infrared signals. Here's how the secret will work. Simply point a remote at the circuit and press the appropriate button on the remote for the signal you want to record. Then press a button on the circuit associate with and store that signal. Meet our own to play back that signal point the led on your sick it to the device you want to control and press the button. The cool thing about this project is that even when the circuit is powered off when it is powered back on, the signals you stored are persisted. So it remembers them. You can. How's your circuit in a box and you have a universal remote that can copy and play back any IR signal. How cool is that? Let's take a look at the objectives. By successfully completing this project, we will have mastered the following items. You will understand how infrared receivers on led is work. You will learn how to connect on IR Receiver on led in your sick it. You also be introduced to the popular IR remote library for working with IR components. You will see how easy it is to record and playback signals, and you will be introduced to the E prom and it's get on put methods for storing deter that can be retained even when the Arduino is powered off. If you are ready to begin, let's get this project started. Here are the parts we will need on our green Oh, you know, a USB cable, a bread board, an infrared receiver. We'll be using the T S. O p. 3 82 model. It's a very popular, inexpensive IR receiver, and I are led 2 20 room resistor, three push button switches on and connecting wires before we get into our projects. Let's was talk about in for a technology Oi are IR is a common, inexpensive and easy to use wireless communication technology. Iron light, a similar to visible light except that it has a slightly longer Waveland IR is undetectable to the human eye on is perfect for wireless communications. Here's how it works. IR signals are all around us, but for a device such as your TV to pick out signals from your remote among all other ambient ir signals the IR signals transmitted on modulated modulating a signal is like assigning a pattern to your data so that the receiver knows how to listen for them. A common modulation scheme is called 38 kilohertz modulation. There are very few natural sources that have the irregularity of a 38 killer hoods signal. So on IR transmitter, sending data with that frequency will stand out among the ambient IR. When you hit a key on your remote, for example, the volume up button the transmitting IR led will blink quickly for a fraction of a second and transmit the modulated encoded data to your appliance. The receiving device. Well, then d modulate the signal on. I'll put a binary we form that can be read by the microcontroller. In our project, we will take the input from a remote store. The sequence that is sent to our circuit on a plate back on it a month. Pretty cool, huh? The higher receiver has three pens. The VCC pin is connected to five volts. One pin is grounded. On the other is the signal pin, which is connected to your agree. No, let's take a look of the sick it background for our project in the food sickened diagram will simply be demonstrating how on infrared signal can be received and transmitted again. For our our receiver, there are £3. One of the pens are connected to five bulls and another pin is connected to grown. The signal pin will be connected to any level on your adrenal. For our IR led the cathode or short, a pen is grounded and the A node or longer pin will be connected by a to 20 room resistor. Two Penn three on your Arduino. Next, we have a push button switch. One of the switch is grounded on. The other end of the switch goes to Penn 12 on your adrenal. Also, you have to remember to connected ground pins and the five volt minister the ground and fiber old reels on the bread board. That's the worrying for our circuit. Okay, let's go ahead and wire up Are well, first circuit. So first we have the IR receiver. This is what it looks like. It has three pins, so go ahead and put that in. I'm gonna use a small, smaller bread board just to make the circuit over the more mobile when we tested out. So this is a smaller version of a bread board. Things might be a little tight, but we'll try to get everything in there. So there is our receiver. Then I'm gonna put in our infrared led. So as you notice, it looks so, you know, different from our normal ladies. It's clearer, but this is an infrared led. Next, I will put in the push button switch, so I will put this in on the extreme left of the circuit Parents in this wasn't Snoopy there? That's what's gonna be infrared receiver. So from one pen, he left most pin. We're going to go to Penn 1100. We know that's the signal pin. So I'm gonna connect that to penny level in the middle Pin is going to be grounded, so we'll make that connection. And since on our IR led, we also have to ground the Catholic, I'll just connect this here, connect those two pens together, and then I'm going to jump from that pinned to the ground when you're a greener. So go from ground on the Arduino and I'm gonna go to ground here all right. So essentially, we have grounded both d three ir receiver and the i r m d right at connection. Next, looking at the five bullpen on the I receiver, that goes to five volts. Go across here and I'll make that connection to five volts. So that is that connection for our I really d we have that resistor. I'm gonna put back to 20 women, sister, and that has to go to been three when you're do you know. So go ahead and make that connection here on the other end of that resistor will go to Arpin three on the Arduino. Okay, So as you notice with this Mullah bread board, you seem concepts of play like the big bread board and that these rules here horizontally connected. Okay, there is a break in the middle of the bread board again. So just bear that in mind the similar concepts of play. Now let's finish up will switch. So one end of the switch goes to grown. So I make that connection here, and we can use that seem grown connection. All right, that's with our led. So I just connected it along that seam room, right? now it's kind of difficult to see here, but all of these are seem room you're grounded. And then the other end of our switch go stupid 12 for years. We know. So I make that connection And when a ribbon ago, it's up in 12. All right, so that's Ah, that completes the wiring for our first circuit before we go ahead and upload the code to run our project for the I. R. Record and send circuit, one thing you need to know is that you have to install the Arduino IR remote library. This is a link to it. I will post it in. The resource is for the project. So when you come out here, of course, you would download the library. Extract is a file, and you would put it in the library's sub folder of your sketchbook location, just as we have seen before and how you installed the party libraries. One issue you may run into and there's an ongoing bug in the Arduino forums is that you may get a conflict with an existing bundled, are doing a library, which is the rule, but ir remote library. So the handle this if you look at? You know where you are. Greenoe is installed Java sub folder. You could go and click on that. You'll see libraries India. You may see that robot ir remote library And this is where all of the libraries that come bundled with your Arduino installation This is where they're housed as opposed to you know , your sketchbook location where you can put in custom three party libraries When are doing is installed? Anything that comes model with it is located in this Java libraries. Some folder. Go ahead and delete that robot IR remote folder on everything. That's ah, you know everything that's within near Onda restart your Arduino i d and that should take a of the conflict problem for those that are on windows. You confined that path very easily. Toe where where your Arduino is installed on go to the Java Libraries folder. For those of you that are on the mark, which you'll need to do is you need toe click on your Arduino up on do show package contents. Okay, and then when you look at the contents, that's how you could get to the Java Onda. That library sub folded to delete the robot ir remote library, but just wanted to make you aware about in case you run into any issues on again. This depends on the version of the are green. Why d you have installed the little visions should have corrected this, but you may run into issues there. Okay, let's go ahead and upload the cool for our I r receive sample project. So the name of that particular the particular program I'm gonna uses ir receive. So go ahead and upload that Onda. While that's uploading all, just open up the serial monitor here. So essentially what this program does is it shows how the IR receiver actually receives a signal that is sent by are removed. So here is a removed for a Sunni TV that I have. So I'm gonna go ahead. And if you look at the serial monitor when we send an IR signal to our receiver, it's going to receive it. Onder display where that signal is. So go ahead. I'm gonna press the power button and you'll notice e 90 Is that the quoted signal? So our IR receiver was able to receive that signal on DA correctly process it. Um, I've just try some of the other buttons here. So oppressive. For instance, the one button. Right. So you see 10 showing up when a press the ah to button no. Press these two buttons. There we go. 93 button. All right, Um, the five button and so on. So you'll see even make what? Volume up. All right, you see that? You know, it's being correctly received by our second. So that's that sample program. So when our next program the ire record, we're actually going to send a signal to our sick it. And then when we pressed the button, that single is gonna be played back. So go ahead and upload that code. No, Onda opened up a serial monitor. Rights are program was uploaded, and I am going to Let's press the guinea power button for circuits are but impressive part button. So, as you can see, it says received the Sony and it tells you what the quarters. And now if I were to press our but none are circuit, it actually sends that back out. So it's sending back all that cold. Similarly, for the volume someone oppressed the up volume button here. So it received at 4 90 cord. And if I press the button, all right, as you can see, it's gonna clear back in particular. Cool. So that's pretty cool and that, you know, we're able to send Let's try out the number eight here when oppressed in number eight button. All right, so it received that code. I'm again. Clear that back. Right, So that's pretty handy and pretty nifty in pretty cool. It's using the IR receiver to receive the signal and then it's using The ire led to pre back. Oh, the signal. In the next project, we're going to make a modification to store three signals, but actually persisted so that when the circuit right now, if we take remove power from the circuit is gonna forget board that signal is what we're gonna make modifications to store three signals and persist those So that will be in the next project. Okay, let's take a look at the code for our I r receive circuit. This was a example. Programmers in my country who look that great infrared library. So this is what we used to be able to receive a signal on ir receiver. So initially we including ir remote my Murray on guy will receive a pin was 11. We created the I r receive object on We pass in that pin as the argument Our constructor Next we have ah results global variable which is every type the cold results. And again these two are coming from our are removed like Murray, you know, set up function. We begin this year of communications and we do it able ir in to start the receiver on the call. That method only are receive object in our function which is very short. Basically we do. When I received our decode on we pass in a reference to Dr Results object And basically what we're doing here is once we have received a signal, we simply get that in. We decoded and we display the results out. After we received a signal, we do our received resume on. We just wait to receive the next value and then we continue looping on. So that's our program for short, but it demonstrates how we are able to receive any infrared signal sent our circuit decode the signal that was received. Okay, let's take a look at the code for our circuit that was able to receive a plea back. One infrared signal with a button so at the beginning include our IR remote library on. We set up a couple of global variables, so we have the receive. A pin has been 11 or butter was connected to in 12 on your window, and we have the status spin, which is the 10 13 that's the built in led on the board. Next we construct our IR receiver object passing in the receiver pin, and then we also create the I. R send object. So those that was two variables there. We also have a record results global variable called results. You will use that to store our results. Next, you know, set of function. We begin serial communications and we start up our receiver by calling the enable IR in method. On the I receive object next to be enable the input pullup resistor on our button up in. So we do a pen road apartment in the pull up, and we said he started spin as an output villain there. Some other global variables that are initialized are out of this was taken from the i R send sample program that comes bundled with the IR remote library. So here we have some variables where we use the story called value and they were coats. So we set some of those values up, and there's a global tuggle variable that we used to maintain our r C five or six tons state. So here is the store called Function and basically takes in that record results variable or reference that are variable on in here in this function were essentially storing the code. So when the call comes in with personal traveling what it is and a lot of this code is from , you know, from the sample program with make interest So we able to receive determine what code was sent in based on the device on restored code in our results. Object. Then, when we want to send the cold back out, we have a send code object and we person ah, repeat parameter at the court needs to be repeated on, as the function says it just sends the code back out. So, um, a lot of logic and near around receiving the signal and sending it back out in our loop function through things were doing here. Basically, we're determining if the button was pressed and if that was a case, we sell the last cool that was sent in. So we call center called Function onder if a new signal had come in. This is where we store that code for later playback where you press a button. So that's it. That's our i R. Record program. 8. Infrared Repeater Project with Arduino: Let's take a look at the I r. Repeater sick of Bagram. So as we've seen before, we have all IR receiver was one been connected to five volts. Other to ground on the signal, pent up in in leaven on the Arduino. Next we have our early D with the cattle grounded Andi the honored connected via a to 21 resistor to Penn three on your greenoe. Next, we include our three push button switches. One end of each of the terminals of the switches are grounded. Other end of the first switch goes to Penn four on the ed. We know. Second switch goes to Penn. Five on the third. Goosed up in six. Of course. We have to connect the ground pinned to the ground rail only bread board. And the five will spin to the five bulls on the bread board that completes the wiring for our I R repeater circuit. Okay, now we're going to make the changes needed for our i r repeater sick it to finish up our project. We're gonna add in the extra two switches. So if our next switch reeling about Anna's close to this second switch is possible I remember one end of the switch was the ground. All right, So I will actually make a small jump year to this white wire which goes to ground. So just gonna these two switches together, All right, That's essentially to seem ground connection. The other end of my switch would go to Penn four on your Amina. So where'd make that connection now? Include the other switched the final switch again when in about switches grounded. So I will ground back on again. I'll go back to that seem ground pin as the other switches used. And the other end of that switch who's been fine when you're, you know, all right. And we have to make a small modification from our food. Sick it. That initial switch was going t o pay 1200. We know we're gonna move. That depends. Six on your All right. So I know it's a little bit tight in there, but that completes our wiring onda its compact so that we could actually use it as a remote on real demonstrate that shortly. Okay, now, who had an upload? The code for our infrared repeater circuit? As that's done, go and open up the serial monitor and with our circuit were able to record upto three infrared signals. So I'm going to use my remote here, and the 1st 1 is I'm gonna record the power button to turn the TV on and off. So I'm gonna push that as you notice It was received on the circuit and I pushed the first button associated stored on now associated with the first button. Next, I'm going to record the volume up button. Someone oppressed that, and I'm gonna top on the second button. So as you can see, you know, if I press on it and I tapping a second weapon, it's storing and associating with that button. And then finally, the volume down. I'm gonna record that signal someone pushing that and I'm going to record that volume down associated with my, uh, third Buccaneer. So, no, I should be able to play back these signals. So if I, you know, press the first button, you see, it's sending the first power signal that I recorded. This one would be the volume up, and this one would be the volume down. OK, so, um, one thing to note is the way that our second works is if I remove power. So I'm going to disconnect my Arduino here, right to remove power from a circuit. We are actually storing this an e problem. So now I have no power applied to the circuit. All right, I'm going toe, Um, because off my cereal monitor, I'm going to apply power again. Okay. Onda opened back up Thesis aerial monitor here so that you can see it, Onda. Now, if I press the first button, all right, I still have that power signal stored, and the second is volume up. And the third is William down. So very cool about our project. And it wouldn't really be a good removed if we couldn't store it right. And if we lost all of our information when we removed power. So what you can do is if you want a power, they are green or remotely here. I have Ah, a battery on the connector. Um, So I'm gonna connect this here. So my battery and I'm gonna plug this d c borrow Jack into our Arduino. And that's what we can use the power are doing are remotely onda. We will demonstrate how this reboot actually works to turn the TV on enough. So here I'm connecting the actual battery to the Arduino, and I'm able here to power mired. We know remotely as this concede it's on, And, uh, we'll show how this can be used to turn on TV on and off and actually turned volume up and down. Okay, so now I'm going to demonstrate to you how our infrared repeater sick it works. So this is our repeater, and I am going to point towards the TV, all right? And the first button here is which I associated with Trinity TV on and off some. When the point this infrared led towards a TV and press it on, that should turn the TV on. So we'll go ahead and do that. No. So here we go. All right, so our TV comes on. All right. So now I'm going to change the volume on the TV, and I can use these to other buttons that I have associated with telling volume up until evil him down. So he will go turn the volume up now pointed towards the TV and press it turn the volume on up. All right, so Now the volume is up. I want you to try, right? And that'll Jozy of a button to turn the volume down. So I had associate ID. This button would divorce him. The three button someone appointed to the receiver to the TV. So when appointing to the TV and turn the volume down, here we go beginning to feel your islands. All right, so there you can see the volume is going down and I'll put it up again. So again, point this towards a TV point. The i r towards a TV press it, and here goes, DeVore him coming up. All right, so, no. And then I'll do down again from three. You will be in a state of complete relaxing. Okay, so the i r our i r e Peter was able to store the signals that we passed in and is able to turn the volume up and down accordingly. And we can record any other signals on our remote and play them back to the TV. We go. No, I'll go ahead and turn the TV off. So press the power button and here we go. So it all works. Let's dive into the cord for our infrared repeater project sewn it up. We include a few the body libraries. We have the IR remote memory and he bounce to library and another library. And we include is the E Prom Library that comes bundled with our Drina for writing and reading to the Ebro. Next with the firing. A few global variables are Receiver Pin, which is connected to an 11 on your demeanor and the start of spin connected depend 13. Next, we have our buttons. So the those air connected Ben is 45 and six on your wiener. We will incorporate the bunts library here to accurately detect when we push on buttons for transmitting IR signals and storing our signals. So next Winston, she at the barn subjects. You've seen this previously in Sun projects that we've done next. We said that the IR receiver and the iris en as well as our record results global variable results, as we have seen in the last project in order to store an associate. Readings are recordings. We created a structure here and that Struck has several different properties. We have the code type. He could value the world chords in case we have to store on unknown IR signal that doesn't conform. Nearly prettify ing remote the court length on the tuggle, which is the r C 56 double state, and we create a view of these instruct variables current recording. And then we have recording 1 to 1 tree, which are associated with each of the three recording. If you want to store next a few other variables, we wanna record what the last button state is. The button states onda a bullion of recording complete, which will use for that envelope, you know, set up. We started receiver on. We set the status spin as output and for our push button switches, we enable the Internet pullup resistance. So we do that for buttoned one button to one, but in three and then we have touch the but independence that he appropriate. The bones objects. So here we do. But pending bond but had been, too. But it's been three next and set up. We also do a get stored recordings, so I'll jump down to that function and with get store recordings. This is where we use e prone. So the meat things that simpler. We're seeing an e prom. We're calling the get method on e prom. That's objects, and we're seeing to start from memory Location zero, and we want to please. Whatever we receive into the Ari Seaborn instruct object also retrieved the second value that restored from memory location 301 to start out in the Ari seat to object. And then, finally, we're getting from the member location, starting in 600 storing and policing that into the R E C three global variable object. That's to get stored recording next to looking at a few of the functions and we've seen before store code. This is exactly the scene, as we have seen previously, essentially takes in a reference that results object and stores the cord when a signal is received. Senator Cord as well that is the subject of what we've seen before. It simply sends a cold out so basically differences. We have modified this function a little bit to take in and recording the structure, and in here we use that variable that we passed in on. We send the appropriate code of back out, so that happens when B button is pressed. One of the buttons on our circuit suppressed, and there's a court associated with it. It's said tobacco. So when are you function? We update the pounds instances for our push button switches, and we take a reading from those demands objects. If recording completeness fools, here is where we want to check for press buttons. So essentially, if the signal was received and we have not yet started. This is where we wait to see which button was pressed to assign that signal to that button . So if the recording completely will bearable this false meaning, it has been stored. Yet we check to see if the amounts of one girl that was pressed one associated but one else if it's to associate with. But but to or if it was but three, that fellow was pressed. We suceed with button three. If a recording is complete, meaning else, that else part of that. If Jack, Then we went to transmit a signal. So, basically, if the button one state is low, that means but one express we transmit for button one and then similarly, for Button two and three re transmit those signals accordingly. If the buttons were depressed, we have to re enable our receiver. So that is one caveat with the the I R library is that we have to re enable the receiver, you know, after we receive a signal. So that's what we do here. We enable I r n recall that weapon on the I receive object. Also, we're checking to see here if on IRAs signal was received. And if that's the case, we're going to store that code on wheat for the appropriate but impress to determine which button that we need to associate with that store coat. Just a couple more functions. Movie ready, transmit for button. So essentially it takes ah, button as an argument on if it's one, we are going to send the cord of four. The boost for the first instruct already first are received one variable that we have else if it's but to do thes second, structure the food. It's the to instruct, so that's just used to transmit the cold. For whatever button we associate ID with the particular data. So next we have the associate with button function again, it takes a button. So if you know Button was one, it would associated card recording what er received one struck objects, if it was to the 2nd 1 was traded. Thing one and so one set store recordings is where we write to eat from. So instead of doing and get, we do e from put passing in the starting memory location and what we want to store. And then we do a Hebron put 300 passing in the second instruct or the second recording Onda Memory Location 600. You pass any food recording. These are just arbitrary. So he used the normal location. 0 306 100 You're just not picturing memory locations, Andi. That's where we decided to store any particular recordings. That so that's it. You mean benefits here Is that restoring the actual recording and you Berman retrieving it from the air that we, you know, it follows you move from the circuit. It would always be associated in memory on the Arduino. So then you haven't Let's take a look at the documentation for you perm from their green a website. So here you'll see all the different types of functions that could be called on that e prum object. So the ones who were doing specifically are the get put. So I'm just quickly click on there so far the get yeah, you see, call the e prime, not get passing any start address and this is a variable. We want to store what was retrieved from the department on. That's what we did in our project as well. Um, for the put here, it's similar to get, except you're going to specify again the memory location that you want to start at storing your variable. And here is what we we went to store the actual variable went to store. So that's the difference between getting reports and get to retrieves and put actually saves. So that apron, you know, is basically only Michelangelo. They have about 512 bytes of any problem, and that's memory, whose values are kept when the board is turned off. So you can think of it like a tiny, very small, hard drive that we can store some information not a whole lot of Skase, but nevertheless, it's useful if we need toe persists some information, even though the Arduino is turned off. So that's the documentation for the E perm. Hopefully, it makes it a little clearer on how it works and how we can use it to summarize. And this project you learn how I are received was work and I are led is work. You also learned how to connect them in a circuit. You learned how to incorporate the IR remote library to store on the playback IR signals and how e prom can be used to store information on your Arduino that has persisted even when the board is powered off. Infrared is an easy to use wireless communication technology that you can incorporate into your projects toe allow you to remotely control your hardware components. You now have the knowledge on how this works and can inexpensively make your projects wireless. Let's move on to the next project. 9. How a Joystick works with Arduino: In this project, we will learn how to incorporate a thumb joystick in your electronic circuits. We will be building a game with the joystick on an eight by eight metrics. Led the object of the game is to capture the falling balls. If you can do that within a specified time, you win the game. You will also be introduced to the max 72 19 dot matrix module, and we will leverage a couple third party libraries to help us control our eight by age led matrix. This project is going to be a lot of fun. Let's take a look of the objectives. By successfully completing this project, you will have mastered the following items. You will understand how to connect and take positional readings from Ethan Joyce taking a circuit. You will also understand how Imax 72 19 dot matrix module can be used to help control on eight by eight led metrics. And we will also see how some third party libraries CA NBI, used to help make controlling our led matrix Much simpler. If you are ready to begin, let's get this project started. Yeah, the parts we will need and I will. You know, USB cable, a bread board, a thumb joystick. I need it by it. Led matrix display E max 72 19 dot matrix module and connecting wires. Let's for this address. The operation of a thumb joystick. This is a very hunde component for your electron ICS projects. It can allow you to control servos motors or basically any component where you'd want to control movement. Emotion. The joystick typically has five pens. The ground pin will be connected to ground. The plus five volts, like its name implies, will be connected to the five gold pin on the Arduino. The vrx and we are y pins or horizontal and vertical pins are used to measure the horizontal and vertical distance moved by the joystick. Analog readings off voltages taken at thespians having value in the range of 0 to 10 24. For example, if the joystick is all the way to the left or the horizontal open or vrx might have a reading of zero when it is in the middle position, the reading might be 5 12 and when it is all the way to the right, a reading taken might be 10 24. Thus, you can pinpoint the horizontal position of the joystick by determining the value in this 0 to 10 24 range, and you can map that accordingly to the position of your servo or whatever directional component you want to control. A similar principle also applies to me, v. E. R. Y, or critical. In order to determine if the joystick button is pressed, the select been could be used. If you're reading Taken of this pin was high, the joystick was pressed. If it was low, the joystick was not breast. Now we will look at the marks 72 19 module and more detail. This is a hunde hardware component that interfaces to your eight by eight led Matrix B hardware, coupled with 1/3 party library for the marks 72 19 makes it easy to accurately light and displease any individual led or patterns off ladies on the Matrix. The max 72 19 also makes it possible to daisy chain several led metre seas together to make a complex display. In order to communicate with the led metrics. The SP I or serial peripheral interface protocol is used This is a synchronous serial data particle used by microcontrollers for communicating with one or more peripheral devices quickly over short distances. It can also be used for communication between two microcontrollers. We will need to connect five pins to the Arduino. The C C is connected to five volts on ground is connected to ground D. I n is connected to pin 11 on the Arduino, which is the master out Sliven used in SP I communications Onda VCs Spin is connected to the slave select pen 10. Finally, the clock pin is connected to the serial clock which has spent 13 on Arduino. We will use to third party libraries to help us communicate with the led metrics by the max 72 19 module. These are the marks 72 xx pattern library On the other foot graphics library. We will see these and more detail when we look at the code. Let's take a look at these sick. A diagram for basic joystick operation in this circuit will just be looking at how the joystick interfaces with Arduino and how we can take measurements to determine the position of a joystick. As you remember the joystick has five pins on BCC is gonna be connected to five volts on your do we know Then we have the VR Y connection that goes to ah, analog. Been a zero on the road. We know that measures the vertical direction of the joystick. The next connection is ah, vrx. That goes to pin e 100. We know, and that measures the horizontal distance of the joystick. The other pen determines if the joystick is pressed or not. The select pin that is connected to a 200 Reno and finally be grown pin is grounded on the Arduino. That's the wearing for our joystick circuit. Okay, let's go ahead and wear for first circuit where we will see how we connect the joystick to be Arduino. This is the thumb joystick. As you'll notice there are five pens. We have the 1st 1 being grown. Then you have the fables. Vrx measures the horizontal position and you have er why and finally the SW pin or the Selectmen will tell us if the thumb joystick was pressed or not to make things a little simpler in order to perform the connection with the joystick, I have some female to meal connecting wires. He's actually come in pretty handy because they can just connect directly to the header pins on our joystick. So go ahead and connect those. It was three, and they want him to, right? So, no, that's a nice ah, solid connection. And the end of those pins are meal header pins, so this makes it convenient. Okay, so the the first pen ground, which is the green pin, goes to ground. I'm just connecting it to the ground, really only bread board. The second thing is the five will pin, which is a yellow pin. Connect that today. Positive riel. The vrx goes to a one. That's how orange wire here goes to E one on Neared. We know make that connection. The V e. R. Y goes to a zero. That's the red wire. And the select pin, which is the last one burn wire, goes to a to so me that connection here. Okay, So with that being connected, I'll just go ahead and connect the, uh five bull certify bulls really only bread board from married, we know. And then under the ground to the grown real. So that completes the wiring for our joystick. Okay, let's go ahead and upload the cord on opening cereal monitor. So as he can see, the joystick is currently in the middle. Onda, um, you'll notice the vertical measurement is 5 25 on the horizontal is 5 11 That's about the middle of 10 24. So now I'll go ahead on and let's move the joystick all the way to the left in the horizontal motion. So if I take it all the way to the left, you'll see that the horizontal reading changed toe one. All right, so that's the only way to the left. Now I'll move the joystick all the way to the right when you see the horizontal reading change to 10 21. Okay, so by moving the joystick left and right, I'm able to get, you know, values within that range of 12 10 21 I'll be able to tell the position off my joystick in that horizontal access. Let's just take a look at the vertical axis snow, as you'll see right now, it's currently at about 5 25 and that's in the middle or rest position. When a push the joystick to the top. Only way to the top. You'll notice the vertical reading goes to one zero and one about approximately. And I'm gonna push the joystick now all the way down to the bottom onion. See, that political reading goes to 10 20 or so for the actual pressing of the joysticks. And now you can see that select is not pressed And with the press in and there you see the pressed showing up in winter release it, gonna see, not pressed again. And when I press it again Annecy depressed showing up. So we're able to ah, take readings from, you know, individually any position on the joystick and we can use that to determine you know where the joystick is. Onda We can control the movement off another device connected to the Arduino based on the position of our joystick. Okay, let's take a look at the code for our joystick operation. At the beginning, we simply define and to clear a couple of global variables. So for the vertical, it's clear as a constant on that's connected to bin E zero on the Arduino. The horizontal pin on the joystick is connected to been anyone on your team, you know, on the select pin is connected to pen A 200 earned Guido next in our set up function. What we are essentially doing here is enabling the pull up resistor on that select pin. This was an older way of doing it s so he couldn't do pin Mood Select specified as an input and then to a digital right to the Selectmen specifying a high value that would turn or not pullup resistor over. Alternatively, we could do the pin mood select and then we pass in input pull up as the argument that would accomplish the same thing. Next we set up the speed for the serial communication. So this is syntax you've seen before in the loop function. We have a couple of variables that we want to capture and store the position of the joystick. So we have vertical horizontal and select. Next, we take readings for those variables. So far, vertical. We do an analog read on that vertical pin for the horizontal. Similarly, an analog read on the horizontal open and on select. We do a digital read on the Selectmen because we just want to determine if it's a high or a low. It will be high if it's not breast on boo if the button is pressed next, we simply print out the values of those readings to the serial monitor. And that's how we're able to see those values for vertical horizontal onda for the status of the select benefits. Pressed or not, that's our code, very simple and very straightforward. 10. Configuring an LED Matrix with a Joystick in Arduino: Let's take a look at the circuit diagram for including the led metrics in our project. The joystick connections remain the same as in the previous circuit. Now we will add in the max 72 19 dot matrix module that's part of the circuit. It has five connections. The first been, which is five wolves, or BCC, is connected to defy bold Rio on the bread board. The second pin, which is ground, is connected to the grown real mixed. We have the D in pen or data in that's connected to 10 11 on your Arduino. Then we have the sleeve select Been, which is connected to pin 10 on the Arduino. And finally, the clock is connected to Pin 13 which is a serial clock on the Arduino for SP I communications. Those are the only additions that we need to make toe a previous second. Okay, let's go ahead and make the appropriate modifications to connect our it by eight led matrix . This is the max 72 19 dot matrix module. As you can see, we can plug the eat by it led matrix directly into here. Let me disconnect it so you'll see what it looks like. Okay, So, essentially, on the right hand side, you'll also see, you know, the duplicate of dependence that only left and that so that weaken daisy chain one module toe a next control multiple or several. You know it by eat Mitrice's So that's very handy. And this module enables us to control a myriad of multiple Oh, led Mitrice's. So why didn't connect that back again on the left hand side? As you notice there, five pins. Oh, you have VCC ground data in this little select on the clock. Okay, Just like the joystick. What's handy is on this particular device. You have these pins that are sticking out. So we have What makes it easier is if you have these female to meal connector pins, that makes it easier to get everything worried up. So in this kind of connect blues back again, it's a Let's I was three and in 45 OK, those are no securely in place. All right, let's begin wearing up are sick it so first the re vcc goes to fables. So I make that connection. The vcc is my yellow wire here going to connect not to fabled. Then we have our ground or black wire here that goes to ground. Next, the data in goes to pin 11 on yard. We know. So that is my pope in here goes to Penny Leaven. My Steve Select goes to Penn 10 on the Arduino. And finally, my clock goes to Penn. 13 year. Do we know three? That's it. That completes the wiring for our eight by eight led matrix. Okay, let's go ahead and upload the code to demonstrate how the joystick works in conjunction with our eight by eight led metrics. So we'll upload that joystick led matrix operation program. So go ahead and do that. Okay, so now that program is uploaded, What you'll notice is the dot is being lit at the middle around the middle of our ah, led matrix. And now, as I move my joystick around left, you can see that it dark moves around. I'm going down. Up. Right. Okay, So I'm gonna move in a circle, and as I move my joy stick around. What we're doing is we're mapping that, detecting that Ah, position that X Y position X Y coordinate for where the ah joystick is and we are lighting the appropriate led on our it buy it led matrix. This is pretty cool. So it shows that, you know, with fine green control were able to determine the exact position of the joystick and were able to use that to affect some other external part of our circuit. In this case, we're using that information toe light. The appropriate led in that grid that eat by eight metrics led cred. So there you have it. Let's take a look at the code for our joystick led matrix operations circuit. So at the top, you'll notice that we have to include a few libraries, and a couple of them are third party libraries. The 1st 1 is the SP I Not age dot cereal per froze interface communication library. This is included with the Arduino, so you know you don't have to do anything special to include this. The next one is the out of fruit graphics library. Andi. Then we have a library to interferes with Thea Max empty to 19 panel. So for those particular libraries, I will include the links for you to download those libraries, and that's part of the resource is, but just to ah show you here is the link to the other food graphics library on. And of course, you We know when you get here, you're gonna download the zip file. Well, I wanna say that to my desktop, right? And then the, um max 72 19 panel library again when a download that zip file on going to see about to my desktop and from there, remember, with Arduino when you go to your preferences, you want to install those unzipped libraries to the library's folder. That's indicated in your sketchbook location. So let's go and do that. If we unzipped thes remember, you'll have to rename that library take off the master at the end of it. The dash master, um, so renamed those folders and then you'd want two copies and for specifically for me. Um, it's in my documents are do we know libraries? And here it is. So, as you can see, they have those libraries in here already. But this is where you want to place them in Ondo for you. Irrelevant path would be indicated by your preferences. You convey that sketchbook location cop your libraries here on restart your Arduino right to eat. Okay. So with that being said, next, let's continue on with the code review. We set up a our select Steve Select pin, which has been 10. We define a couple a global variables the matrix, X and matrix. Why variables. The's air used to pinpoint which exact led. We want a light. Only our it buy it led metrics. Next we create the matrix object for which is a max 72 xx panel object. This, of course, we would get this object code from our library that we included. Let's take a look at the documentation for this. We have to foods pass in that, um you know that pin that we're selecting for the device and next we pass in a one on the one, which would be the number off vertical or horizontal. This, please. But we quickly dove into the documentation here. I'm gonna open up the heather file so you can take a look at the code for that constructor for that object. So, as you can see, it takes in a pin for selecting the device, which is anarchy. Said I could tend and next week in passing the number of horizontal this, please on vertical this, please. So remember, you could DZ chains several of these, you know, several of these it by eat Metrics LTD's with the different panels. And decode accommodates for us to connecting multiple different configurations and to be able to write to them. So in our case, we're just using one. So we have one horizontal display, one vertical display. Okay, so don't go back to our code. So we set up our metric subject. Then you've seen this good before. Here is for a joystick to vertical horizontal and select pins. I'll move on next in our set up function. We, of course, tune on that input pullup resistor. We've seen this before, and here's where we set the intensity of our metric. So this is how bright we want, Ah, remedies to be, you know, displayed. I have set a value at five, and then we begin the serial communications so continuing on into our loop function. You've seen this before. We get the political horizontal and select found use for our joystick. And here when we get those values, this is where we begin the process of mopping was values corresponding led on our metrics. So we do. Ah, metrics. Why the position of the Matrix? Why? I want a map. The political value that we read in on it primarily is in the range off 5 to 10. 18. Remember, it's really supposed to be 0 to 10. 24 but you give ah little margin of error there and we want to mop that into a range of 7 to 0 because we address a specific you know value of ah, why that why access has to be in the range 0 to 7 sentence. An eight by eight metrics led, um, the index difference in next starts at zero. That's why goes to seven, not eight. Similarly, for the exposition, we want a map that horizontal value that we you know, we got in and you want to mop that in the range with again. We're specifying 10 18 to 5 and we're mopping 0 to 7. So that would mop the correspondent X value in that range for us. And then the next thing we do is we clear our screen. So using that matrix object, we do a full screen passing in zero That would clear off screen for us. Onda. We also with the scary output on the serial monitor. This is more informational purposes. You don't necessarily need this, but it's good for the bugging. If you wanna see what day X and Y coordinates are, we didn't proceed to draw the actual pixel, so we'll pass in the, you know, the X coordinate on the Y coordinate. Remember, those values will be between zero and seven Onda. We set the value high toe, actually tune that pixel on and to finalize that we do a metric start, right? That actually turns it on on displeased that pixel. So that's this is what you need to actually set the sandy but not to display on this would show the position off our led. We include a small daily Onda. Then we actually here is this is some code that is left over where we could detective, the joystick was pressed. We aren't actually using this as part of the Ali this plea, but, you know, you could, um, you know, you can incorporate some logic here. Maybe you wanna send a message? If it's, you know, pressed what have you this quarter. Still in here on this, you can respond to ah, button or drastic presses in your code, and that's it. Eso Fairly straightforward again, We need the out of Fruit Graphics Library, which works in conjunction with the max empty two xx panel library on. That really makes it easy to write Teoh any led or patterns of any allergies on the IT by eight metrics the spree. 11. Joystick Matrix LED Game Project: to complete our project. No food for circuit changes are required. He's sick. It remains as it was from our last lesson. All right, so now we're gonna upload the code for our juristic led matrix game. Let's go ahead and do that. Wait for that to complete. There it goes. Okay, so here we go. So as he couldn't see, there's a falling ball on. If you don't catch a ball until it reaches all the way to the bottom, you'll see lose that lose message. So I'm gonna move that. I'm sort of moving a, um, platform that's catching the bulls, who, as you notice we're good on. If I If I can do that for 10 seconds, I'm a winner. So the game spells winner. And if the ball falls will lead me to the bottom without me catching it, you'll see that lose message. So I'm gonna try to win one more time. Here we go. I'm moving my platform to catch the ball, all right? And I want so we could make it a lot more difficult by tweaking. You know, the time that you have to continuously catch the ball and code, we'll see that when we dove into the code. But essentially we're able to used the I'm joystick to move that platform around in our game to catch our bowl. So we'll take a look at the specifics off. You know how we can treat those settings and cool and how this all works together. But this is a really cool game on. You can change the difficulty level to make it even more fun and exciting. Very go one again. Like some of the other games that we have developed. This one is also highly addictive. Okay, let's take a look at the code for our joystick. Led me tricks game. You're a few modifications to what we have seen before. Remember, we're continuously building on our previous projects. The first major changes. Ah, in addition to the libraries we had included before, we're now going to include a stop watch third party library, and that helps us to keep type. Um, let me show you the documentation for lead library. So this is the link to the library itself. On get hub. I will post the link in the resource is for the project. But again, when you come out here. You just download the library on. You'll save it to your libraries folder in your sketchbook location. It's the next. Continue with the code review. We've seen this before, where we have our select a pin set up to 10. We externalize the number of horizontal and political this crease in the variables. Previously, we just had 11 but I put that out there toe, make it a little more self documenting. We create our metrics object, which is a max 72 xx panel object, then continuing on. We have a couple of other variables. Just the length is you know, the X and Y coordinates. They go up to eat and we use a couple of pointers, which we'll talk about those a little later on for the joystick we have to keep track of you know what the current position of the joystick is and what the falling position off the actual ball is. So we have some variables that do that. Onda and of course, this proteins to the joystick leave critical horizontal and select reading. So he said, those up those pins, their vertical. It's been zero easy zero, I should say, for the horizontal is a woman on the selected z2. Next we said of the stopwatch object. So this was from a stopwatch library. What you were specifying here is we're initializing lee stopwatch and we're seeing that we want the timing token. Second, So a couple different options that you can use and you can you look at the documentation for that library. But we're using seconds. The next variable is timeto win. Ondo. We've set at us 10 seconds. He is where you could increase the difficulty level. So if you want toe, you know, have someone continuously catch the ball for 20 seconds or minutes. You can change that accordingly. To increase the difficulty level of the game in our set up. There's some cold we've seen before. This is Ah, this section might be new. It's just resetting variables that will be using for their on Onda next to me for the joystick. We've seen this set up before where we enable the input pullup resistor and then we start our game. All start game does is it's resets our clock and starts to crack again. So that's the initialized. The clock from ah, stopwatch slavery. Okay, Let's look at the loop loop is very simple. We have a function called pregame dove into that, but essentially throughout the loop process. Remember, this executes over and over. If these time that has elapsed is great and any time the win meaning that 10 seconds or whatever you set up initially, um, for the timeto win, then we call the winner function and winner. Simply this, please, that a schooling message will on the screen. So I'll go down here toe winner. It would just, you know, draw that text win, and it stretched the game over. So as faras, the displaying of the scrolling text on display of text on the screen, there are few functions that we can use that leverage d the Max panel library. And here they are. He simply pass a string instead, and it takes care of during the text on the led matrix to Jordan schooling text. You can use this function, Um, you simply passive texting, and it's gonna screw all that text across the screen. So too handy convenience functions for you there. So let's delve into play game. This is where all the magic happens from our loop function. So let's look at a pregame function. What we're essentially doing here is we're get generating a random number off the Y axis. We're starting. So that's where the ball initially starts from. And we continue deck remitting going down and during the pixel as the ball falls. So that's what they look. Function comes into play where we're drawing that pixel. It's in one spot. Then next the drops to the spot below and so on and so on. During that time, remember, the joystick could be moving. So we call this century stick position in order to draw where that platform is. So I'll take a look at that shortly. Um, but then, um, next week continue during our pixels on, we determine if a collision has occurred. So when the collision has occurred, that means the platform has caught the ball also at the bottom. If we continue going on, if I Z equals the seven, that means you've reached all the way to the bottom. The ball has reached all the way or the current will. That led pixel has reached the bottom of the screen without a collision occurring. The in you didn't catch it with a platform. The game is over, so he called the game of our friendship. So let's quickly look at Thea set joystick position function. Essentially, we are doing a reading like we've seen previously of the vertical horizontal positions. We're performing a mop the drawer dot on the screen. And remember, for the joystick, it's our platform is three sort of pixels, or LTD's wide. So we have to add on Teoh either say, that's where down in this draw pixels. Uh, that's where down in this area, we draw the pixels and we increment on deck. Remit the current position so we can make up platform three pixels wide. We also have to keep track of that platform, will keep track of the, um, current position of the platform. So that's why we said those global variables. All right, so the game of a function is, um, pretty straightforward as well. We just, you know, draught. That text moves to the screen and we start the game over. Finally, the main ah function, which is the collision occurred basically what this is checking. This is checking for epic current position off. Your platform is, you know, at or below the position of the ball. What a the current early didn't Smit? Then it returns. True, but if collision occurred is true, we continue on with our game. If collision occurred is false. When it reaches alter, the bottom game is over. That is quite a lot of cool in this particular program, hopefully have broken it out for you to be modular. So the you know you can understand what the different functions do, but I would encourage you to take some time and, you know, look through the school to become familiar with how it works, and you can also tweak it to change the game. According me as you see fit to summarize in this project, you learn how to use a joystick in your circuits and how to take readings that can be used to control the position of components in your projects. You're also introduced to the max 72 19 dot matrix module, which can be used in conjunction with third party libraries to control your it by eight led metrics. You now have the knowledge to include these two components in your circuits. Let's move on to our next project