Your first Arduino project: Design and Build a Colorful Musical Toy. | Bill Jamshedji | Skillshare

Playback Speed

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

Your first Arduino project: Design and Build a Colorful Musical Toy.

teacher avatar Bill Jamshedji, DroneBot Workshop

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

    • 1.



    • 2.

      What is an Arduino?


    • 3.

      Choose your Tune and Colors!


    • 4.

      Using a Solderless Breadboard


    • 5.

      LEDs and Resistors


    • 6.

      Piezo Buzzer and Switch


    • 7.

      Parts List


    • 8.

      Installing the Arduino IDE Software


    • 9.

      Hook up your Arduino


    • 10.

      Arduino Inputs and Outputs


    • 11.

      Arduino Sketches 1


    • 12.

      Arduino Sketches 2


    • 13.

      Arduino Sketches 3


    • 14.

      Wire up your Project


    • 15.

      Program the Arduino 1


    • 16.

      Program the Arduino 2


    • 17.

      Let's make Music!


    • 18.

      Playing Other Tunes


    • 19.

      Make it Unique!


  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

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

Arduino’s are a family of inexpensive single-board computers that allow you to create just about anything you can dream of with minimal technical skills.

This class will teach you to build your first Arduino project, a fun device that plays a tune and flashes colored LED lights. You can design it to play your national anthem while flashing your country's colors or get creative and make a unique tribute to your favorite sports team!

Don't worry if you've never worked with electronics or programed before, it's not a prerequisite. Just come prepared to learn something new and have some fun!

Meet Your Teacher

Teacher Profile Image

Bill Jamshedji

DroneBot Workshop


Hi - I'm Bill Jamshedji and I've been addicted to technology for nearly 50 years. Started building radios when I was 7, hand-wired my first computer in the mid 1970's and have been on the Internet since 1987.

I have always enjoyed creating things and these days I spend a lot of time building robots, quadcopters and devices for the Internet of Things. You can follow my adventures and see my tutorials on DroneBot Workshop and on my YouTube Channel.

I love learning and I especially love sharing my knowledge. Through my many careers (and I have had many) I've taught writers to use the Internet, website owners to do SEO and children to build solar-powered toys.

When I'm not immersed in technology I enjoy cooking and both listening to and creating music.

See full profile

Class Ratings

Expectations Met?
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%

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. Welcome: Hi, my name is Bill, and I'm in my workshop today with a really good friend of mine, a guy who I find really useful around the house and his name is Arduino. Now the yard. We knows a micro controller microcontrollers air tiny computers that are embedded into Elektronik devices to make them more intelligent. You'll find them in your television, in your appliances and even in your car and with my buddy, the Arduino Aiken. Build intelligent devices to let's say you wanted to build a burglar alarm or a home weather state you could use in our greenoe. For that, perhaps you'd like to experiment with wearable technology. Are dwindles, are perfect for that. Maybe you want to build something more sophisticated, like a robot or even a three D printer. You can use an Arduino for those things and so many more. There's really no limit to what you could do with this wonderful little device. Now in our project, we're going to build a musical toy. Using an Arduino is going to play a familiar tune. Well, it flashes some lights, something like this. Along the way, you'll be learning a little bit about electron ICS a little bit about programming and even a bit about music. But most of all, you were going to be learning how to use an artery. No. And once you learn to use in our green Oh, the sky's the limit as to what you could do. So please join me for the class will get to the work bench, get our Silas bread boards out, and we'll start learning to build within our gamino hope to see you soon. 2. What is an Arduino?: Hello. Welcome to my work. Bench. I'm really glad you decided to join me for this class. I think you're gonna find it to be a lot of fun and educational at the same time. Now, here's what we're going to be working on our class project. This is a Solace Bread board. It's a device we use for prototyping. Electronic circuits weaken wire things up with how it happened to start of them so we can reuse or components and came there circuit until we get it exactly the way we want it on the bread board of Mounted some electronic components a tiny push button, swift PS electric buzzer and three l e ds and some resistors. And I've wired this up to an ard Weena with, you see, beside the bread board over here, the Arduino itself is being powered by a power supply. There are a number of ways I could have powered it. I could also have connected a nine volt battery to it. Or it could have used a USB cable, the power from the computer. In fact, when we develop it, we are going to be using the U. S. B cable the power of the Arduino. Now the project is very simple. I pressed the button and it plays a tune and flashes the lights. Quite fascinating, isn't it? The rial fascinating part of it, though, is the Arduino itself. So let's take a look at the Arduino now. One thing you should know about the yard, we know is that there are several different aren't rinos is a whole family of these devices now. The Arduino I used for our project is called an Arduino Uno have another one over here. This is by far the most popular Arduino. So when most people speak of the Arduino, they're talking about the you know, it's a very inexpensive device. This is an Arduino Yunel clone that I picked up for about $15. So it's not a big investment, and you can reuse this in other projects as well. So it's well worth it. But there are other are DWI knows you could use in this project and also achieve success. Here is an art between Omega Now, As you can see, the Maiga is larger than the you know. The principal difference between two is that the Maiga has more connections on it so you can connect more devices to it. If you happen to have a Maiga, you can certainly use that to make the project. And the work is fine On the other end of the spectrum, I've got a very small Arduino over here. This is called an E T. Tiny, and it's aptly named. As you can see, it's a very small device. Believe it or not, this is capable of running the same code that this Arduino is. So you could build your project on the Arduino Uno and then transferred the code to the 80 tiny and run it on that to make your final product very, very small. You could even go one step further and transferred the code onto the process. Your tip that runs there. Do we know this little device over here? And you can wire this onto a circuit board and make it work the same way that it did on the you know. So the you know is a very versatile development platform, and the Arduino is a very versatile family, allowing you to build products and then eventually make final devices that are very small and very efficient. So now let's look at how the Arduino is actually programmed with your computer. Here is how hard we know programming works. First, you will need a computer. It can be Windows, Mac or Lennox Doesn't matter. You'll also, of course, need your Arduino on the computer You were runs the software called the Arduino I D E or integrated development environment. This is free software that weaken download from the Arduino website. He will write to program using the I. D. E and R DWI knows programs air called sketches and then you will connect the Arduino with a USB cable. This will power the Arduino and allow you to send your sketch to the Arduino. Once to sketch has been loaded on the Arduino Arduino will run the sketch. Once you're happy with the way your sketches working, you can disconnect the U. S B cable and get rid of the computer. Now you can power the yard. We know with a power supply and again the Arduino will run the sketch. The computer is no longer necessary. You can even get rid of the power supply and use a battery to make a portable Arduino project. So Now that we've seen how we program in Arduino by writing a sketch with their computer and sending it to the Arduino through the U. S. B cable, it's time to take a closer look at the Airdrie. No board itself. Now you'll notice that the Arduino has a number of connections on. A few of them are relatively obvious, such as the USB connector and the connector for an external power supply. But there are also a Siris of connectors around the board, and these are the important ones that I want to talk about. Right now. You can divide these connectors into three different groups. There's the power group, the Analog Input Group and the Digital I old group. Io means input output because these pins could be either inputs or outputs. Now, in our design, we will be using a couple of pins off the power group to supply five volts to our Silas Bread board so that we can run our L E DS and supply voltages to the other electronic components. We won't be using the analog inputs analog inputs air normally used with sensors that can measure things like temperature, air pressure or sound and send analog voltages to the Arduino. We do not use that in our toy design. We will, however, be using some of the pins in the dick. It'll Io group now. Digital signals can exist in two different levels. They represent either a zero or a one to a computer. Zero is normally represented by zero volts, whereas one is represented by five volts. Now we will be using one of these pins as an input, and that will be for our push button. When we push the button, we will send it five volts and then Arduino will interpret that as being a one. And then it will run the program that we've designed to run when it sees a one on that pin . We'll also be using four outputs on the Arduino. Three of the outputs will drive the three L E D lights, and one of them will drive the PS electric buzzer to make sound. So here's a closer look at how I've wired the Arduino into our sod Elice bread board. Now you can see that these connections over here are the power connections and sending five volts and ground out to the bread board to supply power to the electronic components. And here are the connections on the Digital i o Bus. Here's my output to the PS O Speaker, the three led outputs and the input from the push button. So this concludes our a quick look at the hard we know now. Obviously, there's a lot more that you could learn about these amazing devices, and the best place to do that is on The official are Tween a website, which is www dot Arduino dot cc. Please note that's dot cc and not dot com. Another good way of learning about the Arduino is to buy the official Arduino Starter kit from Arduino. Now this isn't about an 80 to $100 investment, but if you're serious about the Arduino, it's a great way to learn. They give you an Arduino, a starless bread board, a number of electronic components, plus a book with a series of experiments that you can run with the Arduino to really learn a lot about the device. At any rate, the next lesson we're going to do is to look at the toy that were building and to pick out the color of the lights that were going to be using and the tune we're going to be playing . So I'm looking forward to seeing you on the next video. 3. Choose your Tune and Colors!: Okay, We've looked at the Arduino and we're about to look at the parts we need to buy to complete our project. But before we do that, we need to discuss what our project is actually going to do. As you know, it is a musical toy. It's going to play a tune. What flashes some colored led s and the example that I've shown you already is the Star Spangled Banner with red, white and blue L E. D's. As we mentioned, however, you can change this to another tune and another set of led colors if you wish. And this is the point in which he should start making that decision now. If you've never done any of this kind of work before, I would strongly recommend that you at least follow my example for The Star Spangled Banner , get everything toe work and then go back and re program it for a different song. However, the led colors or something that you could make a decision on right now, if you will, we will be using three L E. D's. In our project. They could be three different colors or three of the same. Mix them and match them any way you like. I would suggest using three millimeter or five millimeter led visas. These are the most common variety and are very inexpensive. The's air available in a variety of colors, including red, green, yellow, blue, orange and white. If you would like your device to play a different tune, you will need to obtain some sheet music for your chosen song. You will need to know both the notes and the timing of the notes. Please bear in mind the simplicity of the project and don't choose a very complex musical piece. 4. Using a Solderless Breadboard: a Z mentioned in the introduction. We're going to be building our project using something called a starless bread board. Someone's bread boards come in a number of different styles. I have one style over here, and in the second I'll take you over to the work bench to show you another style you can use. What they're used for is to prototype electronic circuit within certain electronic parts and wires into these devices. Move them around until we get our circuit working correctly, and then we can go and build our circuit on something more permanent, like a perf border, a printed circuit board. So let's go over to the work bench and take a closer look at how a song was. Bread Board works. Here are two different styles of saw Dallas Bread Board. The one I was just showing you is on the right and another style of bread board upon which I have built. Our circuit is on the left. You could use either of these bread boards for this project, and they would work fine now. One thing I should point out is that in both examples, these air, not individual bread boards, bread boards are designed to be stacked upon each other so you can build larger circuits. And so the one on this side has to bread boards stacked together on this side of act. You got four bread boards, so let's take a closer look at the bread board. What the bread board actually is is a series of small sockets, and each socket is capable of accepting the lead oven electronic component or a piece of hookup wire or a special bread board jumper wire. Now the sockets air interconnected. So, for example, this tiny socket here is connected to the one next to it, and the one next to that etcetera. All five sockets on this particular rower connected all five sockets on this roller connected to each other. There's also sockets on the other side, and these rows are separated by a gap, and I'll fill you the purpose for that gap in a second so that sockets on this side and the sockets on this side of the gap are not connected to each other. Bread boards also have what they call buses, buses or where we connect power or ground connections, so they run down the side So all the connections down this side, for example, or one bus. This is also another bus over here. This is one over here. So I would have normal cases connect my five bolts in my ground two buses because I have a lot of connections that my circuit will need to make to the power supply and ground. Now, onto these little connectors, we could insert little jumper wires. This is a jumper wire that I've inserted in here and since all the connectors on a on the same line or connected via insert a jumper wire over here, I have now electrically connected these two wires through the bread board. The bread board is also sized to accept electronic components, and that is the reason for this gap here. This is size to accept integrated circuits. What, You're very common electronic components. We won't be using an integrated circuit in our product today, though, So now that I've plugged my integrated circuit or I see into the bread board, each of the pins of the I C is connected to four adjacent pins, and so I can wire things directly to my integrated circuits simply by plugging in jumper wires or actually by connecting electronic components directly to the bread board itself. Now here's the bread board that I've wired our project to. As you can see, it's a slightly different style, and the difference is there are two power buses on each side of the bread board, as opposed to a one that the other style has. This can allow you to connect multiple supply voltages, and it's for this reason that I prefer this style of bread board myself. But again, for this project, either style will work. Fine, as you can see, have used bread Board to mount all the electronic components of our project. Got the led is over here and there Associated resistors of gutter PS electric buzzer over here, and I've got the push button along with its resistor. There, a number of jumper wires air used to connect the components together and to connect them back to the herd. We know the bread board is even being powered off of the Arduino as well, and I'll show you that in a future video. Now, in order to hook up components on your bread board, you're going to need some jumper wires you can make your own jumper wires out of 22 or 24 gauge solid wire to strip some of the insulation off of each end, and you've got yourself a custom made jumper wire. But I prefer to use pre made jumper wires like they could be used over and over again, and they're very convenient. They come in a lot of different colors, which will make it easier for me to sort things out when I make a very large circuit. Now, as you can see, I've got an assortment of these over here. Closer. Look at the end of one. Ah, what you'll see on the end there is that the wire has a little tip that's been pre made to fit into the bread board, and this will last a very long time, and it's very convenient. Also got other wires inside here that you might find useful, although you won't need them for this project. Things like these ribbon cables, which connect the bunch of wires together, can be very handy when working with an Arduino. When you're connecting, let's say half a dozen different connections. Some of these also have different style sockets they have male sockets on one end and female sockets on the other end so that they can connect to external components and sensors except and bring those connections back to the bread board. In short, having a good selection of wires is really something you're going to want to do if you intend to continue experimenting with electron ICS, which I hope you do after you build this project. 5. LEDs and Resistors: So, of course, the heart of our musical toy is the Arduino, but there are some other electronic components we're going to need to use as well in order to complete the project. So now let's take a look at a couple of those. We'll start off by looking at L. E. D's or light emitting dial's and resistors. An led or light emitting dialled is a semiconductor device that is capable of producing light of a specific color being a semiconductor device. Led czar polarity sensitive L E. D's have to Leeds and an OED and a cathode. The an old lead, which is generally the longer of the two leads, is always connected to the positive of the power supply led zehr. Available in a wide variety of colors, a resistor is an electrical device to come limit the flow of electricity. A resistor is specified by its resistance, which is measured in homes. Resistors of over 1000 homes are generally specified in Kiel, OEMs and over a 1,000,000 homes in mega homes. Resistors air available in a number of different sizes, the sizes correspond to the amount of wattage bacon dissipate. For our project, we will be using the most popular type of resistor, which is the quarter watch resistor. The value of the resistor is generally indicated by a series of color coded bands on the resistor itself. 6. Piezo Buzzer and Switch: wait. Look there, Dwayne O T, L E D's and the resisters in our project. That only leaves the switch and the PS electric buzzer to take a look at. So let's do that right now. The PS electric speaker is also referred to as a buzzer or a transducer. It is a very efficient device capable of producing quite a loud sound with very little electrical current applied PS O speakers or buzzers air commonly used in video games and smoke detectors and other areas were allowed. Sound is required without high fidelity. Interestingly, the PS O can also be used as a microphone, although we will be not using it for that. In this project, the push button switches a very simple electrical component that essentially just connects or disconnects an electrical circuit. The switch were using a specified as an S P S T, which stands for single pole single throw. This is the simplest type of switch. Make sure that you specify a momentary contacts, which, as this is the type of push button we will be using, the other type of push button is a toggle switch or push on push off, and that would not be suitable for this project. 7. Parts List: Now that we've looked at the components for our project, let's gather them together so we can actually build it. The first thing you will need is an Arduino uno or Arduino Uno clone. You will also need a USB A to B cable. This is the same type of a cable that you would normally use for a printer. Here, Arduino Clone or Arduino may have come with this cable. You will need three l E ds. I would recommend either three or five millimeter variety. You may choose the colors as you wish. He will need 4 1/4 watt resistors. Three of these resistors should have a value of 330 homes, although any value between 154 170 OEMs will suffice. The remaining resistor could have a value of 10,000 homes, which is also referred to as 10 key loans or simply 10-K Any resistor with a value of 5.62 22 key loans will work. For this. You will need a PS electric buzzer or speaker. You will need a push buttons which this will be an S P S t. Momentary contact switch. He will also need a sawed Elice bread board. You can buy a small bread board with 400 contact points or a larger one with 830 contact points. Either will suffice for the project. Along with the bread board, he will need 10 jumper wires. You can either buy specific bread board jumper wires, which may have been included with your bread board. Or you can simply use 22 or 24 gauge solid wire and stripped the ends yourself. So now you've got to shopping list. It's time to go out and purchase your parts. Now, if you've never bought Elektronik components before, you might be a little bit confused as to where you can purchase some of these things. So I want to give you a couple of suggestions. Keep in mind that none of these air necessarily endorsements now. First of all, if you live in or near a large city, there is probably one or more Elektronik distributors. You may not even be aware of them, but they're they're likely they'll be in an industrial park area. You never know. Check out your yellow pages or Google and just Google for electronic parts or electronic components with the name of your city, and you might find something. Alternatively, you can buy these things online now. There are large electron ICS distributors like Digit Key that will have all of these things . But I have to confess their websites a bit overwhelming for people who have never done this before. And they're the kind of company that usually sells things by the 1000 although they will sell individual components, another great source online would be Arduino itself. Arduino sells a number of starter kits, and any of these starter kits would contain everything you need to build this project, such as an Arduino uno, a bread board and a number of electronic components. And they also come with guides to learning about the Arduino. So that would be a great investment if you intend to continue working with the Arduino. Otherwise, there are specialty stores like eight of Fruit or Spark Fund, these Air electron ICS components stores that catered ah, hobbyists, and they will have all of these components along with a lot of other cool components as well. Ah, great place to shop, believe it or not, is Amazon. I buy a lot of stuff off of Amazon between Amazon themselves and the dealers who sell through Amazon. You'll be able to pick up everything you need to build this project. E Bay is another good source. Of course, delivery could take a while with some of the eBay suppliers. But eBay will give you some great deals on these components as well is going to some of the Chinese distributors who advertise online. Now they'll give you the rock bottom Price is. The one thing, though, is that you'll have to be aware is you may wait a month or two for delivery. However, having said that, I buy a lot of parts directly from China because simply the prices air. Great. Now, when you're buying things like L E. D's and resistors, you may find that it's hard to buy. Individual ones need to buy at least packs of 10 or maybe even packs of 20 or 25. But keep in mind that if you're going to continue working with electron ICS, he will reuse these things. And we're not talking about expensive components. I buy resistors for less than a penny apiece, and I buy led s and bulk. And they usually cost me about three cents or so on average. The cost of led is varies depending upon the color, but none of them are that expensive. So anyway, I hope that helps you with your shopping. Good luck with it. Pick up the parts and join me on the next video. 8. Installing the Arduino IDE Software: now, in order to work with the yard, we know you're going to need a piece of software called the Hard Reno Integrated Development Environment or I D. E E. So let's go and install that on the computer right now. I'm gonna show an example of installing this for Microsoft Windows, but you can also install the I. D. E on a Macintosh or on Olympics workstation. The first step is to go to the Arduino website at Arduino dot cc. Now click the download link and from there choosier operating system. I'm going to cues Microsoft Windows. You can contribute or just click the download button. To begin the process, select the location to save the file and wait for the file to download. When the download is complete, open the folder that you downloaded to file, too, and click on the file to begin the installation process except all license agreements. And unless you have a specific reason except the default settings as well. When the installer is finished, you'll need to install a USB driver for Microsoft Windows. Once that's done, close all the windows and you should see an Arduino icon on your desktop. Click on the icon to open the program the first time you run it on windows, you'll need to allow the windows firewall toe, have access. And there you have it. The Arduino i d is now installed on your computer. 9. Hook up your Arduino: start working with the hard we know we will need to connect it to our computer. We will accomplish this with the U. S B cable, the aid to be cable that you purchased or that came with your Arduino plug one end of the U . S. B. Cable into your computer. It doesn't matter if you use a USB two or USB three port. The Arduino itself is a U. S B two device. Take the other end of the cable of so called printer end and plugged that into the connector on the Arduino. When you do, you should see a power light light up. Now your Arduino may have the lightened different position. That's fine. He may also see another light, this light here that is flashing. I'll explain the use of this light in a few moments, so don't be concerned about that right now. The next step is to go to the Arduino i. D. E program that two installed on your computer and make certain that you're actually connected in communicating with the Arduino, navigate to the Tools menu and then choose ports. And in the port menu, you could see an entry on a Windows machine. This entry will read something like Com three come for It will read something different on a Mac machine or analytics. But it doesn't matter. As long as there is an entry there in the com Port, you're communicating with the Arduino and are ready to proceed to write code and dump it to your Arduino. 10. Arduino Inputs and Outputs: now. When I first discussed the Arduino with you, I'd explained that the Arduino has a number of input and output ports that are going to be useful in our design. I want to go over that concept just a little bit more right now because it's very important now. The ports we're interested in are the digital input output, ports and a couple of the power ones. You may recall that the Arduino also has analog connections, but we aren't using that in this design. Now a gain. The digital ports on your Arduino are up over here, and these are the power ports down over here. Now, one thing to observe about the digital ones is there numbered, and they're numbered on the, you know, starting from number zero and going up to number 13. Therefore, they're being 14 ports 0 to 13. It's very common with computers to start the numbering with zero and not with one. If you're using a different our adrenals, such as amega or a nano, you'll find that you have a different number of ports, but that doesn't matter. You'll have the same ports that we're using in our design. Now we're using these ports as both inputs and outputs. The ports can be configured through the software to be either. This particular port over here is being used as an input, and it is being connected to port number two. Ports number 34 and five are being configured as outputs. They're going to R L E D's and Port number 12 is also being configured. Isn't up put? It's going out to the PS electric buzzer. There are two other connections to the power that we're making as well. This is the supply power to our Silas bread board. You may recall it told you the Arduino can be powered off of either it's USB or from an external power supply or battery yard. We know has on board a voltage regulator, which will turn whatever voltage you place into here into five volts. If you're giving at USB, USB already is five volts. The Arduino supplies this five volts so that you can run external circuits and you will find a ground and a five volt connection down on the power bus. And that is what we will be connecting to our bread board 11. Arduino Sketches 1: way. So now that we've hooked the Airdrie no, up to our computer, it's time to start learning how Arduino sketches actually work. Before we begin, I wanna 0.1 thing up to you on my work bench. I've got a computer built in. You can see about a keyboard Trey under here. And actually, my our Drina was pumped into a connector on the workbench with those to the U. S. B on the computer, and that's very useful to May. But the thing I wanted to point out to you is the computer on my workbench is a linens computer. So the screens I'm going to be showing you may look slightly different than the ones that you're using because I assume you're likely using Windows or a Mac. It doesn't matter. Everything will work identically. It doesn't matter whether you're using a Mac clinics or windows, but I just wanted to point that out. Just still. You don't get confused about the differences in her screens. So with that said, let's go and take a look at our first Arduino sketch. So we're in the Arduino I d e e and what we're going to do right now is learn a little bit about using the I D E and using sketches as you recall sketches or what they call programs in their DWI. No talk. Now Arduino has supplied a number of examples sketches that we can use. And so let's take a look at a couple of them. If you go under file and go under examples and then basics, there's one called Bare Minimum. Let's load that you'll notice it opens up in its own window. This is typical, so you could be working on more than one sketch at once will expand that so we can see it now. Bare minimum, as the name might imply, is a sketch that doesn't really do anything. It just has the minimal components to be considered a sketch, and it shows you the two critical areas that have to be in every sketch. First is an area called the set up area. In the set up area is where we put the code that lets dared we know, know how it is supposed to be configured. In other words, retell it. If the digital pins are set to run as inputs or set to run as outputs. The other area that is key in every Arduino sketch is the loop. Now the loop is where the actual code is going to go. When an Arduino was first powered up or one of his reset, it begins to run whatever code it finds in the loop. So in the case of our toy, all the code to make music and to wait for the push button to be pressed is going to be written into the loop. So now that we've seen bare minimum, let's open up another Arduino sketch, one that most people work with the first time that work within our Galino. And again we'll go into examples and basics, and we will load one called blink. Now the Blink sketch is a sketch that simply flashes and led on and off, and conveniently, Mostar DRI knows haven't led that is connected to Pin Digital 13 or D 13 on the board. This way we can monitor and troubleshoot circuits without having to actually even connect anything to the Arduino. Blink will simply flashing led, turning it on for a second and then waiting a second and turning it off and waiting one more second and what we're going to do in our next video is toe work with Blink, send it up to our board and then modify it to prove that we're actually really working with Arduino sketches. 12. Arduino Sketches 2: So now we're gonna look at the blink Sketch sketched. It flashes the light on and off. Now blink starts off with some comments. Comments are simply what they sound like. They have nothing to do with the program, and they don't affect its operation in any way. They're simply there so that you can share program with other people and explain how they work. And so you can leave notes for yourself in case you have to go and modify one of your programmes a few months after you wrote it. There are two ways direct comments in the Arduino coding. You can do it this way like we have the top where you have a slash and a star followed by a star in a slash. Everything between these two points will be ignored by the Arduino, and it's simply a comment. Another way of commenting is too straight to slashes everything on the line after the two slashes will be ignored and will be considered the comment. This is actually good technique when you're programming because you sometimes want to eliminate a bit of your program, and rather than erasing it, you can simply commented out temporarily now underneath the comments we have one statement into led equals 13. What does that mean? While int means integer means we're defining an integer and into jurors a whole number like 1234 as opposed to a number like 26.2 or 19.7 inter jurors air also positive in most cases . But they can be negative as well. Now we're defining an integer on. We're giving it a name and we're calling it led. We could have called it anything we wanted to, but we usually give the things we define descriptive names so that later on they make sense to us. And then we're giving that integer of value of 13. So what's important to know here is that we've given an integer called Led of value of 13. Now we go to the set up If you recall from the last video set up is how we initialize the Airdrie No, and let it know what we're using its pins for. And we're gonna use one pin in this blink sketch with one that flashes the l e. D. And that is pin 13. So we're going to initialize this digital pin as an output. And here's the actual statement pin mode led output. Now what that means is that pin mode is a command that lets us know whether the set the pin as an input or output. L E d is what we defined up the top over here, so L e d actually has a value of 13. In fact, you could replace the number 13 and there, and it would work just fine. And then after a comma, we have the word output. So we're telling it that the pin led, which is, in other words, Pin 13 is going to be an output. When we write our sketch for our toy, we will have to define which pins were using his inputs and outputs. The beauty of calling this led instead of just simply using the number 13 is that if we decide the blinking different pin, all we have to do is change the number up here and the rest of the program worked is probably and then we come to the loop Loop is what actually runs a program. In this case, it will blink, are led and we have a couple of commands here. They may seem a bit cryptic, but they're really not that difficult. The first ones is digital, right? Led high. That means digital right means write something out to the digital output. The output is number 13 which is only D, and we're going to send it high. As you recall high means send it up to five volts. This will turn the led on. Then we're going to put a delay in and a delay says 1000 now delays air simply a time delay and the number after them tells you how long to delay for DeLay's are in milliseconds, So 1000 milliseconds is one second. So we're writing to the led, making it go high. Then we're gonna wait for one second. The led will stay on at that time. Then we're going to write to the led on this line, and we're going to send that low. In other words, we're going to turn it offs and zero volts, and then we're going to delay for another second again now, because this is the loop. Everything in the loop when it gets to the bottom simply goes to the top, have runs over and over and over again. As long as they are. Torino is powered up. So what? The Blink sketch. We're gonna turn the led on. Wait a second. Turn it off. Wait another second, and then Gope repeat the whole process until we turn the power off on the Arduino. 13. Arduino Sketches 3: Now that we understand how the Blink Sketch works, let's see how we move the sketch from the Arduino i d. E out to our Arduino on the top of the Arduino i d Either is an arrow and the aero says, upload clicking that will upload the sketch to our Arduino. I'm going to do that right now. And as you'll notice, Mired, we know flashed very briefly as the traffic came from the computer and was loaded into the Arduino, and now it is running the blink sketch. That's kind of impressive. Except, of course, my Arduino came out of the factory running the Blink sketch. So let's see if we can send it a slightly different sketch. If you're gonna be working in an Arduino sketch, it's a good idea to save it first. So let's say this under a different name and we're gonna call this blink Blink again. You could have called it anything you wanted to. I'm doing this just to avoid overriding the original Blink sketch. Now let's look at the business end of the Blink sketch where we have the delay. A pretty simple modification would be to change that delay, so Let's go in and change these one thousands to five hundreds, okay? And we'll save that sketch. And now we'll send this up to our Arduino, and now you will notice. The led on the Arduino is blinking twice a Sfax. In other words, it is accepted the new sketch, and it's over, written in the old one. Every time you upload a sketch to the Arduino, you overwrite the old sketch. So now that we've worked with the Blink sketch, it's time to actually build our toy. 14. Wire up your Project: So now we're ready to wire up our project. Now, I realize this may be a little bit difficult to follow on a video, so you will find in the attachment with this class in wiring diagram that is much easier for you to follow along with. I'm going to start off by taking my Arduino and taking the power outputs and supplying it to my bread board. I let giving my bread board power when I wire oppa circuit. Now, as you recall, the connections down to bottom are the power connectors. And if you look about three in, you'll see one that's labeled us five bolts and then a place a wire into that, and right beside that, the next two connections are ground. You can use either one of those, so I placed a wire in that No, I used a red wire for the five volts and green for the ground because it's kind of conventional, but you can really use any color you want, as long as you know what the color is. So I'm taking my five volts and ground. Now I'm going to supply them to the bus on. My song was spread board. So now what I've done is the Arduino is going to be powering these two bus lines with five volts and ground, and I also want to use ground bus on this side of my bread board as well. The reason for that is it keeps the wires away from the L E. D s, and they're a bit easier to see, and it's also a bit easier tow wire up. So I'm going to take a wire and connected to the negative here, and then connect that to the negative on this side of the bread board. So now I've got a ground on both this bus and this bus over here. Now that I've connected my power buses, the next thing I'm going to do his wire up some l e ds. Now I've got an led over here. This is a red one. And as you can see, one wire on the led is longer than the other one. This is the an ode or the positive wire. And so I want to make certain that connect. My led is up correctly. I'm gonna connect them across this gap over here. It's gonna be a bit easier. So the long side is going to be facing this way and the short side, in other words and negative is going to be facing down here and you'll see why I'm doing that in a few. In a few seconds, let's put my red led over here and I'll get my white led and put it there. And finally the blue one. So there I have my red, white and blue L E D's. Now. The next thing I'm going to do is hook up some resisters. I have the 3 330 ohm resistors there. These air water called current limiting resistors. They prevent the led from getting damaged by putting too much current into them and they go between the led is negative terminal and the ground. And that's why wire to ground over here. So I'm gonna connect one end to the same rose. The led and another end will be connected to the ground, and I'm going to repeat that for the next two LTD's and finally, on the other side of the L. E. D's. I'm going to connect some wires that are eventually going to go back to my Arduino Now I'm going to use a red, white and blue wire, so I know which one goes toe which led again. You can use whatever color do you like. So on the positive or an old side of my led connect the red and the white and the blue led to the wire. Okay, so now I want to show you something that we can do to actually test our wiring so far. Now, to test this, I'm going to actually hook up the Arduino again. I've dim the lights a bit, so you can see the l e. D is a bit better. Now I'm gonna hook my Arduino up. And so the Arduino is now supplying five volts and ground to my circuit board. Normally, when you wire the board, you won't have the Arduino powered, But this is just a test right now. Now, as you recall, I've got red, white and blue wires connected to the positive end of the L E. D's and the negative end of the L E. D's are connected to the ground through some resistors. And so this means that if I connect five volts up to any of these wires, it should actually light up the l E d. So we have five volts in this line here that's kept that. And lo and behold, our red wire is connected to the red led, and that's working. How about the white one? Yes, indeed. The white one works. It's kind of blasting a thread one there in the video and the blue one. It's a little hard to see, so I'll turn the other ones off. There you go. The blue one. So now that we have the led is wired and tested, we're gonna work with the PSL buzzer next. Now, like the led is the P as a buzzer has a polarity, if you can see there, the little plus sign on here and that is supposed to go to the positive lead on the other end will go to ground again. I'm gonna put the peers of buzzer across the gap in my bread board, and I'm gonna note where the wires actually go because they're going to be covered by the buzzer itself once it's in there. Okay, so they're going to hear, and opposite there. Now, one end of this I'm simply going to ground and the other end. I will connect the wire that will eventually again go to the Arduino. Once again, I'm going to test my wiring by hooking up the yard. We know to the U. S. B. So I have power on the board. Now, As you recall, the PSL buzzer has its negative side connected to the ground, and its positive side is waiting for an input from the Arduino. When I apply voltage to the P as a buzzer, it will emit a sound. And so if I connect this to five volts, I should get a sound. Now, the next component, the wire, is my push button switch. Now, if you take a look at the bottom of the switch I have it might be a little confusing because there are actually four leads even though they push button should really only have two. The reason is simply that these two leads here are connected together as air. These two leads here, so you can use either of the leads on this side and either of the leads on that side. So I'm gonna put this into my circuit board. You have to be careful mounting these so you don't break leads and then I'm going to get my 10-K resistor. Now, what the resistor is doing is it's gonna hold one of the inputs down toward ground. This is what's called a pull down resistor. When we push the button, we're going to send five volts that input and make it high. So I'm gonna connect one end to my push button on one end to the ground. I'm going to use the ground on this side, although it could have also gone from here to here, and it would have worked just as well and then going to take a lead and put it into the same connection. And this is going to go to the input on the Arduino. And then finally, I'm going to connect five volts to the other side of the push button. And so the idea is, when the button is pressed, it will send five volts out of this line. When the button is not pressed in, this connection is open. The resistor will pull the line down toward ground and send zero volts out, which will be a zero to the Arduino. Once again, we're going to check our wiring before we hook everything to the air. Do we know now? As you recall, the push button sends five volts of this yellow wire whenever it is depressed. Five volts is also what the PS O Speaker needs. So let's just use that in order to test the button, I'll take the orange wire that have connected to the Piazza speakers positive side and temporarily connected to the same place that this yellow wire the output of the push button , is going on when I passed the button. As you can see, that seems to work. So let's disconnect that orange wire and get it ready for the Arduino. And the last step is to connect these inputs and outputs to the Arduino. So let's finish off our wiring and hook everything up to the Arduino. Now the first thing I'm going to hook up is the PS electric buzzer. Now, this is a digital output, and it's gonna be hooked to pin number 12 or need 12. So take a look for the 12 marker on the side and hook the orange wire up to that. The next thing I'm going to hook are my L E. D's. The red one is going to go to pin number five. The white led is going to go to pin number four and the blue one to pin number three. Of course, you may have chosen different colors for your L E. D's, and that's fine. Dis wire them to the same pins. And last but not least, is our only input with one from the push buttons, which and it connects to digital input number two. And there you have it. The entire wiring of your project is done. Now the next step is to actually write a sketch so that this will work. 15. Program the Arduino 1: Arduino project is going to require a sketch sketches, as you recall, or what they called programs in Arduino. In order to make things easier, I have attacked the sketch that you need to this class. Just look in the class attachments for a file called music toy dot zip And please download this to your computer. Once music toy dot zip is downloaded, locate the file and extract it. You can place it anywhere you wish I would suggest looking in your documents file for the Arduino folder and placing it inside there. But again, it's your choice as long as you know where you placed it. After that opened up the Arduino i d e e In the i d e under the file menu, choose open navigate to where you downloaded and extracted the file. Open the music toy file that will have a little Arduino symbol. He could actually notice it to files. Open up. Now, If you look in your open recent, you will see something called Music Toy. So just to make certain close the Arduino I d and then reopen it. If you look under recent gain, you should see your music toy file And this is how you will locate and work with your Arduino sketch 16. Program the Arduino 2: now those of you who were observant will notice there are actually two files here, one called Music Toy and another one called pitches dot H. What pick his daughter, H is is a library. It's a collection of items that we could use in many different programs. So instead of writing them directly into music dot toy, they've been kept in a separate file, so that could be used again. In this particular case, pictures dot h defines all of the musical notes on a keyboard. Now here, for example. Note. See, one would be a C on the first doctor, and it's got a frequency of 33 hurts. Here's a C sharp one with 35 hertz. Here's a D one with 37 hurts. Those of you familiar with music will know that at 4 40 hertz, we have a over middle C. That's what tuning Forks air often calibrated to. So there you are. Note a four meaning and a in the fourth octave. Now back to the main sketch. In order to use all of the items in pictures dot h, all we need to do is include this statement here include pitches dot H And then all of the constants inside here will be included and available in our main sketch. Now, let's take a quick look how the sketch works. If you'd like some details about this sketch, please visit the link of giving you to my website, where I will give you detailed details on how this sketch actually functions. But let's just look at some of the main elements in it. First of all, as before, we're defining a number of Constance, and I've called these ones things like PS hope in our pin w pin and be pin for the red, white and blue L E D's and then peep in for the push button. And I have given them definitions. So PS open is 12 um, the AARP Innis five. The W pin is for beep in his three. Now, if you remember, we connected her PS o buzzer toe output number 12 on the Arduino are red to number five are white, the number four and are blue two number three and on number two. We have the push button switch. Now, if he wanted to change the wiring and move these items of different pins, you could do that and you'd simply came the number in this section. Now, over here is where the actual music is. The music is written into two different arrays or raise our large groups of numbers. And most programming languages, like the Arduino language, will support arrays there. Actually, to raise this array gives you all of the notes in the song that we're going to play. And this array, which has the same number of elements as the one we just looked that gives you the duration of the notes and the duration is written as as a number. So what? Two would be 1/2 note of four a quarter note and ate an eighth note except trick sector. Those of you who know something about music will no doubt know exactly what I'm talking about here. Now we go into the set up for our program, and we're setting things up is inputs and outputs. So we're setting the push button. Pinup is an input, and the rest of the pins were defining as outputs. And then finally, the loop, the business that actually runs the program a gain. I won't go into detail on this because I want to keep this video short, but you can visit my website to get more details about how the program works. Essentially, this is where we're checking the state of the push button to see whether it has been pressed or not. And when it presses, we toggle the state. We, in other words, if we aren't playing music, pressing the push buttons caused the music to start. If we are playing music, pressing the push button should cause it to stop. Here is where we send the output to the L. E. D's, and we have three different lines for the three different sections in the 1st 1 The red one is on. The other two are off in the 2nd 1 the white ones on the other two are off, and the 3rd 1 the blue one, is on with the other ones off. 17. Let's make Music!: Elrod right all its leftist. Load the sketch to the Arduino and see if our in musical toy actually works. So the i d e. We go to the upload button, I would click it. And if you watch the Arduino the same time, you can see if you lights flicker while the sketch was loaded. The sketch has now been loaded. Let's test it out and it seems to work. Okay, so we're making music with heard. We know we've got the code loaded onto the yard. We know everything's wired up to it and it seems to work. There is one other thing I want to demonstrate to you at the moment the Arduino is plugged into my computer. That was so that I could dump the code down from the Arduino i d. E. But also, the computer is supplying power to the Arduino through the U. S. B cable. Now that the code is on the urge, we know there is no need for my computer anymore. So I'm going to disconnect my computer. I want to take this USB cable and plug kissed into a regular USB power supply. This power bars got a couple of USB power supplies. So now I'm powering the Are Tween off the power supply. There is no connection anymore to my computer, and yet we still have a working circuit. This is proving that the code on the Arduino is capable of executing on its own. It needs no external computer, and I could plug a power supply or nine volt battery into this and achieve the same results . So if you've come this far, congratulations. You have built an Arduino musical toy. Now, of course, Air Toy right now is on a bread board, and it's not that pretty. And while it's probably really need to show this off to people, especially if you've not done this kind of thing before, it would be even neater if it was in some kind of its own custom enclosure. There also might be a possibility that you might not want to play The Star Spangled Banner . You might want to use another tune. So if you stay with me for the next couple of videos, I'll show you how you could move this onto its own permanent enclosure and how you can change the song to something else. 18. Playing Other Tunes: if you wish, you can modify the music toy sketch to play a different song. In order to do this, he will need to know some music theory. I would suggest starting with a simple song. You can always make several modifications until you get the song correct, and ideally, you will need the sheet music, or at least the notes and timing for the song of your choice. Now I certainly can't go into a full blown music. Very lesson here, but essentially music consists of a series of notes. There are 12 notes per active. If you look at a piano keyboard, you will see them grouped in syriza's of 12. Each note has a specific frequency. If you raise an octave, you are doubling the frequency, whereas if you lower and note by one octave, you are half ing the frequency. Now, in addition to the notes in the song, you will also need to know the duration of each note. In music. Duration is specified by using things like full notes, half notes, quarter notes, eighth notes, etcetera, etcetera. You will need to know the notes and the duration of every note in your song now When you go to modify the music toy sketch, you will be modifying two different arrays, a raise, our collections and there are two of them in our sketch. The melody array contains all of the notes in sequence, and the note duration array specifies the duration of each of the notes in the same sequence. Let's take a look at our sketch now, and I'll show you what I mean. The first array we will examine is the melody array. All of the values in between two squiggly brackets are the values within the array, and this array contains all of the notes in the tune. In sequence below it, we will find the note duration array again. The values in between the squiggly brackets are the note durations, and they're in the same sequence as the melody array. So there will be a corresponding entry in the note duration array toe one in the melody array. By the way, if you need to enter a stop in the duration array, just use a zero. Now let's take a quick look at pitches dot h. This is where we actually define the frequency of each note, and here ice highlighted one octave of notes so you can take a look at them. So hopefully this will give you a little bit of a nine idea as to what it is you need to do to change the music on your musical toy. 19. Make it Unique!: So now that you've completed your project on the song list Bread Board, you may want to make a more permanent version of it. There are several options for doing this. If you were going to be manufacturing a large number of these devices than the only real option would be a printed circuit board. You would have to design a printed circuit board for this, which in the case of this project would be quite a simple one. And then either etch them yourself or send them off to a service. That X system for you. If you're making dozens and dozens of these, this is really the only way to do it. However, I suspect you're only going to be making one of these projects, and for that you could use something called a perf board. I hope you can see this. This is a perf board. It's got a number of little pads on the back, and you could insert electronic components like this. Led, for example, of his put into my perf board, and now it's mounted on the board with a place on the back disorder. It the idea is you mount all of your components on the perf board and then use small jumper wires and saw them all together. Perf boards are built on what's called a 0.1 into spacing for all the holes, and that's a standard among electron. ICS is the same spacing your funding your bread board. You can also get specialized perf boards that are actually made to emulate bread boards. They have the same design pattern, the same row of wires connected together, and with those you can simply take the components off your bread board, put them on the PERF board, run the wire is exactly the same way. You have the jumpers and you come up with the same circuit. These air a great way to build something permanent, although it doesn't shrink the size of your device anymore. Speaking the freaking sizes, I had felt the 80 tiny the very beginning of this course, and I wanted to point this out again. The 80 tiny or the Arduino Nano are very small versions of the Arduino Uno, and they would both be sufficient for this project. They are physically a lot smaller. In fact, you could mount an 80 tiny onto a little perf board make a device about this size. The 80 tiny has a micro USB connector instead of the USB type Be connected that we have on the you know. And it only has six input output pins. But since our project is only taking five, it'll be completely sufficient. You could take the same code that we used on the Arduino Uno downloaded to the tiny. And why are your devices to that? And make a very, very small version of this that you could also battery power? Um, now, when you're building your device, you're gonna want to put it into something, and there are a number of different things you can use for enclosures. I've been playing with electronic since I was about seven years old, and I have built things into just about anything. Uh, look out for old food containers, things like margarine containers and things like that. They're great to build electronic project into, and they're really easily available. Check out your dollar store. You'll find all sorts of things at the dollar store that you could build your components into Elektronik stores themselves cell specialized enclosures for building electron ICS projects. They're a bit pricey, but sometimes you can get surplus ones that air pretty. Keep an Altoids or seacrets container is a classic, and if you use a small battery and an 80 tiny, you could fit this entire thing into that. Also, take a look at, perhaps, and toys, perhaps an old toy or something. You could mount the electron ICS, including a full size Or do we know inside the toy along with the battery and good fancy? Put a push button, slips on the back of it and make the eyes light up when the music plays. In other words, use your creativity and that's what this whole thing is above. So I hope you have enjoyed this class. I hope you've learned something from it. And what I really hope is that this inspires you to start working with the Arduino and learning about all of the fascinating things that you can do with it. Thank you very much for joining me. Have a great day