Arduino Bootcamp : Getting Started with Simple Projects | Lee Assam | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Arduino Bootcamp : Getting Started with Simple Projects

teacher avatar Lee Assam, University Instructor, Software Developer

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

18 Lessons (2h 43m)
    • 1. Class Introduction

    • 2. Welcome Message and Helpful Tips

    • 3. Introduction to Arduino

    • 4. Installing the Arduino IDE

    • 5. An overview of the Arduino IDE and how to upload code to your Arduino

    • 6. Understanding the Structure of your Arduino Program

    • 7. Installing Additional Third Party Arduino Libraries

    • 8. How to Use a Breadboard and Basic Wiring Concepts

    • 9. Let's create our first project

    • 10. Helpful Programming Concepts - Part 1

    • 11. Helpful Programming Concepts - Part 2

    • 12. Controlling an LED with a Push Button Switch

    • 13. Controlling a Piezo Buzzer with a Push Button Switch

    • 14. Using a Potentiometer to Adjust LED Brightness

    • 15. Controlling a CPU Fan - Part 1 - User Input Control

    • 16. Controlling a CPU Fan - Part 2 - Button Speed Control

    • 17. LED Reaction Game - Part 1 - Interrupt Demo

    • 18. LED Reaction Game - Part 2

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





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. 

Meet Your Teacher

Teacher Profile Image

Lee Assam

University Instructor, Software Developer


Hi, I am Lee Assam. I bring to the table 18+ years of programming, development and IT experience. I have a Bachelor's degree in Electrical and Computer Engineering and a Master's Degree in Computer Science.

I teach at Universities on topics ranging from Software Development to Electrical Engineering and prototyping. I like coming up with new ideas and prototyping them using the Arduino and Raspberry Pi platforms.

My passion and hobby is Arduino and the Internet of Things. I have been playing around with the Arduino and the Raspberry Pi platforms since their inception, and I use my Electrical Engineering background coupled with software development skills to create and develop exciting projects. I prefer a hands-on, project-based learning approach and use my teaching backg... See full profile

Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Class Introduction: here. - Hi . Welcome. Tired, we know. Put camp raining through projects. This is a hands on projects based up towards 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, electron ICS hobbyist out being clean around and tinkering with the Arduino platform since its inception. And I even teach university classes about this course is meant to bring you quickly up to speed on our greenoe. 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 came 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. You can advance to the Intermediate Projects section, where we will focus on making game type projects. For those confident of doing folks, you can jump to the advance 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 with information on will make a remote control car that you can control our smartphone app and open source for unlike other Arduino courses on you. To me, that only show you the basics of how to use components and sensors with Arduino. 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 hobbyist, 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 and teach you to be a confident maker if for any reason at all. You do not love this course on the content, I stand behind you dummies. 30 day money back guarantee you can get your money back. No question. Dust Ah, what he step by step through all the electron ICS principles involved in projects were making show you exactly how tow wire up the 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 Reno. And I look forward to being your guide on this journey. Come join me in the Arduino boot camp and let's work together, toe rip our Reno skills into shape. Can't wait to see you. 2. Welcome Message and Helpful Tips: welcome to the Arduino boot camp course, learning through projects where we're going to whip your Arduino spills into shape Amalie s , um and I'll be instructor on this journey. You'll be learning a lot about Arduino and building some cool projects in the process. Here are some tips to help you successfully navigate this course. If you're circuit does not work, you need to double check your wiring on. Check it again. Most of the times issues and circuits are due to wiring problems. I even make mistakes sometimes as well. Check on the tea one e on the course for questions and answers that may have already been asked and answered that will quickly get your resolution for a problem. If all else feels you can send me a message and I'll get back to you, be patient is gonna be a lot going on while we're working on a project metrical components , hardware, software and they all have to play together. I always explain electron ICS principles about the components were using in the project, so you understand how everything fits together. The projects are self contained, so you don't need to buy all the parts of ones. You may decide which particular projects you want to focus on and by the parts that are needed for those projects. And the parts list have also put a list of parts by project to make things easier for you so you can plan ahead. Remember, we're going to be learning about important concepts and electron ICS on the Arduino platform. But don't forget to have fun while you're doing it. Let's get started. 3. Introduction to Arduino: before we begin our journey into the world of Arduino. But let's talk a bit about the Arduino platform so you can have a better understanding of what it is and how it works. Aren't we knew is an open source platform. What this means is that it's designed Leo, and structure can be manufactured on improved upon by anyone. The main benefit of a product or software being open source is that many individuals contribute to making it better on the collective knowledge of different folks. Working together contributes to consistent improvements over time, resulting in higher quality. By prototyping, we mean that it can be used to rapidly build and prove out ideas for animatronics projects . The Edwina can also read inputs such as light from a sensor voltage differences temperature changes, etcetera and convert these measurements into an output, performing tasks such as activating a motor, turning on an led and even publishing a tweet out to Twitter. It is easy to use for beginners and can be used by electron ICS, hobbyists, makers, Internet of things, engineers or even entrepreneurs as a means to quickly try out their ideas. Essentially, you can tell your board what to do by sending a set of instructions to the microcontroller on the board. Let's quickly take a look on the Arduino website. You can find the website by just typing in Arduino and doing a Google search on it should come up. It should be the first result. Similar. Click on you're doing a home on Dhere Is Thea Arduino mean website here You find a lot of information about the Arduino platform. See projects book by others Get tutorials on learning Resource is on the network with other makers. The version of our do we know we will be using for our class is the Arduino Uno. It is the most popular flavor or do we know you can think of it as the basic model on it has the following characteristics. The board is based on the 18 mega 3 28 p microcontroller onda When we see microcontroller what we mean here is It's a small computer on a single integrated circuit containing a process, a core memory and programmable input output peripherals. It has 14 digital input output pins. These ey're located here On the right hand side of the board. There are six analog input pins located on the left hand side of the board. It has a 16 megahertz quartz Crystal Onda 32. Key of flash memory. Um, as you noticed, that is a small amount of memory, so we have to be always concerned under be mindful when we're writing are we know programs to consider of memory as much as possible. There's also a USB connection at the top that we plug into our computer in orderto Upload Co. To the Arduino under the D C. Power Jack that can be used to provide additional power to the Arduino Micro Angela. The operating voltage of the Arduino is five goals. There are many different flavors of Arduino, but as we already mentioned, the Arduino Uno is the vision will be using for this class. Another version is the Arduino Mega, which is a bigger board sporting more inputs and outputs and more memory capacity. This one can be used in projects that have moral bust requirements. Our Drina Gemma is a version of the platform that can be used for your wearable projects since this very tiny about the size of 1/4 Arduino Yun is a version of Arduino that has WiFi already built in for your Internet of things projects. This allows you to easily take your project in the wireless mood on enable network connectivity. The various flavors of Arduino can all be viewed on the Arduino Projects page from the Arduino website. Let's talk about how we actually use the Arduino. You will need software to write your programs in before they can be uploaded to the Arduino board. The Arduino i D E Shortfall Integrated development environment allows us to do this in a level lesson. I will be demonstrating how to install there'd be no I D and give you a walk through of how to use it. The code for do know programs can be written and C or C plus plus and must be compiled before they are uploaded to the on chip flash memory. To summarize, you should now understand what is the Arduino and be familiar with the Arduino Uno. You will also introduce to some of the other flavors of our do we know that are out there. You were quickly introduced to the Arduino website, which is a great police than get a resource is and information on network with other makers about dared we no platform. Finally, you should have a high level overview of the process by which court is uploaded to the adrenal to make your programs work using the Arduino i d. We will delve into the agree No I D and much more great deal. In another lesson, we are off the great start so far, let's move on to our next lesson. 4. Installing the Arduino IDE: the Arduino I. D E, or integrated development environment is the software that we need to use to communicate with our Arduino, typically in the i. D. E. This is where we write the code that's necessary for our project, and then we proceed to upload that code to our Arduino. The first thing that we need to do when you start off writing aren't we know programs is to install the I D. In this lesson, I'll show you the process of installing the early no i D. If we go to the Arduino homepage and click on the Learning Getting Started link. Here is where we can get detailed instructions on how to install the Arduino i. D. E for Windows and Mac. So first, let's talk about Windows. We'll go ahead and click on the Windows Link. This particular guide shows us in detail are we can install the Arduino I D on Windows. First, you need to actually download the actual software, and then this peach provides step by step instructions on what we need to do to install the I. D. I'll post the link to the Windows Installation Guide on the Resource Is Section of this video, but essentially, it's very straightforward. One thing that I would recommend is actually using the installer e x e file, as opposed to the ZIP package that just dream lengthy installation process and gets you everything that you need. Once you have installed the I D, then we can proceed to get going on our projects. To get the idea installed on your mark, click on the marks where sex link from the getting started page and here we'll get specific instructions on how to install the I. D. E for the Mac. Specifically, when you get the application, you condone drug it and drop it into your applications folder. They you'll see the Arduino icon, and that's what you use to double quick to start up the Arduino I d. Again. The mark process is very simple and straightforward. Go ahead and get the already installed, and then we can proceed to our next lesson. 5. An overview of the Arduino IDE and how to upload code to your Arduino: in this lesson, I will be giving you an overview of the artery. No, i D. Or integrated development environment, which is the tool that we use to write our Arduino programs. And also I'll show you how you upload your programs to the actual are doing on microcontroller. This program we're looking at is the sample blink program that comes preloaded with Arduino . I'll show you that in a minute and where those of the programs are located, but we'll use this for the basis of our discussion. If you looked at the top, there are a couple of icons here that are handy when working in the I. D. E. If this does the verify button. Essentially, what this does is it compiles are cool and checks to ensure that their new errors. So I'm gonna go ahead and click that button on your notice here at the bottom. If everything was OK, you'll see a done compiling message on. You'll see some information about the memory, how much memories use and how much memories available. So our program compare Aled successfully. Now we'll go ahead and introduce an error by deleting this semi cool in here so If we try to do a verify, you'll notice that down. Balu, Move. Get an error message and it's seeing that it's expecting that semicolon before the end of the curly brace. And typically it would highlight the lying around which the air occurred. So generally the I D tries to give you a nera message that helps you to understand what went wrong and how what you need to take on the action. You need to take the correct the issue. It's not the best at all times, but generally it tries toe, give you an indication off. You know what went wrong on how to address it? Of what hadn't put back the semi colon in there. Go ahead and do a verify again. Onda. No, everything is okay. The next button is the upload on. First, I'm gonna click on this button without connecting my Arduino, so I'm gonna click on it on your notice, tries to do the communication, but you get an error message now I have a Mac s O. The message you get if you have a windows PC or laptop would be similar. It's would say that it can't open the device on the particular USB port because it's not connected. So I'm gonna go ahead on the Connect the Arduino on. I will try to do that a blood again. Another issue that you may run into is that the Arduino is not being recognized the particular port for communication from the i. D. E. So to address this, typically, if you booted tools and board, the first thing it want to do is make sure that our do we know, you know, selected. And the other thing is you'd want to go into the port to check that the Arduino Lou Newport selected associated with the appropriate USB ports. I'm gonna select that occasionally you might run into this, but, um, once you address it and you correct it, you should not have to Oh, you know, run into that issue again. So there I went ahead, uploaded it. And now if you look at the Arduino, you'll see that a built in led is blinking. That's essentially what this program does. It simply sets up your pin 13 which is a built in led pin on the board as an all put it right said hi pauses for a second rights at low and imposes for another second. And this continues. So you're every Blix. Hence the name of the program. Blink. The other button to the left is new, so if you want to start a new sketch, you can click on that button and has they set upon loop functions already pre filled for you? It's you can start quoting. Then there's an open so open would allow you to open you know, existing samples or examples. Or if you have particular examples from libraries, or you wanna select a particular project from your file system. That's what opened its. And as you work through your program, you'd want to see if theoretically, this button helps you to see if you're program. Essentially, you can also do some of these some of the functions from the film and you hear you can open or save or close. And one thing that I wanted to highlight is the examples. This is where the built in examples can be found. Example sketches. So the particular one that I have looted here is the blink from the basics holder, and I encourage you to go through some of these other building examples because they do have some good documentation and give you an example of off some simple programs and simple sketches that you can use onder if you're neutered, we know they could be helpful as a learning tool. If you have a party libraries that are installed on in another lesson, I will explain to you what these are and how you install them here. You can find those particular examples if you have them loaded also from the sketch drop down menu here, you can also do your verify or compile your upload and so forth. So, um, again. But you can use these buttons here, or you can use the drop down menu. And also there are short, good keys, so that is essentially they are doing No, I d eat. Very simple, straightforward to on day. You will become really familiar with it as we continue our electron ICS projects in this course. But it's meant to be very, very easy and quick to start up on get you going into the code. So that's it for the Arduino i d. Again. Very straightforward, simple, easy to use tool you will become quite familiar with it as we progress through the course, but very, very straightforward Onda allowing you to get in their on right here. Programs for Arduino. Let's move on to the next lesson. 6. Understanding the Structure of your Arduino Program: Let's talk about the structure of an Arduino program. In this lesson, I am using the serval Sweep Example program that comes preloaded with her a greener and will be going through the various pieces of the program. Generally for adrenal programs at the top of the program would have some documentation. Usually there'd be some description of what the program is and what it does, and some other information around who created the program and maybe ill created on last modified date again, this is optional, but as you do your projects, it's generally helpful to have some documentation at the beginning of your program. Next comes include statements and these air used to include any libraries that we may be using this part of our project. You may be using several different libraries and third party libraries and Adams as part of your project and typically, at the beginning is where we include those libraries so we can make calls to particular functions, or it'll eyes variables the finals libraries weight around. Next comes the actual declaration of variables or global variables that will be using these air declared at the top of the program on and generally they can be used anywhere within our program. Next comes one of the most important functions that you'll seen any Arduino program. It's the set up function, and it's within the set of function, as the name implies, where we set up variables and we just prepare our program to begin execution. So if there is any sort of initial configuration or set up off values that we need to establish that is done, any set of function, it's important to note that a set of function is run only once, once we power up our agreement, next comes the other function that you will see in every Arduino program. It's the loop function. Here is where the meat of our program lies. And this is where we will execute all our logic around, you know, taking input readings, creating output readings or driving routers, or whatever the logic of our project is typically resides within the loop function on. And as the name implies, loop starts at the beginning. It runs towards the end, and then it loops again and starts and runs in a continuous fashion. So once there's power to the Arduino, this function looks continuously so to summarize for the structure of an Arduino program at the beginning. Typically, you'll see some comments that's followed by includes where we include our libraries that we might be using. This is followed by variable declarations for those variables that we'll be using throughout our project. Then comes the set up function, where we initially set up those variables and perhaps our program to begin hand. Finally comes the loop function, where we have all the logic, concern with ah project on and the specific functionality we want to perform and again loop runs over and over again. Once there's power provided to the Arduino board and a set of function runs only once. Know that you have that basic understanding. Let's move on to our next lesson. 7. Installing Additional Third Party Arduino Libraries: in this lesson, I will be addressing third party libraries in Arduino. Are we talking about what they are, how we use them and how we install them in the Aren't we know I d e If you remember in our previous discussion, we mentioned that our Drina was an open source platform. What this means is that many developers can create custom libraries, which referred to a student party libraries that package up functionality that is commonly used. This reduces the cool that we right in our own programs on is helpful in that we do not have to reinvent the wheel every time and can focus on solving the parts of our program that are unique. Project as an example in a project that we will be building meter on for a posibles again, there is a very handy deed bounce a library. It's for food to as bounced, too. Essentially, it helps us to determine when a push buttons, which is being pressed on, eliminates any the bouncing that might happen in the circuit. And we'll talk more about what that means later on. So I'm actually going to search for that library that aren't we know bones library. Onda. Actually, I'm gonna look for the get Hubble link. It was built by Thomas Fredericks. So typically, when you get a labour, you're going to download it from where it's hosted. In this case, you know, a lot of develop was used. Get hub, which is, ah, repository for you to download code on, have ah source control and manage updates and so forth. So you click on download Link Clooney or download and generally you would download the zip file. It's on a quick line that and I'm going to put it in just on my downloads folder here on my desktop, someone a quick save and it's downloaded. So now the question is, where do we put this in our we know I d e so that will be able to refer to it leader. Well, if you go to Arduino and Preferences, what you'll see here is thes catch book location. This is the path to where you would put any third party libraries. You copy them into their. So I'm gonna go to that on here. As you see from my particular computer, it's going to be in my Arduino documents are Do we know folder, You'll see a libraries full. They're in there on the zip file that we got. You would want to copy that in there. So are we saved it to the dustup. Gonna go ahead and unzip it. And typically you would see a dash master next to the file, especially if you get it from get home. You'd want to rename that to just the name of the library, and you can take off the dash, Master Attribute. When you get that, you can copy it to your documents wherever that location is. Libraries folder and you can paste it in here. As you see, I already have that bounce library in here. But you would just pieced it in there, Corporate over across there. So once that's copied, you have to restart your i d to make the changes take effect and that library to load up. So I'm goingto close it off. I'm going to restart my aren't we know. And when it comes up, typically, if there are examples in the library. So if you go to your examples, uh, here you'd see the actual bounce library that we put in Ah folder are libraries folder, and here are some samples. So with Scott on this one here to give you an idea on Dhere is the library itself. So that takes care of how we install it on when we want to use it at the top of our program . We have to do an include statement. So by doing an include were able to pull in the particular heather file for this, um, this particular library and general, any libraries have documentation on? You know what you need to include on the samples would tell you a Zaken. See, in this particular case, if I go to the bones at the top, it tells you what the include is to pull in that library. So, um, pull that end. And, as you can see in this particular project because we pull in the library were able to use the objects that were defined in there on foot from, you know, the cool critical of functions on those subjects. So we're able to use all of that being the features of that library by including it so that essentially, is it. But regards to third party libraries you'll see in some of the more advanced on intermediate projects that will be addressing. There are some third party libraries that will be needing so this lesson earlier streets what those libraries are. Third party libraries are in General Onda. When you find them, you typically would have to put them in your library's folder from Preferences on the Restart Your I D. You include those libraries at the top of your program, and then you will be able to use those particular functions or the functionality that's provide. 8. How to Use a Breadboard and Basic Wiring Concepts: In this lesson, you will learn about a very important component, which is used while working with your agree No for prototyping. It's called the Bread Board. You will learn what it is, how to use it on the underlying construction of the board, which affects how connections are made. You will also be introduced to some basic wiring concepts. In that way, you will be able to make the connection no pun intended here between how a circuit is drawn , a represented and how it is physically worried up on a bread board. Let's flys address some basics about the breadth board. This tool helps us the quickly prototype our electron ICS projects, because you can easily make connections between the magical components. This is beneficial in that we can easily decide if a circuit works and move things around before we make a more permanent solution, which is usually accomplished by a process known a sorry. Most bread boards have to power reels on each side of the bread board. One can be used as a common positive real for your projects, any other for a common negative real. Some bread boards have a break in the connection between the reels. If this is a case with your bread board, you'll have to use a jumper wire to bridge the gap. The rose on a bread board, ah horizontally connected, allowing us to make the electrical connections between components. Let's take a closer look at our bread board on either end. You'll notice that there is a positive, really, on the negative real that are all connected politically on On this end, you can see here there's also a positive real and the negative real that's also connected politically in the middle of the bread board. The pins are all horizontally connected. So on this end this these pins are all connected. Thespians are all connected and so forth. Similarly, on this other end of the bread board, the's pins are all horizontally connected. You're noticed that there is a break wind down the middle of the bread board. That means that these are not all connected. If you want to connect this particular rule with this rule, you'd have to apply a jumper wire. So let's see what this means. From a practical perspective, if we look at our reels, if I put a connecting where here and another one here along the same room. These wires are actually connected there enjoined because again, this entire rule is one single connection. So these two wires are essentially joined together. It's like if they were one continuous wire. If, however, I would have please a connecting where here. These wires are not connected because again, it's this entire positive real is connected politically and the other one is connected. So these wires are not connected to each other at the center of the bread board. If I put one connecting wire there and another one here, these wires nowhere essentially connected because again, um, in this role, horizontally isn't ah, rule is connected so current would flow into this particular wire than into the other one back up. So hopefully that gives you, ah, an idea of you know how your bread board is weird. If you're still unclear, a little later on in the lesson will actually be wearing up a circuit so you'll see. Um, this in action. Let's switch to the topic now off some basic wiring configurations. The first is a Siri's configuration, essentially in a series circuit. The current is this seem everywhere in the circuit. It comes out of the power source close through each component and then goes back into the power source. Let's compare and contrast this circuit diagram how it is actually wired on the bread board . As you can see here, we start off at the positive of the power source and go into the are one resistor on our bread board again. Here we started the positive and remember, these horizontal rules are all essentially connected. So if a wire goes to any pin any hole on this rule, it's connected via to this resistor. So essentially you're achieving the scene concept publicos out. It goes into the resistor again. Are one here is connected to our to because this roux is horizontally all connected. So it goes into the are two resistor than into the are three resistor, just like here and then, since again this rule is all connected. A wire from here on this rule goes back to grown, which is the semen on diagram. So that is a series circuit, and the wiring that's on this bread board is identical to be worrying. That's on the Siri's sick, a doctor. Let's go ahead and wire up our series circuit. So it has all through resistors, so essentially be happy where that's coming in. I went to connect one resistor here. It's gonna spend it cross for those rose. Next comes oh, second resistor that's in Siris. And then finally our third resistor. That's in Siris. Then we have our wire that's going to come back out to our part source. So if we look at our circuit, here is if we apply, reconnect these to tow our power source. Current is going to float down into this wire. Remember this Roussel connected horizontally into our resistor. This is well connected into a second resistor into 1/3 and then back out right? So that's a serious connection. The other circuit configuration is a parallel circuit. In this set up, the voltage applied to each resistor is the same. But the current splits up current, leaves the power source and splits up flowing through each resistor here, here, on here, and then collects again before returning back to the power source at the values of the resistors are different. The current flowing through them are different. However, the total sum of the current and trendy resistance coming into here and being sped up is equal to the total sum of the current, leaving the resistance going back into the power source. This is known as coach offs. Current law, an electron ICS. Let's compare and contrast this sickened at ground toe how it is actually wired on the bread boy. So here you'll see from the positive of our battery. The there's a connection. Remember, this riel is a well connected. So here is our our one resistor, which is connected to R two and R three. So here we are. One R two and R three are connected along this horizontal real here, and then the ends of the resistors are all connected. So are three is connected to our two, which is connected to our one, which that's the keys here, since this horizontal row is well connected, and then we go back to a battery so they have it. That's, Ah, parallel sick it. And again, the wiring on this bread board is identical to the wiring that's on this sick and background. Let's go ahead and a wire. Our parliament sick it. So first we have a wire that's coming in connecting Where then? We have one resistor. It's gonna spine a couple of rules here, and I'm gonna put in a second resistor and then the final. Thirdly, Sister, Finally we have our other wear that's coming back to the power source. Right? So if we apply our power source here to the circuit, essentially kind is going to come in from the power source when it reaches here. Remember, this horizontal rule is all connected. The current actually spits three weeks, so it splits. Some of it goes down this resistor, some of it goes to the other and then the rest of it goes to the third resistor. If these three resistors are, they seem the current going through here would be the same. It would be the total current that's coming in. Divided by three would go into each of the resistors and then coming out. Remember, this rule is well connected, so these resistors are all connected. The total current that's leaving here is going to be equal to the total current that's coming in. That's coach offs. Current lore. So this is your parallel circuit to summarize, you should now understand what a bread borderless, how to use it and why it is important in prototyping. It really is an indispensable tool for us. You were introduced to the basics of series and parallel sick. It's on how a circuit diagram is actually physically wired up on a bread board. Making that mental connection of understanding the connections needed on a diagram on how that is physically represented on a bread board is sometimes a hurdle for beginners. But if this is new to you, don't be alarmed. Pretty soon you'll get behind of it. That was quite a lot of information, but definitely needed as we progress in our journey so that you will understand what is taking place As we wire up circuits in our upcoming projects. Let's move on to the next lesson. 9. Let's create our first project: enough with all the basic stuff already. Let's get on the building off this project. I hear you were going to do just that. Our first project is controlling an led using the Arduino. It seems like a simple project. But if you are new tired, we know it's a great start and understanding how your hardware and software please together . And aren't we know lead? Let's take a look at the objectives for this project. By successfully completing the project, we will have mastered the following items. You'll understand how an led works, how tow wire and led in a circuit, and we'll learn how to use the pin mood digital right under Lee functions. These functions are very common in a lot of our projects. Let's get this show on the route. Yeah, the parts that we will need. Andrea, you know, the U. S. B cable of bread board, Red led or any of the color of led that you might have 2 21 resistor and connecting wires. Let's first address some basics. Amount of led led is short for light emitting diode in the wool of electron ICS. A dialled is a device that conducts electricity in one direction only. This is the case with an led. It has a long pin which is referred to as an AL owed on a shorter pin, which is referred to as a cathode. When we apply an electric current toe led current flewis into the and the cathode. So here currents gonna flow into the hallowed and of the Catholic. Generally, we also connect a current limiting resistor in series with an led in that way for a given voltage, we can limit the current flowing through the led so that we do not bring it out. So in this second dark ground are D. C. Voltage is applied and from the positive goes into the hallowed. How the cathode to our current limiting resistor and back to the D C power supply. DC voltage know that we have those led basic stone. Let's take a look at the second background for project. It's very simple. First we have a from the Arduino, we have the groaned pin connected to the grown real. Then we have the 2 21 resistor going to our car Food of our led negative pin or short depend of the led and then from the a load or the longer pin we have that connected to tell eat on the road. Really very simple, very shrewd fall connections, that's where for a circuit. First we're gonna connect are led Then we have ah, current limiting resistor going from the cathode to ground. Then I went to connected ground riel to the ground near Reno. I could have also directly connected the resistor to the ground pin on the Arduino to see a connecting where next from the a load of the diet, I'm going to connect, make a collection to pay 800. We know that compete so wearing now we're gonna go ahead and up with the code, right there it goes. So as you can see, our led is blinking on and off. Hey, success. You have wired up and created your first Arduino project. Let's take a look at our code. Essentially at the top of the program, we define our early deep in as eight. So remember, where can we did connect the unload to pin eight on the Arduino. Next, in a set of function, we used the pin mood function to determine or specify that the led Penn is going to be an output. So pin Mood tells a four PIN is going to be used as an input or output. It takes two arguments to this function. The first argument is the pin, which we define us pin eight. And then the second argument is whether it's going to be an input or output. So our set up function is very simple here and all first program in our Lou function. First, we do a digital right to hourly deepened, turning it high. So that's gonna turn the of the on. We then used the delete function on DeLay takes the number of milliseconds Azan argument for our program to halt or stop. So when we do did may 1000 milliseconds, it poses for one second or the led stays little for one second. Then we proceed to tune the led off. So we do a digital right to the led pin setting it. Look, the students are led off again. We wait one second so we do a delay. 1000 Wait one second and then our Lou function starts all over again. Do a digital rights setting at high wait one second than a low and wait another second and sore. So as long as power is applied to the led, this will continue looping on. Our led will be blinking on and off. So let's take a look at our pin lewd function in the documentation. As I mentioned, Pin Mood takes two arguments. Pin is the number of the pen you wish to set, and then mood is whether it's an input or an open. In another lesson, we'll look at input. Pull up on exactly what it is. It's an input pullup resistor. Um, what for? No input. Output determines if the pin is an input or output. The other function that we looked at was digital Right. Gonna linked about here on digital right again takes two values. The 1st 1 is pin the pin that we want to write to. And then the other argument is the following. Whether it's higher, look so again it is used to tail or evd on off. A final function that we looked at was the lovely function. Bring that up here on DeLay, as I had mentioned, takes Ah, if the argument is in milliseconds, so it takes the number of milliseconds too, you know, Hold on the layer program. And when you do the lay, 2000 milliseconds is one second. So we just pause for one second. That's how we're able to keep our led on for one off for one and so forth and keeps repeating. So those are the three functions we were introduced to in our first project to summarize in this project he learned what on led is on how to connect it in a circuit you were also introduced to the concept of how you're cool is uploaded to the Arduino, the pen road digital right on Dealey. Functions were also introduced to you, and you should have now be aware of how to use them. These functions are the building blocks of many Arduino projects. So it was great that we got them covered here. Let's move on to our next lesson. 10. Helpful Programming Concepts - Part 1: in this lecture, we will be diving into some helpful programming concepts for those that might be new to the world of programming. This would also help you to understand common quoting patterns as we work through the projects. In this course, let's first talk about variables. There are different types of variables that are available for us to use as an example into is an individual flute is a floating point number on an example would be 1.5 or any number that has more precision with a decimal point. Car is a single bytes of memory. Enough to hold one character such as an A or B bullion is a value that's either true or forts. Andi. There are other types of variables, such as double and long and so on. But for the most part, these are the variables that will be seeing throughout this course. Variables must be cleared before they can be used on. In this case, we are declaring three variables. The 1st 1 is speed, and it's off type interview. Next, we have a character variable ch. On a boolean variable is lit when variables are defined outside of functions, as is the case here in our program theory flew to as global variables. We'll talk a little bit more about that speech around. When variables are declared, we can define values for them. In this case, we're setting speed toe a value of zero C H equal to H. And since this is a character or char variable, we have to use single Kuyt's for the character that we are assigning to see. Each, because is lit is a boolean variable weaken set its value equal to truth. That's the B six around variables on defining and declaring their values. Another type of variable Mimi encounter is a constant. These are variables that do not change. Essentially, you defined them once on assigned them of value, and they cannot be modified later on in your program. It's a good way to protect a value or a definition that you want folks to reuse in your program, but you do not want it to be modified. It's up. Here are a couple of ways that we could define Constance. In this example, we used the pound sign, define keyword on. We specify the name of the variable that we want to make a constant on its value. Alternatively, we could see CONST. Which is the constant key, would specify the type of variable in this case. It's an interview, the knee multi variable on assignment of value. These two statements are essentially accomplishing the exact same thing, and later on our program, we could access the value of that variable so in a week and retrieve more tip in two and get the value of that variable. However, if we were to assign it a new value, look at what is going to happen when we compile all program. All right, you'll get an error saying That's It's a read any variable. So that, essentially, is what constants are. They allow us to the fine read only values that we want to remain constant throttle program . Let's talk about the difference between local variables on global variables. A variable that is declared globally is accessible everywhere in your program. So, as an example in this program, we have three global variables in motor speed float temperature reading bullion completed. These can be accessed anywhere in your program. So in a set of function, we can actually set motor speed quote to 10 and similarly, in our loop function, we can set that value again or read out the motor speed found you, it seem, applies to temperature reading and complete it. So hence when variables are defined outside of functions, they are referred towards global variables and they can be accessed anywhere in your program. On the other hand, in local variable is declared with any function in your program. So in this particular thes, we are declaring a result variable, and we're setting result equal to numb one plus number two in or cultivate some function. This result variable can only be accessed in this calculate some function. So what that means is we could not sent or retrieve results in our loop function, since it can only be seen within the boundaries of this car. Commit some function, so that's a local variable. So to summarize, the global variables are defined outside of functions and are accessible anywhere in your code on local variables are defined with in functions and can only be changed in access within the particular function itself. Next, let's talk about a raise you could think of a raise is just a way to perform groupings of variables of these seemed type. Really, They are a collection of variables of the same type. This was an example. Here we're defining a pin out ary. It's uptight integer, and we're specifying that it has values of 1357 and nine. Alternatively, we should have specified the penalty array in this manner. Here we have interject in all three. What we're saying essentially is the size of our worry is three. Meaning it can hold three specific buckets, uh, vintages and to the final values off those buckets we see pin out zero. Meaning the first bucket is gonna have the value one, not one, which is the second memory location is gonna have the value three. And panel to is gonna have the value fight. So this is a longer we of defining the values of the ary, and this is a shorthand way of actually declaring the penalty array on the finding values all in one line, you have to remember that individual a re elements are identified by an integer index. So if three is the size of your re, the first integer index always starts at zero. So the access or set or retrieve the first element. We were footed as pin out zero, equal to whatever value. One thing to remember is that if the size of your ES three two would be the maximum value that you can access, so if you specify, pin out to that's the last member of your a rate. If you do, pen out three and try to access that value, you'll get on out of bounds. Exception occurring Because remember, arrays start at zero or the first member of theory is the zero index. Here's another example of defining a character re so here we have carte attempt, this plea, and we specify an actual string, which would be stored in the ary. Another example, you might see is a multi dimensional array. What this means is, it's that weaken store each of these our this. The size of this particular rate is 10 which is the first dimension. On the second dimension is the number off individual characters or in this case, bites that are stored in that in each room for theory. So we have 10 rockets that go from 0 to 9, and within those individual buckets we can go from 0 to 7 fights. We'll see the use of this bi tary when we look at our seven segment discreet project. Next, let's talk about the concept of looping. Looping simply means performing an action again and again based on some criteria. The first type of loop we'll look at is it for and in our four loop. We are essentially saying that we want our loop in this case to execute 10 times. Here's his syntax for a four. So initially we have four. We specify a starting integer int I equals zero. So we're starting zero at the end of our loop. The condition for that when we jump out of our hope, is that I has to be less than 10. Once I is equal to 10 we exact our loop I plus Plus. That means that we want toe increments the value of I, which with each iteration we simply print out the value of I. So when this has run its going to dispute 012 or leeway to night on a new line. In this case we do. For int, I equals 10. We start a 10 is greater than or equal to zero. That means that we want to run this on. Of course. Where Declan Menting I I minus minus First we will see the value 10 being the speed send. When we loop around, I is documented. Value now becomes nine. Is nine greeted unequal to zero? Yes. Then we document eight as eat greeted on equal to zero. Yes. And so on until we get to zero. So this will this be 10 20 and then when we de Crimmins zero to minus one minus one is not greater than equal to zero. So we would exit are that is essentially a for loop and how it works. Another type of looping construct is an if else sleep This is what it looks like Essentially we are checking for your particular condition If digital read on our button penance low We performed this action and the action actually is defined within the curly braces else if this is not the keys and of course digital read of But the pain is high. We would perform this alternative action. That's the find within these brackets. So you could think of if else as a bullion check if a particular condition is true or whatever. If expression we evaluate in the brackets quits, the true or false Once that's meant we execute this metal logic else, we execute an alternative piece of logic. And if else statement can also be nested with several conditions. So in this case, we're checking if state is equal to zero. We perform this action within these Cooley Breezes else. If state is equal to one, we perform this action else. If status equal to to this action also state is equal to three. This action. And if all those feels you can have a fight, no else check where we if none of our conditions are met, we jump down into this else final else block and he is. This logic would be executed. This is Cooley nested NFL's statement. The next type of looping construct we may see is a switch statement. You could think of a switch statement is providing clean. We toe organize and present conditional logic rather than having multiple if else statements, he is what a switch statement syntax looks like. Essentially, we would have the key would switch with the expression we want to evaluate, and then we run through several scenarios of if the case, if expression is item one, meaning the value of expression is item one. We execute this logic, and then we break out of our switch. If it's item to we execute this logic and so on. Let's look at a practical example of a switch statement here would define a reading into reading equal to three. We do a switch passing in that reading variable, and we evaluate several different options in the first case. If the value of reading is one who would execute this logic and then break out of our switch statement. In our case, the value of our reading is three. So neither case one what keys to would be executed. However, since the value is three, we would jump into here. Found it. Reading is three would be displayed on our off the terminal. He would then break and exit out, and we would be done evaluating our switch. Statement was, he conceded, it's just a different way of doing a multiple NFL's check. But in a more clean, concise, organized wait, if, for instance, our reading was five, it would no longer be equal toe 12 or three. So if none of these commissions are met, hey, switch statement would ultimately jump down to the default option and it would print out. In this case, reading is not following, so he should always include a default option with your switch statement to tell the program how to be heave if none of your conditions are met. 11. Helpful Programming Concepts - Part 2: let's address the concept of functions in a lot of our projects. We have custom functions that are defined that execute different pieces of logic when we look at every Arduino program. In fact, set up and loop are two functions set up is only executed once, and Luke is run again and again when we take a look at how the function is defined. Typically, the function foods specified with a type that it is going to return. In this case, our teak reading function is going to return on interject. In the case of our loop on set up function, avoid the notes that the function is not going to return anything next after we specify what type off curable or if any is being returned from our function. We have the name of the function, followed by parentheses or brackets, and within here there may be one or more arguments that are specified that our function can operate on as an example. In this particular function, it returns a boolean value so it's switched, engaged when Cole will return a Boolean or true false values toe whatever is calling it. So in our loop function, weaken, do if is switch, engage. And if that's true, we execute some logic here. In this particular keys, our functions takes on argument. So an off convert to Celsius function, it returns a floating point value, and it also takes in a fun had reading, which is a type flute. So if we was cool this particular function as an example here in our Luke, we would say, convert serial dot print lying. That's they were sending into the output we call the convert two Celsius function and we personally fern had value. We can say 35.2 right, and once that's cooled, the convert to Celsius function, the value of fine heart reading would be 35.2 on in here. That's where we access our 35.2 value performer calculation and retune our floating point number. In this last example, we see a function which takes multiple arguments, so calculate some returns an integer, and it takes a number one on the number two, which are type inter jizz. Here we put a comma between the different arguments to the Newt. One argument from another. Within our function, we can access the values of those variables Number one and number two. Here we define a local variable. Some is equal to numb one plus number two, and then we return the result, which is inter. Just some, just like ah, function. Define park out today calling program. So to call that I can do cereal that friends line and gonna call cocky need some. And if I pass in five comma three, I'm going to get eat, being returned and that in and not show is functions on how they work. Let's talk about arithmetic operations. We'll see. In Arduino, you perform a lot of calculations based on external sensor measurements and also, if we want to interact with peripherals. Sometimes calculations may be involved. The arithmetic operations, the core common ones are addition subtraction. Multiplication division on module is calculations, so to perform. Addition, weaken Do into Total is equal to five plus three as an example on, If we have readings which we define isn't urges, Weaken do an Intertoto is equal to reading one plus reading, too. That's going to take the value of whatever stored in reading, too, added to the value of whatever stored in reading. One on store that new value in total to do subtraction as an example into difference is equal to Max reading minus men reading. So we use that minus saying to perform subtraction to do multiplication. We used the Asterix symbol. So in scale amount is equal to reading times scale factor. This is going to retune whatever devalued that reading is multiplied by whatever stored in scale factor. And it's going to assign that new value to skilled. A month that performed the vision here we have into measurement is equal to reading, divided by 10 and we used the backslash as our division indicator. And that's going to divide that reading value by 10 on a sign that result to the measurement bearable. Another sort of handy operation that you'll see is the model ISS and marginalised just means remainder. So as an example, 10 marginal three would be equal toe. Three remainder one as three threes are nine on, there's one that's left over. The model is gives us the remainder, and we used the actual modulates calculation in our stopwatch program so you can see and get a good idea of exactly how that helps us out. That's arithmetic operations and I'm not show. The last topic I would like to address his struck's basically is trucked is a way of combining several different characteristics to form a variable. So as an example here, we're creating a structure called joystick reading Unassociated. With this one variable, we have three individual values. We have an exposition of Adre Stick A Y position which are both of type integer on a boolean variable, which is is but impressed when we went to define our own variable, which is off typed, struck joystick reading, we can do it like this. We can see joystick reading, which is the type of the variable on the name of the variable. Remember, this is no different than if we said into reading. Remember, In our classical definition, reading is the name of our venerable and into his third type. In this case, we're seeing current reading is the name of our viewable on. It is a type joystick reading, which is a type of structure when we want to access or set the individual values of our struck variable. This is how we do it so we can see current reading dot Exposition is equal to 1 25 current reading dot y position is equal to 2 25 and similarly weaken sea currents. Reading that is button pressed is equal to falls. The benefit of this is that weaken group associate ID values for a variable and have everything housed in one complete variable. Sort of like we're creating an object and object oriented programming. And that nacho is what instructors. We'll see a structure being used in our infrared repeater sick IT program, where we combine a lot of information about an infrared signal and store that in East Trucked Object. This was just a quick introduction into some helpful programming concepts, but there's quite a lot to learn about programming. The course isn't meant to make you an expert programmer. It's meant to introduce you to the world of Arduino on programming concepts, so to help you out if you want to improve upon your program and skills, Oh, post a few programming resource is, and books in the resource is section for the lecture, and you can take a look at this in more detail to dove a little deeper into programming concepts 12. Controlling an LED with a Push Button Switch: in this project, we will learn how to control an led with a push button switch. Essentially, when the push button switches pressed, the ebony will right. It will continue to steal it when the switch is engaged and once it is released, the led will go out and stop being lit. Let's take a look of the objectives for our project. By successfully completing this project, we will have mastered the following items. You will understand how one led works, how toe wire and led in a circuit. How we push buttons, which works, how we connect a push button switch in a circuit. And finally, how to use the digital read function for real. If you're ready to begin, let's get this project started. He had the parts that we will need 100. We know you know. A USB cable bread board, a red led or any other color off Led that you, me? How a to 21 resistor on the one killin resistor, a push button switch and connecting wires. Let's take a look at our sick, a diagram that will be using for the Arduino. As you can see the grown connection and the five ALS connected to the ground and five world reels celebrate board for the led be cathode or the negative pin of the led is connected by a to 20 home resistant to ground, whereas the and load or the positive pin is connected to pin eat on your greenoe For our push witness, which one end of the switch is connected to the ground riel. The other end of the switch is connected via a one kilogram pullup resistor. 25 worlds on the other end of the switch is directly connected to be pin seven near Reno. Next, wire up this circuit. The first thing we'll do is let's connect the ground and fight bulls. So, America, we know I'm going to go from ground to ground pin to the ground, real on next from the five Bolt put to decide World really inbred board. Next, we can connect our led now for an led. You'll notice that there is a shorter pin on a longer pin. The shorter pen is Cooley Cat food. What's the negative pin? And the longer pin is the hallowed or the positive pin foran led to light. Electricity has to flow into the load and out of the cathode. Right, because an led conducts electricity in one direction only. Okay, so let's wear a por led. Um, if you look at our circuit diagram, we have a 2 21 resistor that is connected from our cat food directly to grow. Let's go ahead and wear that up. We have our extra gonna connector to 21 resistor to Crown Onda from the Arnold of our led Goes to pin eight on your agree? No. So I make that connection now, next component, we wear a bizarre push button switch. If you look at a push button switch, the particular one that I have There are a couple of connections on this side. Once the switch is engaged, current can flu ah through the circuit between these two actual connections here and similarly on the opposite side of the switch when it's pushed or engaged. Current flu's between these two connections here, so let's go ahead and connect that switch in our sick It he looked at our circuit diagram from our switch. One end of the switch goes directly to ground. Let's make that connection and then we have a one killer world pullup resistor connected to five volts from the event of the switch. It's will go ahead and make that connection here, okay, directly, as he can see from the other end of that switch to the fry brawled real. And the final connection that we have to make is actually from that seem. End of the switch and we're going to go to our Arduino. Pin seven writes about completes the wiring for a circuit that's go ahead and upload the code and test this up. So I'm going to connect the Arduino. Here we go on, upload our sketch. When that is complete. Less test. Let's test it out when you press the push button, switch our led lights so they have it. As long as the switch is pressed and engaged. The led states lip, and as soon as we move our finger from the switch, the led goes out. They have it. You're now controlling and led using a push button switch on the Arduino. Let's take a look at the code for our project. At the beginning, we do some initial configuration. We define the led pin as eight, since it's connected to pin eight on the Arduino on. Then we defined the button. Pinna seven. Since it's connected to pin seven on the Arduino in her set up function, we set the early deep in is an open and the button pin as an input. Been, since you will be taking our readings at the button pin to determine if the button is pressed or not, our loop function is fairly straightforward. Here. We'll use the digital read function and read the value of acne input pin. If that's low, that means that he switches pressed. And if that's the case, we want to turn or led own. So we used the digital right function to turn the led penned high, and the elderly will well, it. If we do a digital reader button been and it's high, that means that it's which is not being pressed on. We would set the led pin toe loop on. It would turn off just a reminder here on all circuit diagram in its normal state. As you can see, if we take a digital reading at the spin, it would be five bulls or high since it's connected via Lee resistor to the Five World Real Wendy's, which is pressed, however, current is going to flu three D resistor down to ground, and if you were to take a reading here at this point in this circuit, then it is shorted to ground. Hence that reading would be low or zero fools. So hopefully that explains how the push buttons, which is used in conjunction with the resistor in the Arduino to turn, are led on enough to summarize. In this project, you learn how an led and a push button switch work and how we are connected in a circuit. You were also introduced the digital read function for taking an input reading. These are basic components that are common in many electron ICS projects you know have gained an understanding of how they work under can incorporate them in any of your future projects. 13. Controlling a Piezo Buzzer with a Push Button Switch: In this project, we will learn how to control a pies Abuza with a push button switch. Essentially, when the push button switches pressed, the buzzer will sound. It will continue to sewn once the switches engaged, and when it is released, the buzzer will stop. Let's take a look at the objectives for this project. By successfully completing the project, we will have mastered the following items. You'll understand how a pies Abuza works. How the wire up isil buzzer in the circuit, the difference between an active and a passive buzzer using the tune function on also using the no tune function. If you're ready to begin, let's get this project started here. The parts study will meet. I learned. We know, you know are U. S B cable, a bread board Heisel buzzer a 3 38 win resistor and a one killing me sister. A push one switch and connecting wires before we get to a circuit. Let's talk a bit about the difference between active buzzers and passive users will address active buzzers. First active Pusser's generates the sound itself using an internal oscillator. What this means is all you need for an active buzzer is to apply a d c voltage similar to how you would turn on led on and off, depending on the buzzer. You might also need a transistor to give a power boost due to higher current off bolted requirements. On the contrary, for a passive buzzer, you need to provide an A C signal to control the sound. In order to facilitate this, Arduino has ah handy built in tune function to accomplish this. And we will look at this in more detail a little later on In this lesson, a prize of passive speaker can use the Arduino to drive it. It doesn't necessarily require an external power source and you can also control the pitch of the sound that can be heard from a positive buzzer. So those air a few differences between active and passive brothers. Our project will be using a passive buzzer. Let's take a look at all circuit Bagram First we have reconnected ground up in from the yard. We know to the grown real and then for the buzzer we have the negative been of the buzzer being grown did by ah 3 30 limit sister the positive skin of the buzzer is connected to pin nine under agree no for our push button switch when another switch goes to pin seven of the and we know. And also there is, ah, one. Colossal, um grown did resistor. Then finally the other end levels, which is connected to defy bold riel on. We complete that connection on the Arduino. That's where a circuit first will connect the pies of Mazer. If you look at the top of the prize a buzzer, you'll see a plus sign. That's where the positive print is. So just be mindful of that when you were up the circuit. Next, there's a 3 30 when her sister that goes to girl the positive pin of the price of buzzer go step in line on the Arduino. Next, they'll connect me push button switch. When I'm in, the switch goes to Penn. Seven. When you're do you know there's also one kilogram resistor from that particular end as well To ground the other end of the resistor goes to five volts. So I make that connection to the FIBA world real, and then finally we have tow wire up the actual five bulls collection to be flammable riel and ground. Okay, that completes our circuit diagram. Now, go ahead and upload the code, right? No, just the second out. So is he seeing when I pressed the buzzer? The button. So, as you can see, when I pressed the button, the buzzer makes a sound. They keep holding. Only button. The buzzer continuously makes a sound. Unless I take my hand off the buzzer, it stops. Let's take a look at the code. So at the top, we define our buzz up in being Penn Line of the Arduino, and then our button pin is connected to pin seven. In our set up function, we do a pin mode button pill input, saying that we're taking readings from the wooden pin and essentially in our loop function . If the digital read of the button pen is high, that means that we need to sound a buzzer. So in order to do that, we used the tune function, which takes two arguments. The first is the buzzer pin, and the next is a value for the frequency of the sound, so that would cause it was at the sun Else. If the digital read of the button pen is low. We call the no tune function passing in the buzzer pin, and that stops the buzzer. If we take a look at our A circuit diagram again, you'll see that wants the push buttons, which is engaged, oppressed, essentially and we take. If a reading is taken at this, been, it would be connected directly to fry boots. Hence, if they're reading when he switches high, we know that the buzzer is being pressed. If, on the other hand you're reading is low, that means that that these you're reading on this particular pin is directly connected to ground where any resistor there's a break in the circuit because it's switches not being pressed. We know that we need to not sound a buzzer on. We accomplish this by using a new tune function. So hopefully that explains the operation of the circuit on how we take the measurements in code to summarize in this project, he learned how to control a buzzer using a push button switch. You will also introduce to the tune on no tone functions for controlling the weather. A buzzer can be a useful component in projects as an alarm on general purpose auditory device, you know, have the knowledge to incorporated in your projects. Let's move on to our next lesson 14. Using a Potentiometer to Adjust LED Brightness: In this project, we will learn how to control the brightness. Oven led using a potentially ometer, essentially, by adjusting the value of the resistance. With our potential ometer, we can make the led brighter and dimmer. We will be using a process known as pulse with modulation to accomplish this or pwr for short. This is a simple circuit, but it illustrates how weaken take analog readings as input from external sensors and use this to control another part of our circuit. Let's take a look at the learning objectives for this project. By successfully completing this project, we will have mastered the following items. We will understand what is a potential ometer and how to connect a pretend She ometer in a circuit how to take an analog reading, using the Arduino understanding pulse with modulation and how it works and will be introduced to three new functions. The animal agreed Analog right and map function very handy and useful in our electron ICS projects. If you are ready to begin, let's get this project started here. The parts that will need on our Drina you know, how are USB cable bread board a red led or any color led that. You may have a to 20 room resistor, a 10 kilogram potentially ometer on connecting wires before we move on to a circuit diagram . Let's talk a little about pulse width modulation or P W. M for short. If you look at the week from for vaulted signal, we can essentially modify the duration of time that the signal is high. In the first signal, we make the voltage high, but only levered haIf of 50% of the time. Then we make it low Overall. The combined effect of this way for is that the voltage is high Rooney for 50% of the time , and hence of 50% duty cycle in our second wave form, we keep the voltage high for 75% of the time and then drop it, Lou. Only for 25% of the time. In our last we form the wall Tages High only for 25% of the time, and Lou for the remaining 75% in tombs off our led. The longer the we form is high, the brighter the led appears. The led is actually turning on and off. But this is actually so fast that the naked I can't see it switching on it off. Thus with our away form in the middle led will appear brightest because it is actually on 75% of the time. While in the last week form it will appear dimmer. Since it is only on 25% of the time. Let's take a look at the circuit diagram for our project. Essentially, we haven't led that's convicted to pin line of the Arduino. There's also a to 21 resistor. We have seen this previously, and this is our 10 Kalume potentially ometer. One connection of the potential ometer goes to ground. The other end of the potential ometer goes to five volts. So essentially, at any given time, five bulls is going to be dropped a course or pretend kilometer, we know take readings from the center pin. So there it goes to un a lump in a zero of the Arduino. As we adjust the potentially ometer. The voltage changes at this point and we can read that input analog voltage. When we get to the cool, we'll see exactly how this is done to get an understanding of why the voltage changes of the middle pin As we adjust the potential ometer, it hopes to understand how our potential metal works when we adjusted Diallo of a potential ometer. We are actually changing the resistance between one end of the potential ometer on the center pin. Resistance is the opposition to the flu oven electric current. The more resistance we have in a circuit, the smaller the current will be for a given portage apply to the circuit under diagram. We can see that the three pins on the right correspond to the three pens on our potential ometer. As you tune the potential ometer in one direction, we are increasing the resistance on moving closer towards five volts. If we take a reading from our A zero Kanaan yard, we know we would get a higher value. As we move the potential ometer in the other direction, we are effectively reducing the resistance and moving the point at which we take the measurement closer to ground or zero volts. Hence our reading from the easier open will get smaller until it is zero. When the dial is turned all the way down when the potential metal is about in the middle as it's depicted here. On the diagram, 2.5 bulls will be the voltage that is at the center pin. We will get an analog reading in the middle of the range to reflect this. We will clarify how we take the readings and the specific on along values that are involved when we examine the code in more detail later on, hopefully this earlier streets how our potential OMETER works and how resistance changes lead to our corresponding voltage measurement changes. Okay, lets where a par circuit First, we're going to connect our led. There needs to be a to 21 resistor more led that goes to ground. I'll connect that to the ground real. Then I'll make the connection from ground ground on the Arduino. The other end of the led goes to pin in nine. Now we're going to connect our potential ometer. Let's take a look at this potential ometer, as it seemed in the second diagram. There are three pins. The voltage measurement is going to occur at the center pin, so essentially five bolts is going to be applied to one pin of the potential ometer on the other end is going to be grounded as we adjust and turn the potential ometer. We would record the voltage change at this spin here in the middle. That's what we will use to determine the brightness of our led on DWI would taken input reading at this center pin on the pulse with modulate our open signal according me to change the brightness of our led. So we'll get this guy in the circuit. Okay, in the end of all potential, meta goes to ground so I'll make that connection. The middle pin goes toe are analog zero pin on our and we know on finally the other end of the potential Mitter the three pin goes to five volts. So I'll make that connection here to five points. Okay, that concludes the wearing of our circuit. Let's go ahead and upload the cool. All right, let's test out our second. As you can see, as I turned the potential ometer, the led gets brighter and brighter. This is all the way toe one in, and as I decrease it, it gets dimmer until it finally goes out. So again, we're taking that reading from the center pin. Onda, we are generating a pulse width modulated signal, which affects the brightness of the led. The longer the way forms high, the brighter the led is at this end of the potential matter. It is almost always high that that is why the led is brightest and as it reduce it towards the end. Here, the led appears them because it is off for most of the duty cycle. Let's take a look at the code to understand how we take those measurements on how we adjust the brightness of the led. At the beginning, we do our initial set up and configuration. We defying the led pin as nine is connected to pin line on the Arduino on the center, potentially ometer pin is connected to pin a zero on the left hand side of the yard. We know the E zero to a four pins are where we can take the analog ratings on their sitting pins on the right. There, it opens on the right hand side of the heart. We know that are able to generate pulse width, modulated signals. They have a till they sign next to them. In our set of function, we set the pin mood of are already has an output that we weaken right to that pin on our Luke function is fairly straightforward. What we do is initially we taken input. Reading on Dhere is the where we use the analog read function. So we taken Anil agreed function of a potentially ometer pin and that would give us a value that's in a range from zero toe 10 23. Once we get that reading, we passed that as an input into the map function which months that 0 to 10 23 range toe 0 to 2 55 range, and that 0 to 2 55 ranges the range that we could do an analog right out to. So you can think of it as whatever reading we get on the center pin will have a value between zero and 10 23. But we're going to get the equivalent of what that fraction of that ratio is of a value between zero and 2 55 Because when we use the analog great function, the only values that we can specify are in the range 0 to 2 55 So we're performing a Skilling, if you will to convert that fraction without reading that we get to an equivalent reading off between zero and 2 55 Then we do an analog right function to the led Penn, passing in that skilled value that we just calculated. This will generate a pulse width modulated signal if you send in 2 55 the way for Moby High , always high onda. Accordingly. If you send in a zero as they're reading, it will always below. Then we have a small 10. Milly second Billy between, um, you know each analog right on. We just continue looping over this to get some documentation on the animal. Agreed. Unlike writing my function, let's do a Google on along right on. It will take you to the Arduino documentation here, as you can see on local right takes two parameters. One is a pin, which is he pin that we need to write to and the value. And of course, as I mentioned, the value lies anywhere between zero, which is always off 2 to 55 which is always on for the analog read function. We can do a quick google for that as well. The only input to that function is the pen on a zai mentioned. It returns a value that's in the range from 0 to 2010 23. So it takes that bull did. Reading in Onda retains this equivalent value. When we get that value, of course, we want a map it to you know that 0 to 2 55 range. So the map function becomes extremely convenient and handy. So we can google that as well. If we take a look at the map function. As you can see, it takes five input parameters. The first permitted is the value you trained toe map. Then there's a from Luke from high. That's the initial range that your input reading could be. And then what? We're mapping it to the to move value, the lower end of the spectrum and two high value to the highest end of the spectrum. So there is also a sample down here on example here, similar toe all program. There is, ah, law, greed of, ah, been zero. And then we want a map that reading whatever we obtained to and here's the From Lou. It's gonna be between zero and 10 23 and we want a map that to some value from between 0 to 2 55 When we get back to value similar to what we're doing, they're doing an analog right to the particular pin and passing in the value. So hopefully you know that that clarifies those functions on also, to get the, um, all the functions and aren't we know you can go to this link here on you are able to click on any of the functions on get the putting the documentation to them, post that link and the resource is for you. But here you can get to the documentation. As for all the functions, a quick way to get it, though, is just to google it, as you can see. And typically, first link is the link to the appropriate function that completes the could review for our circuit To summarize. In this project, you learn how the brightness often led can be controlled with a potential ometer. You will also introduced to the concept of pulse with modulation and how it works. Now. You should be familiar with a few more. Do we know functions. These include the analog read on analog, right for taking analog readings on creating PW M output signals, and you can also apply the map function to convert values that occur in a range toe pre defined output skill. It was a simple project, but we have mustard, a lot of new concepts. We're picking up a lot of momentum here and let's move on to our next project. 15. Controlling a CPU Fan - Part 1 - User Input Control: In this project, we will learn how to control the speed of a CPU found by getting input from the user. We will also learn about transistors and how they applied in electron ICS and will specifically incorporate an NPM transistor. In our project. We will also be introduced to the serial monitor in Arduino for debugging and getting input from the user. Let's take a look at the objectives for this project. By successfully completing this project, we would have mastered the following items. You will understand what is a transistor and the different ways that a transistor can be used. You understand the basics of an MP in transistor. We will also use the serial monitor in Arduino to accept input and display output. And finally, we will learn how toe process input that is received from the keyboard and use that affect our art dealer circuit. If you are ready to begin, let's get this project started. Year of the parts we will need honored. We know you know the U. S. B cable of Bread Board a CPU fund 2 20 ohm resistor an M g e 1 82 n. P N power transistor connecting wires on a 12 volt DC power supply. Let's first talk about a foundational component. Electron ICS. The transistor transistors form the building blocks of all our modern electronic circuitry . In fact, we have gotten so good at manufacturing and miniaturizing transistors that billions yes, billions with a B of them can fit on a chip the size of your thumb. Leo. If we look at a single transistor, however, it is composed of semiconductor material and consists of three leads a base on emitter on a collector. We will learn more about the operation of the transistor shortly. Transistors can be thought of as miniature switches and primarily operate in to logic states on and off transitions usually have to mean modes of operation. They can be used as switches to quickly switch a circuit on and off fire an electrical signal. This can be controlled very accurately up to thousands of times a second, and they can also be used to amplify signals in a circuit. In our circuit, we are primarily using the transistor as a switch to turn our motor on and off. Let's take a look in more detail about how a transistor operates. We're using an NPM bipolar junction transistor or N P N B J T. Transistor. For short, another type of transistor is a PNP transistor. The difference between these two lies in the direction of the beast current and how it has to be applied to turn only transistor. For an MP in transistor, we need to apply current to the beast to turn on the transistor. You can think of the operation is a switch for motor in order to tune our motor on fire an electrical signal which we can manipulate. Using the Arduino, we apply an analog voltage output from a can of the aren't we know to the beasts of the transistor. This effectively turns a transistor on, causing the circuit to be complete, and current will now flow through our motor. Turning on our fun down on the ground, the fund turns on. We are using the M G E 1 82 np in power transistor as it can handle higher currents and voltages passing through it. We are actually incorporating pulse with modulation as well to also control the speed of the fan. The longer the own duty cycle that is applied, the faster the fat and spins. We will see this in Lord ity later on. When we examine the code, let's take a look at our circuit diagram for a project. This is our M J E 1 82 and being proper transistor, and the pins enabled from left to right are the emitter. The collector is the center pin and the base on the right hand side. So first we connect the ground pin on the Arduino to the ground wheel. Then, in worrying over transistor, we collect from the emitter to ground. Our collector pin goes to the negatives of the fund. The other positive pin of the fun for our CPU fund for a motor goes to V N off the Arduino . And then finally, from pin 11 of Arduino, you go through a to 21 resistor to the beast or the right pin of transistor. That is our circuit diagram. Let's go ahead and weigh up our circuit. First, we're going to take a look at our transistor. The emitter is a left. Been the collector is the center pin on the base is the right pin, so they have made it easy for you on the M G E 1 82 Uh, depends are labelled, so that would help you out in wiring up the transistor. So let's go ahead and connect the transistor analysts wicket. First, we will connect the ground. Pinot neared. We noted the ground real. Next, we're going to connect the emitter of our transistor to ground, then the from the base there is a to 21 resistor, so we'll make that connection. Now, the other end of that resist er goes to pain 1100. We know now it's time to connect our CPU fund. This is Theseus. If IQ fun that I have, um there are a couple of connections here. There's a bigger Molex connection and there's also a smaller collection for our pins that we may use. So I just used this. The black wire is the negative, and the put the red wire is the positive on this here. So from the collector of our sister, we're gonna go to the negative, read the fund. So that's the center pin. I'm gonna go here to the black wire on defend, and then finally, from our of the end on our end, we know we're going to go to the positive penalty friend Safavian and a positive pen. Remember, the only other thing that you need to do is that you also have to connect up the, um, DC power supply. So the air If you have a jack connector Barrel Jack connector that can go into the actual DC power supply here, we'll wait a while until we upload the code. Then we'll connect that. So that's that's our second. Let's go ahead and upload the code while recorders uploading going to open the serial monitor so you can get to the serial monitor from this icon on the right hand side of the artery. No, I d. On indec room monitor. If there is any cereal that print line commands that have been issued in your program, the text will show up in these here monitor Onda. Also, there is an input box for sending instructions, so a user type instructions and send this to the Arduino program, and that's essentially what we're doing in our project. We are asking the user to enter a number between zero and nine to control the speed of our fan. Zero will shut the fan completely off nine will be the highest speed of the fan Andi. Any number in the range between zero and nine will adjust its speed accordingly. So let's go ahead and send five. So as you can see, it turns are found on. This is about mid speed. We're gonna increase this to seven. All right? No, it's spinning even faster. And then I'm going to go all the way to night. And this is the highest speed to shut our fan off. We'll send the zero instruction, and as you'll see that shuts defined completely off, please remember that when you collect your sick it that you should have your DC power supply plugged them. Your external BC Power supply, because they are doing well by itself, cannot provide the voltage and current needed to drive the fund. So you need an external power supply. So please remember that the difference in this circuit compared to the other circuits that we've done, is that we'll also need a secondary power source for the Arduino. This is because in order to drive the motor for fun, we require a higher voltage. In a higher current, you can use an external, a see adapter, which provides 12 rules that we connect directly to the D. C. Jack of our Arduino to power our funds. Okay, let's delve into the code. No. So in our program, be at the beginning refused to find the motor pen. It's been 11. Remember, that was, Ah, the pin that's going to generate the pulse width modulated signal to the transistor. Next, in our set of function, we have been mood resetting the motor pin as an output, and initially, we are turning. We find off. So we do that on a long right to our motor pin, and we're sending zero. So that's gonna shut defined off. In order to communicate with the serial monitor, we have some initial set up. We do a serial begin 9600. That's the board rate that we're going to communicate with the serial monitor on or at. And then we're gonna display our instructions. Cereal that print lying, enter a number between zero and night. So that shows up in all Syria monitor when we run our program next in a loop function. Basically, we are pulling and checking to see if the user has send and sent any instructions to the Arduino. So we do a serial that available. If that's the case, we're gonna get input from the user. We first extract the character that he user entered. So we do a car ch equal to cereal that read, Read that character in and basically we're checking to see if that character was a number. So if it is between zero a nine, what we want to do is convert that character to an integer so we can achieve this in a clever way here by doing ch minus the zero character. And this would convert our cartoon that we read in into an Inter Joe speed, and then we proceed to do an analog right to be motive pin passing in. And here we use the map Foshan to mark our speed between zero and nine. Let me pass in between 0 to 2 55 so that it's how we able to do an analogue great to the motor pin on a justice speed. Accordingly, depending on the input that came in from the user to summarize in this project, you learned how to accept user input to control the CPU fund. You will also introduce the common electrical component a transistor, and you're sure how it works? Serial Monitor was introduced on. It is 100 feature for debugging and communicating with your circuit by a keyboard input. We also learned how to read input from the user and use this just the operation of our circuit. It was a simple project, but quite a lot of new concepts we learned here. Let's move on to part two of this project where we make some slight modifications to enable our fund to be controlled the fire a but 16. Controlling a CPU Fan - Part 2 - Button Speed Control: in part two of our CPU fun project. We will build on our previous listen and learn how to control the speed of a CPU fun by using a push button switch. Essentially, when the button is pressed, weaken cycle through three speeds of operation, no medium speed and then high speed. Let's take a look at the objectives. By successfully completing this project, we will have mastered the following items. We will understand how we push buttons which can be used to control the speed of our friends. Onda. We will be introduced to internal pullup resistors and how to configure them in our greenoe . If you're ready to begin, let's get this project started. Yeah, the parts we will need on aren't we know you know a USB cable bread board CPU fund A to 20 women resistor on M. J E 1 82 n. P N power transistor. A push button switch connecting wires on a 12 volt DC power supply. Let's take a look at the circuit diagram for our project. There's only one modification will need. We have included a push button switch that has two connections. One end of this, which goes to pin five on the Arduino and the other end of the switch goes to the ground. Really, that's it. That's only modifications that will need from our previous circuit. Let's go ahead and make the changes that are needed for this project. We will introduce a push button switch. One end of a switch goes to Penn five in the Arduino, and the other end of the switch goes to the ground Real. Also, you'll remember that we need to connect in the D C Power Jack in our second. So go ahead and connect to that. That completes the additional wiring that will need. Let's go ahead and upload the code for a circuit, right? No, that's complete. That's tested out. The the switch has three speeds of operation. The when I pressed the switch, one time for the first time is gonna be low, and the second time find is going to be spending a medium. The third time it's going to be spinning all the way on, and then 1/4 time it's going to shut the final, and then we will cycle through those so I'll go ahead. So there is no A. Press it again for medium. It's now going at medium speed than high speed one more time. Now the fun is currently at high speed, and then if I press it again, the fund should shut off. All right, you have it one more time. Most feed medium speed, high speed and then off. And there it is. Let's take a look at the code. Initially, we define our motor pin as 11. This is the same as in the previous program. Also, we define the button pin as five. Since we connect one end of our switch to pin 500 we know next we have a global state variable and were using this to store the steet at which the push button switches the current speed. So we initialize that 20 Initially, in our set of function, we do a pin mode when the motor pin setting that as an output here is where we set the pin mode on the button pin as an input pull up. So we are in fact here initializing the internal pullup resistor on the button pin. We do an analog rated the mood up in on we pass in zero, meaning we want to initially tell me, Find off on we set up our initial serial connection before we go into the loop function. Let's quickly take a look at the documentation for input pull up. So I'm going to Google that 10 would function. So I'm gonna look up that pin mood documentation here. And as you can see, um, for the mod variable, it can be input output. And we have seen these two previously and input pull up someone, a quick one. That input pull up and it's gonna take us into some details about that particular constant . So if we school down a bit here, we will see pins configured as in pull up. So the 18 mega microcontroller has internal pullup resistors, resistors that connect to power internally that you can access. So if you prefer to use these instead of external pullup resistors, you can use the input pullup argument and pin moved. Essentially, what we're doing is, as the name implies, input pull up actually pulls up that value to are high, so by default, if you were to take a digital reading off that input pin because that resistor is pulling it up to five volts. A reading would be high. So that has implications of, you know, when we take our reading, any circuit and I'll show you shortly what that means. So next we continue in our loop function, we do it. If a digital read of our button pin is low, that means that our switch was pressed. We cycle through the States if the current state of zero. And that's what we initially had when we set up our program. So this is assuming that this is the first time in if the state was zero, we're gonna set the front in Lewis setting. We do an analog right to the motor pin, and we're mopping the value of three. Sort of that 1/3 of the range on our range spans from zero to Maine and we're mapping that an equivalent value between zero and 2 55 So that will do an unloved right. And we set the state we implemented toe one. So the next time we loop, if the do a digital read only button pen in its loot expressed again, state would have been one. So if status well, we come in here and we set the front of the medium setting. So no, we'll do analog. Great Ormeau Tip in and we'll map 66 is about 2/3 away in a range between zero and nine and remarked that the equivalent value between zero. And 2 55 we set our state to and we continue one. If we come in status to we're gonna write it now to the highest setting on the fun. So it would mark 9029 on, then we do 0 to 55. Actually, this would equate the 2 55 So this is like we're doing an unlevel right to motor pin. The value of this expression was gonna be 2 55 We said the estate to three. We loop again, and if you press it another time, if status three we shut off the fund So we do analog. Great. The mood up in zero and we start on state at zero, and we start the process all over again. In between, the actors sort of, you know, the bounce and mechanism. We're just gonna do a delay before we continue any other additional readings of the push button switch. So this is just to make sure that, you know, we don't pick up any. He bounced readings that were not intending to. So that's it. That's our program. Just to quickly revisit the operation of the push button switch an inch normal state as the pullup resistor is enable on pin five. If you would take a digital reading with only switch being pressed, it would be high. So in that case, we know that the switch is not being engaged on its high in its normal state. When we push the switch, these two terminals actually are connected. So current is going to flew through the internal resistance back down to ground. And if you want to take a reading at 10 5 it is going to be low, since the current is gonna be flowing through the resistor, that five ALS is going to dropped across the resistor so you'll get a lower reading. And that's how we will determine if the switch was pushed. So by using this logic, were able to cycle through the various states off. The push wouldn't switch on have cycle to me states of our fund. So hopefully that provide some clarity on the operation of the switch and Allah circuit. To summarize in this project you learned how to control a CPU fund using a push button switch on the Arduino. You will also introduced to the concept of pullup resistors and how they're configured un enabled in Arduino great project with some great concepts. I hope you're getting pumped. Let's move on to our next project. 17. LED Reaction Game - Part 1 - Interrupt Demo: In this project, you will learn what interrupts are and how they can be applied to your electron ICS projects. We will be building a simple circuit that illustrates how we can configure and set up an interrupt which performance an action on our circuit when the appropriate event is triggered In our project, we will tuggle the state of on led. When a button is pressed by using an interrupt, let's take a look at the objectives for project. By successfully completing this lesson, we will have mastered the following items. We will gain an understanding of interrupts and why they're useful. We will learn how to set up and configure them in Arduino using the attach interrupt function, and we will define a function that reacts to our interrupt. If you are ready to begin, let's get this project started. Yeah, the parts we will need on our doing A. You know, a USB cable of bread board, a one killer, one resistor, a push buttons which and connecting wires. Let's let's discuss what interrupts our. They are very hunde for making things happen automatically in a microcontroller circuit. Usually we spend a lot of time sitting around and pulling, waiting for events to happen. This is a waste of process, of resource is interrupts. Allow us to be notified when an event which is important to us, occurs so we can act accordingly. They provide a great way to solve timing issues and projects some could use cases for. Interrupts might be reacting to user inputs so that we can be notified when a user is trying to get the attention of the microcontroller. For example, pressing a switch or changing an input, giving priority to important processes we care about and optimizing resources that are wasted just sitting around and pulling and waiting for events to happen. Specifically, let us address how interrupts are implemented In Arduino. We normally define I Essar's or interrupt service routines, which are separate functions that we want to fire or execute. When an interrupt occurs, we should be a short and fastest possible, and the functions can it accept parameters or return any values. Only one ias Arkan run at a time, and if you have multiple in your program, they are executed in the order in which they occur. It is important to note that time functions make Molise on delays will not increment or work and interrupt functions, since these themselves rely on interrupts to operate in order to store information. Global variables are usually used to pass information between IAS ours on your mean program , and we should be identified with the volatile keyword. That was quite a lot of info, but it will become clearer when we dove into some code. Let's take a look at the circuit diagram for our project. It is very straightforward. We have a push button switch. One end of the switch is connected to ground endured Reno. The other end of the switch goes to been to in the ad Reno on. There is also a one kilogram resistor from that end of the switch to five volts. So we connect back to defy bold real. And then we make our final connection from five bulls on your do you know so that fiber old real, that's it. Very simple circuit. Let's go ahead and wear a par circuits. First, we'll connect the push button switch. Then, from one of the switch, we will go to ground. When you're in Reno. The other end of the switch goes to pin to neared. We know there's also a resistor to defy bubbled riel from back end of the switch. And finally, I'll go from Bibles leered. We know to the Five World Real that completes our wiring, right, Let's go ahead and upload the code brakeman. That's done. Let's go and open the serial monitor to know when a test are sick it out. When I pushed the button, the built in led should light, and we should see an interrupt fire on our Syria monitor. So there you see it a pressed it once, and the interrupt you see, the interrupt occurred and the button rights and no, if I press it again, another interrupt occurred and the, uh led is traveled. So as I keep pressing this push quick route led will come on, and when I press it again, it will come off on. What's happening is actually interrupts are occurring and are being handled to Tuggle, the state of the L B. On enough. Now you mean notice that when you press it, you may get several interrupts occurring, And as you can imagine, that's happening because of the bouncing. So when I actually press the button it's making contact several times. So that's why several interrupts me fire. And you may experience this when you actually running this project yourself. But nevertheless, the project is meant to demonstrate how interrupts occur and how they can be handled. So hopefully you get the idea. Let's take a look at our code, so initially we do a constant into for led pin. Suddenly after 13. This is another way of doing the fine. We're just defining an integer. We're setting it a constant meaning that cannot be Children aged or the value of this led pitch variable cannot be changed anywhere meter on in our program. So Ellie, Dependence 13. That's the built in led. Then we do the input pin, which is connected from the button to pin to on the Arduino. In a set of function, we set the pin mode of the led Penn to be an output because we want to write it to toggle the led on. We also enable the input pull up resistor on our input pin just to set that high, and it's an estate when the button is not being pressed. And here is the syntax for touching our interrupt. So we do attach interrupt. The first argument is either zero or one on. We'll look at the documentation shortly, which specifies which will clarify what that means. We then pass in the actual I S R or interrupt service routine that we want to run, which is a function onda we pass in when we won that interrupt occur. So here we're specifying on the falling of the signal falls from high to low That's when we went toe enter up the fire in this particular program for loop We actually don't do anything. So there's no logic in here And here is our interrupt service routine that's called but repressed, which you specified above and remember foreign I s Are it kind of take any arguments? No. Cannot return any values. So it's just avoid button impressed in here. We're gonna right out to the serial monitor that an interrupt occurred. We're gonna do a read on that really depends. So if digital read a little led Penn, if that's high, we're gonna rights to the really Deep in low Simply were targeting the state of it else. We're gonna write to the other deep in high So once it tennis said hi, it's set back to low and vice a versa. It keeps talking every time we press the button on interrupt happens because of the voltage going from high to low Onda. Once that interrupt I S R button press function is fired, we tuggle the state of our led. Let's quickly look at the documentation for attach. Interrupt when it will go that I'll open it up. So, as you can see on the Arduino Uno board, which is a board were using, you can attach interrupts on pins two and three. We are using pin to, you know, sick it now in the syntax for the attach interrupt function down here, the first value of this variable or this argument is zero. If you had to use the pin too, or one if you had used been three, all right. So that's why we used zero when we called the Attachment Europe function. You could also use this digital pin to interrupt in passing the pin number so he could do digital pin to interrupt. Any person to that will evaluate zero for you. All right, so But we just put zero in there. Next we have the actual interrupt service routine only function we want to execute when it interrupt occurs, and then we can specify the mood. So, as you can see here mode there a few different modes load, um, can be used to trigger the and Europe whenever the penned goes toe a low value, um, change if the the value changes rising or falling. So there's several different ah configurations here that you can set up for your mood and that's it. All right, so that's, um, be syntax for interrupt our attach interrupt function to summarize. In this project, you learn what an interrupt is and why it is important. You also learned how to set up and configure interrupts for your Arduino program using the attach interrupt function. It was a simple project, but demonstrated an important concept that we will use in the game we will build in our next project. 18. LED Reaction Game - Part 2: In this project, you will build a fun and highly addictive led reaction game. The ghoul is to press the push button switch at the exact moment when you see the red led lit. This isn't as easy as it seems because the allergies are going on and off at random times on in a random sequence, we will be learning how to apply interrupts to react to events in our circuit. That is how we will know when the button has been pressed. Let's take a look at the objectives for our project. By successfully completing this project, we will have lasted the following items. We will learn how to incorporate interrupts as an important process of detecting and reacting to events in our inner tronics projects. We will also be introduced to be random, are doing a function for creating random numbers. If you're ready to begin, let's get this project started here of the parts that we will need a large we know you know . I USB table of bread board 3 to 21 resistors and a one killer resistor. Three ladies a red green on a yellow, preferably or any three different colors. A push button switch on connecting wires. Let's take a look at all circuit diagram. As you can see, we have three resistors that are connected, which are to 20 rooms to our ladies. Resistors are connected to the ground real, and they are connected from the cathode or the negative, shorter pin of our ladies from the Alan of the first yellow led that goes up in 10 near Reno. The animal on the second red led on the centre. One goes to pin nine neutrino, and finally the load off the green led whose to eat on the and really for a push button switch when a lovely switch goes to pin to on your green. Oh, there's also a one killer whom resistor that's a pullup resistor connected to defy bold real. And then the other end of the switch goes to ground. The final connection is from the five volt pin on the Arduino to defy build real that completes our sick it diagram. Let's go ahead and connect our circuit first, you're gonna have our yellow led next door readily be, and then finally or a green led, then we can connect our to 21 resistors remember those resistors go from the cathode to ground or the shorter pin of the led to grow. That's the 1st 1 Finally, 3rd 1 Next, let's connect the ground real. So we're going from ground a near agree no to be ground riel. Then we'll make the connections for the L. Edie's from the annals. The first for the yellow at one goes to pin 10 yard. We know with their bread. I was to pin nine and to be green. Most open eat the male connector push button switch when an of this, which goes to ground. So we made that connection now at the end has a one K resistor that's gonna go to the Five World Real. And there's another connection that goes to Penn to near Reno, And the final connection that we have to make here is from the fables to define what really all right, that completes the wiring of our second. All right, let's go ahead and upload the code. All right, so when that's done, so what you'll notice is you'll see the led is flushing in a random manner on. The objective is to hit this push button switch on the exact time that we see the red led lit. So if we try and you were not successful, you'll see the allergies continue lighting. But if we're able to do it like I just did, all three ladies would flash. So that's how we know of one successfully sort of hit the switch and the exact moment when the red led was lit. We'll try it one more time. This there, I got it. We'll take a look at how weak and manipulate the randomness of when the allergies are on and off on the time of duration between which the led zehr lit to make the game more difficult. But very interesting. Game on, DA. It's actually highly addictive. Okay, let's go ahead and take a look at the cord. First of the top, we define our ladies, so we have our green led, which is connected to pin it on your greenoe red led to pin nine on yellow led to pin 10. If you didn't have green, red or yellow, you can change these variables today, depending on the color of led is that you have. But, um, that's how we initially set up the ladies and which pins they're connected to. Next. We have honoree for times on, so you can make this, you know, as big as you want it. Initially, it's set up with these four values and this is the duration in mili seconds that be ladies would be lipped. So as you'll see me toe on, what we do is to get that randomness we find we get generate a random number and pick from one of these two values. This is 1/10 of a second the quarter of a second, all the way up to 1/2 of a second. So you could tweak this and make different values in between here to change a randomness of the time such a led your other. These air on next is always wanna reefer delete times. And this is the random waiting period between which the led zehr lit. So again, I have four random values here 1/4 of a second half of a 2nd 1 second and 1.5 seconds. So remember these values air in mili seconds so you can add to these or treaties accordingly to change the complexity of the game. Next we have a couple of global variables that we declare that we want to access and set in our interrupt service routine. So, red led. Let we want to keep track of Wendy. Red led is let so that when you press the button, we could determine when that is. And if you were a winner, wanna keep track of that notice? With these two variables, we have to declare them as volatile. And the reason is because this is done so that they can be accessed on modified within your interrupts. It was routine. So just be mindful of that, then comes on set up function. We set our led XAS output. You've seen this before, and hands we re create our interrupt since we have attached that switch to pin to one year . And we know we define that as the zero interrupt. Specify O R I s r interrupt service routine function check winner on. We want that to happen on the falling. So when we push our switch on me, go from a high to a low voltage, that's when we went out, Interrupt the fire, initially turned off all our ladies, and there's a convenience function that I created to off ladies so quickly, go to that to show you what that looks like. Basically, in that function, we do a digital right to all the ladies telling them, look, so that turns off our ladies. So let's look at our loop function. First we wanna picking, led to light. So we used the random function on random. It will allow us to picking value between one and three. Here we also wanna picking a rightly time that the led is let so again we used a random functioning random function. This will generate a random number between zero and three. And we passed that into the ARY to get our time's honoree which we defined above to pick one of these random times so it would result in one of those random times there. So if we determine which led were going toe light and we have determined what period led is gonna be on, then we proceed toe light that led. So we call the light led function passing in the led that we want a light right, that which would be 12 or three. Those values corresponding to yellow, red or green and then we pass in the time that we're gonna like that every before. So let's quickly jump through this light led function. So as you can see here, it takes these two arguments the led that we got a light one corresponds the green to to read three to yellow. Andi do racial in milliseconds. They're gonna light it for So when this function is called, basically we have ah, switch statement here. If your led was one, that's a green one we hit on there. We do a digital rights green led high. That's gonna like the or like that Green Led. And similarly, if it was two that was passed in, um, we set the red led high. Also, the red led is important. So in this function, we also wanna change that flag Two red led lit. True. So we want to keep that sort of a global variable. Seeing that right now, at this point in time, all red led is lit. After this, we're gonna wait, so we're gonna put the lay duration. Remember, we had passed any time. We wanted already to steal it, so we don't leave for that time. And if uninterrupted didn't occur. We put red led in that false. So we switch it back to force. So that is our light led function. Then we turn off all the allergies. So again, this just sets them to off. Um, next, we wanna wait a random period of time. That led Czar. Often this would make the game unpredictable. So similarly, me get around the number between zero and three. We get a random time from or delete times a re, and we do leave for that random time. What we do then, is we check after that. If is winner. Basically, if that is winner flag set the truth. We wanna invalidated as winners false. And we call the winner function, which would cause the allergies toe light up three times. Right. So here, any winner function, this is where we do the three flashes in quick succession. So we turn the Elise Hi. Wait for quarter of a second to low and we do that for three times. All right, We Lupin here three times and then we diddly for three seconds. So that's a winner. So how is a winner determined? Well, when you push the push button switch and I'll interrupt Service Routine check. Winner is called Let's get good on to check winner Holecek. What it does is it checks at that point in time? Remember, wherever you are in echo what it's going to jump into here for to service our interrupt service routine. So I read a little. It is true. We set that global is with her flag and that is how in our main loop, if that flag was set, we know you have one. So we indicate that you have one and we set it back to false so quite a lot going on here. But, you know, take the time to go through the code and hopefully that explains the operation of our circuit. Let's take a look at the Arduino random function to get the documentation. So here, as you notice random, can be there to different forms of it. Electoral. We have used it. These two different variations in our program. It can take one argument Random Max and Max is the upper bound of the random value. You wanna generate exclusive meaning it it would not be included. So, for example, if you call random passing in three as your argument. It will generate a number that 01 or two on exclude three so your random range will be 01 or two would be a possible list of random values. The next way to call the random function would be random person in a min and max. Value and men is the lower bound of the random value inclusive. That means it could potentially also be included. So let's say we call this random function passing in one come before it would return to us in list of possible random values that are 12 or three. Remember, four would be excluded, so your options would be 12 or three. So hopefully that experience the random function Andi wanted just wantedto take a look at the documentation to clear that up for you to summarize. In this project, you learn how to apply an interrupt to detect important events in your circuit. You were also introduced to the random function for generating random numbers. Our game is addictive. Few Frito place a more and then we can jump into our next an equally fun project