Arduino Master The Arduino Basics Written by Dan Riley © Copyright 2017 by Dan Riley - All rights reserved. The following book is reproduced below wit...
34 downloads
99 Views
502KB Size
Arduino
Master The Arduino Basics
Written by
Dan Riley
© Copyright 2017 by Dan Riley - All rights reserved. The following book is reproduced below with the goal of providing information that is as accurate and reliable as possible. Regardless, purchasing this book can be seen as consent to the fact that both the publisher and the author of this book are in no way experts on the topics discussed within and that any recommendations or suggestions that are made herein are for entertainment purposes only. Professionals should be consulted as needed prior to undertaking any of the action endorsed herein. This declaration is deemed fair and valid by both the American Bar Association and the Committee of Publishers Association and is legally binding throughout the United States. Furthermore, the transmission, duplication or reproduction of any of the following work including specific information will be considered an illegal act irrespective of if it is done electronically or in print. This extends to creating a secondary or tertiary copy of the work or a recorded copy and is only allowed with express written consent of the Publisher. All additional right reserved. The information in the following pages is broadly considered to be a truthful and accurate account of facts and as such any inattention, use or misuse of the information in question by the reader will render any resulting actions solely under their purview. There are no scenarios in which the publisher or the original author of this work can be in any fashion deemed liable for any hardship or damages that may befall them after undertaking information described herein. Additionally, the information in the following pages is intended only for informational purposes and should thus be thought of as universal. As befitting its nature, it is presented without assurance regarding its prolonged validity or interim quality. Trademarks that are mentioned are done without written consent
and can in no way be considered an endorsement from the trademark holder.
Table of Contents Introduction Chapter 1: Getting Started with Arduino Why Should I Choose Arduino? Setting Up the Platform Chapter 2: The Functions of Arduino Variables and Data Types Chapter 3: Learning the Arduino Code Install the Drivers Working on Your First Sketch Chapter 4: How to Read the Analog Sensors Chapter 5: How to Store Data on Arduino Chapter 6: USB and Serial Communication on Arduino Information to get Started Chapter 7: Can Arduino Work Wirelessly? Chapter 8: Other Codes for Your Arduino Board Conclusion
Introduction Congratulations on choosing “Arduino: Master The Arduino Basics”, and thank you for doing so. The following chapters will discuss everything that you need to know to get started with the Arduino software. While there may be quite a few options available for you when trying to work on your very own robotics or engineering project, none of them are as versatile and as easy to use as the Arduino system. Simply pick out the board that you want to use, learn a few basic lines of code, and make sure the IDE is set up properly, and you are ready to go with all the great projects available. This guidebook is going to spend some time helping you to understand how the Arduino system works. We will start out with some basic information on Arduino such as the tools that you need to start before moving on to information about how the coding works on these boards, how to read the analog signals, how to store things on the board, and even how to send information wirelessly to save time and energy. Even if you are a beginner in the world of technology and programming, you will find that the Arduino system is easy to use and won’t give you a big headache to get it all done. This guidebook will provide you with all of the information that you need to ensure that you can get those projects done in no time. There are plenty of books on this subject on the market, thanks again for choosing this one! Every effort was made to ensure it is full of as much useful information as possible, please enjoy!
Chapter 1:
Getting Started with Arduino Before we get too far into some of the technical stuff that comes with Arduino, it is important that we take some time to get a good feel for what Arduino is all about. If you are someone who likes to work on robotics projects, you will find that working with an Arduino board can make things easier, whether you are a beginner or someone who has been working on these types of projects for a long time. When you first get started on a new project, there are a lot of things to consider, but the Arduino platform is one of the best to help you get started. When you hear about Arduino, you hear about a special microcontroller that can be programmed and software that will help you to control some of the robotics projects that you want to work with. In many cases, this is a great prototyping platform that helps you to work on those projects and give things a try with some basic code. Even though there is a lot of simplicity that comes with the Arduino platform, you will find that it has a pretty large fan base when it comes to using this software to help build up some electronic projects. There are a wide variety of projects that you can use with Arduino and the ATMega chip that comes with it. Some choose to use Arduino because it can work as a temporary addition that is easy to add into the project while they are finishing it up. Or you can choose to make it a more permanent part and embed it into the project when everything is done. This makes it easier to work with, and it can fit any of your needs. When you are starting out with the board, you will be able to program it with the Arduino software; this software is easy to work with even if you have never worked on programming or a robotics project before. If you have worked with Java or C++ in the past, you will notice that the coding language for Arduino is similar, so this can make things easier. The software is simple, but you will enjoy all of the power that can be found on this board, so even those with a bit more
experience will get some of the power that they want out of their projects. Another thing to notice about Arduino is that its platform is open sourced, which means that anyone who is interested, will be able to use this platform for free and those who are willing can make some adjustments to the code without any hassle. This is a good thing if you are just starting out with Arduino or with coding because you can access codes and projects from other people who have used this software in the past. Not only will you be able to look around and find that the codes you want to use have already been developed by someone else (which can save you a lot of time and hassle trying to figure out the coding on your own), beginners will like the fact that the Arduino community is vast and can offer them quite a few opportunities. This makes it easier for you to find forums and other locations where you can meet up with others, ask your questions, learn something new, and do other things that make your project easier to handle. Despite all of the power that you can find on the Arduino platform, you will find that it is pretty basic to use. There are only going to be two main parts that come with this platform, which can make things simpler in the long run. The two parts of the Arduino platform include: The Hardware: The first component of this platform is the hardware. This is basically the microcontroller, which is the circuit board. You can take the microcontroller and physically program it to do what your project needs. You will also find that there are a few of these microcontrollers or boards that you are able to pick from and each of them offers something new for you to enjoy. The Software: The second component of this platform is the software. This is like the environment that you will use on your board, and you can run that on your personal computer. The environment, which is also known as the IDE, will be useful in helping you to upload as well as to write the codes that should be
sent as instructions to the boards. When the programs are written on your board, it should react based on the matter that you ask. These two components are going to work together to help your project come to life. The only hardware that you really need to make this work is a good Arduino board and each project will need a different kind to help you out. The software is pretty cool because you will be able to write out the codes that you want to use and get some good results. Before you start writing out the codes that you want to send to the Arduino board, you have to make sure that you have the Arduino IDE in place. This IDE is free, thanks to the fact that the Arduino software is open source, which means that you can just go online and download it on your computer at no extra cost. Once it has been downloaded on your computer, you will be able to write out your own codes for each project or use the codes that are provided if you get the projects from another source, with the help of the Arduino programming language. The IDE for Arduino will work on most operating systems from your personal computer, so this should not be an issue. There is one thing that you should keep in mind if you are trying to download this Arduino IDE on a computer that uses the Windows 7 operating system or an earlier version of Windows. There will be a few additional steps that are needed compared to some of the other operating systems. This takes just a few seconds longer, but it can be frustrating when you try to get things done, and it isn’t working. You will be able to use the IDE on these older computers so don't feel like you need to update your whole system to make this work.
Why Should I Choose Arduino? One question that you may be asking about this software is why you should choose to go with the Arduino board instead of one of the other options that are available. There are quite a few programming languages and boards that you can use for your project, so picking the one that will make your project do amazing things can seem impossible. But Arduino is a bit different than the other boards on the market, and this can help make it the perfect choice. When you get your Arduino board, you will notice that there are quite a few projects that you can do on this platform. First, it is really easy to work with the coding. If you have worked with the C++ language in the past, you will be able to pick up on the coding that is with Arduino in no time at all. Then when you are done writing the code, it will travel from your IDE which is on the computer, and then end up on the Arduino board that you purchased for that project. The board can sometimes do the project all on its own, such as turning it into a kind of game, or you can add it to one of your own personal electronic projects and really have some fun. There are quite a few things that you will be able to do with your Arduino board, whether you want to try something new and have heard about these boards being able to help or you are just starting out, you will be able to work on some amazing projects with this board. The Arduino platform is really easy to learn so there isn’t a lot of technical knowledge that you are going to get stuck with as a beginner. It works well in a lot of electronic projects because it can make sounds, it can control a screen that is attached to it, it can do things with blinking lights, and so much more. We will discuss some of the projects later on, and you will be amazed at all of the cool things that you are able to do with this board. You will also enjoy being able to use the Arduino board for some of your own personal needs. Many people who like to work on robotics and programming
choose this kind of board because it offers a variety of ways to make some of their own projects. But this is not just something for experts; beginners often pick this board because it will help them to make some projects without having to learn a ton of coding. Sometimes, a beginner will have a great project he wants to work on or at least an idea of a project but may be worried that he won't be able to start it due to lack of the right programming knowledge. But Arduino is easy and simple enough for a beginner. Some of the other benefits of Arduino and why you should choose this platform compared to any of the others include: It can work on a variety of platforms: you will be able to download the IDE used for Arduino on pretty much any operating system that you want to use. This makes it great whether you are working on a Windows computer, a Mac, or the Linux operating system. Simple environment: unlike some of the other environments that you may have worked on in the past, the environment for Arduino is pretty simple to learn. It is similar to the C++ environment, but some people find that it is even easier to work with, making it perfect for the beginner. Open source: this is probably one of the biggest benefits of choosing the Arduino system. The board plans that you can use with this board are going to be published online and are open source. This is great because it encourages advanced programmers to make more plans for others to use and they can improve and enhance some of the plans that are already available. Beginners are going to enjoy this because it gives them the option to find some plans for their projects without all the hassle. Free: you may have to spend just a bit to purchase a new Arduino board for your project, but the IDE and the software that you need to make the project work will all be free. The code and the IDE will be free, so this saves a lot of time, hassle, and money when you first get started. The good
news is that the boards don’t cost a lot of money, so you will be able to put your project together without spending a ton. Large community: one thing that beginners will like is that there are many other people using the Arduino system for their own projects. This means that there are quite a few forums and other places where you can talk to people working on projects similar to yours. You can easily find plans to follow, people to ask questions, and even tutorials to help you out. This large community is there to help you get going on the right track in no time. As a beginner, you will discover that there are so many things you will love about using Arduino. It is so simple, it is easy to find the plans that you want, and you will be able to get the projects done without spending a lot of time and money in the process. While we have spent some time on all the great benefits that come with the Arduino board, it is important to realize that there are a few limitations that come with this board. For example, you won’t be able to find a lot of processing power so if your project is considered pretty intensive, you will need to find a different kind of platform to work with. This means that you won’t be able to work on projects that include recording, video, or audio, but you can attach a simple screen to the project for some of your needs. Some beginners get the Arduino board confused with a computer board, but there are few differences. You won’t be able to hook up some things to the board, such as a keyboard or a webcam, so you will find that there are a few limitations that come with your project. Sometimes the confusion comes because there are some similarities between the Arduino board and the Raspberry Pi, which is a product that looks the same but can take on some of these other capabilities. The Arduino board can enhance and help out with some of our own electronics and robotics projects, but you cannot use it as part of your computer
or turn it into your own personal computer.
Setting Up the Platform Now that we have an idea of what Arduino is all about and some of the cool things that you are able to do with this software, it is time to get started on setting up the platform. This platform is pretty popular to use, which means that for beginners, there will be something new to learn in order to work with it. This section is going to spend some time focusing on how to get the platform set up in order to execute some of the projects you like. Before you get started, ensure that you have access to a few things that will make it easier for you to work. For example, you will not able to start with the platform if you don’t have one of the Arduino boards to work with. So, let’s take a look at some of the items and steps that you need to get this all set up.
The Arduino Board The first thing we need in order to get this project started is the Arduino board. This part is pretty necessary if you want to work on any project since it is the part that will hold onto the code and tell the project how to behave. There are a few different options that you can pick from based on the type of project that you would like to complete. Many projects will help you out and tell you which board is recommended, but over time, you will be able to figure out the best one all on your own. Even though there are a variety of Arduino boards out there that you can choose from for your project, there are some basics that are found on each of the board. Some of the components that should be found on all the boards you work with which will help them function properly include: USB and a Barrel Jack: No matter what kind of board you purchase and work with, there have to be some means, either with the help of a USB or
a Barrel Jack, that you will be able to connect them to a power source. Some will have options that connect right into the computer and others can connect to the wall, but they need to be able to connect somehow for them to work. Most of the boards you see will have some sort of USB connection so that you can hook them up to the computer and easily transfer the codes when you are done. Pins: The next component that you should look for are the pins. These are the points where you are able to create the circuits that you want before connecting them up with wires. There will be a few types of pins that you can work with, and each of them has a specific job to do. Reset Button: Somewhere on the Arduino board that you pick, there should be a place where you are able to reset the board. This button is the one that will allow your pin to rest on the ground before restarting the code that you loaded onto the board by this point. It is a good button to work with because it is great for testing out the code to make sure that it works. It is important to remember when you push the reset button, this doesn’t mean that it will reset everything on the board, so you won’t be able to use this as a way to fix your board if something is wrong. Power Indicator: Another thing that should be on your board is the power indicator. This is simply a small light that you can find near the ON button. It is a power source of some kind and whenever you plug in your board, this light should show up for you. Voltage Regulator: This part of your Arduino board is going to be the part that will control the voltage that comes on the board at any given time. If you have a voltage that is above this limit, the board will simply turn it all away. Remember that most of these board won’t be able to take on a voltage that is higher than 20 volts, so keep the power source below this number. If you let it get too high, there will be some issues with destroying the board.
Each of these parts will be important to the project that you want to work on. You should pick out a board that has all of the right parts, plus some extras if that is what your project will call for. The good news is that most of the projects that you choose to work on as a beginner will tell you the type of board you need to work on, so this can help you gain some familiarity with the different types of boards before you go out and try to do it all on your own.
Hooking the software up After you have had some time to look at the boards that are available with this Arduino platform, it is time to work on your first project. But before you are able to get out there and start writing the amazing codes that will start your project, you have to install the IDE, or the software, so that the Arduino board will work properly. Basically, this IDE is going to be the environment that you will work on. You will open this up to write out any and all codes that your project needs. When you are done, this IDE will help you to send that code over to your Arduino board so that everything is connected and will work the proper way. If you don’t download the IDE for your project, you will never be able to write out your code or work on your project, and the microcontroller will just sit there without any life to it. The good news is that it is pretty easy to download the IDE for some of your projects. You simply need to visit the website www.arduino.cc where you will find a link to download the correct IDE. Remember that you are downloading a whole environment, so it does take some time for it to all finish and be on your computer. Once the IDE has been downloaded, you should notice a zip folder on your computer. Now you need to open up the zip file and save it to whatever location is easiest for you to remember later on your computer. The location doesn’t
matter as much as long as you are able to find it when you want to pull it up. From here, it is time to go into the zip file and look for a file that says Arduino.EXE. This is the file that you need to open and run in order to start the installation. Along the way, you will run into a few command prompts for this process. You can read through them to see what they say and then click next or agree to continue one. After the IDE has been installed and all the right components are in place, you are set. You can start on some of your own projects or look up a few that you think are good. The IDE is all ready for you to work with and you can easily write out your codes and send them right over to the Arduino board when you are done. And that is all that there is to the whole process. While you will be able to do some amazing projects with the help of the Arduino board and software, getting it all set up so that you can start is not a complicated procedure. By the time you finish the steps above, you will be ready to learn a bit of coding and get started on your very first project.
Chapter 2:
The Functions of Arduino Now that we have taken a look at some of the basics that come with the Arduino board and made sure that we were able to get the IDE set up, it is time to work with a bit of the programming. Without the right programming in place, it is hard to send over the commands that you want so that the board works properly for your project. This chapter will talk about a few of the different parts that are common, even in the most basic codes that you want to work with and then we will move on to writing your first code on these boards so you can get the hang of it.
Variables and Data Types So, the first part of our code that we will take a look at are the variables and the data types. When talking about a programming language, the variables are like a label for your Arduino board because they are the parts in charge of associating the right values with their names. Before using your variable inside of a program, or a sketch as they are called in Arduino, you have to stop for a bit and then declare that variable. When you make that declaration, then that is when you start working with the data type. Now, in programming, the data type is going to be the part that is in charge of telling the program what data types are going to be found inside of each variable type. Without a name or a specific data type present, the variables can't be declared in these sketches. There are quite a few types of data that we can work with in these sketches. But we are going to keep this pretty simple to help make it easier. Some of the most common data types that you will find inside of these sketches include: Integer: these are the integer numbers, and on this type of programming, they will be somewhere between 32768 and 32767. Long: these are like the integers, but they are going to include much larger numbers. Characters: these can be either numbers or letters that will fall in the code. They can be any letter that is in the alphabet, but the numbers will fall between -128 and 127. Boolean: with these data types, we are working with data that is either true or false or data that is either 0 or 1. These data types will look at the expressions that they are presented with and then try to figure out whether the answer is going to be false or true based on the information in the
code. Declaring your variables is not a process that is too difficult when you are working with the Arduino board. Let's take a look at an example of this. For this one, we will look at a variable that we will call ledpin and we will declare it. To start, we need to pick out a data type for this variable and give it a value of five. In order to declare this one, we would just use the following code: int ledPin = 5; And that is really all that you need to do in order to declare a variable in the Arduino board. Of course, there will be some times when it gets a bit more complicated, but it will still follow the same kind of idea no matter what you are working on. One thing that you should keep in mind though is that a semicolon needs to be added to the end of it so that it helps the IDE read through the whole thing properly. Other than that, you are good to go.
Operators The next part of your code that you need to understand is the operators. These operators are a great way to add some more power to the code because they are often used to help manipulate the variable. In some of the programming languages that you choose, there will be quite a few operators to pick from, but Arduino will focus on just the four main ones to keep it pretty simple. Some of the operators that you are able to work with in the Arduino coding language include: Boolean Operators: This is similar to what we discussed before with the data types. These operators will need to focus on data types that are either true or false or 0 or 1. The symbols that you would use for these operators would include (!) for or, the (&&) for and, and the (||) for not.
Logical Operators: If you are trying to work on a project that needs to do comparisons, you have to work with the logical operators. There are a few options to use such as the (==) symbol which means equal to, the (<=) for less than or equal to, and so on. Mathematical Operators: These are the symbols you are familiar with any time you head to a math class. They are used in your sketch any time you need to do a math equation of any sort in the code. You will be able to use the signs such as (+), (-), (*), (/, and (%). Assignment Operators: This one will usually just have one symbol, the equal (=) symbol because it is used to calculate what will be the final value of your data type. This final value is going to show up on the right-hand side of this equal sign. It can also show that the information that is on the right-hand side is equal to the information on the left side. You can also work with some operators that are in charge of increments and decrements. For example, if you use the symbol (++) after you name the variable, it means that you just want to add one to whatever the value of the variable is. The same can be true if you go the other way. If you use the (--), you are going to subtract one from the variable.
Expressions Next on the list is expressions. When we bring up expressions in the Arduino code, we are able to combine a few of the different data types that we listed above to make our expressions. When these different data types come together, you will be able to add a lot of control to the code that you are working on. One example of these expressions would be to create a mathematical expression. This could look as simple as something like a=4*2-6. The compiler, which is the part of your IDE that reads through the code and translates it, will see the equal
sign and will take a look at the left-hand side to see what the variable is before going through and computing the answer of the numbers on the right side. While we are here, we need to remember that when doing the mathematical equations, the compiler will use the MDAS rule to figure out what the answers are. This means that it will multiply everything first, do the division, the addition, and then finish with the subtraction. This is the standard in most mathematical equations so it shouldn't be anything new in this part. This means that the answer we would get from this equation would be a=2. You are able to write out expressions that aren't mathematical as well. For example, you can work with logical expressions, which will be the ones that use the Boolean and the logical operators. You will actually see these quite a bit when you start to write out your Arduino sketches. There are a few ways that you are able to do this, but let's look at a quick example. Let’s say that we have two pins that we are working with. Pin 1 is going to be HIGH and pin 2 is going to be HIGH. From here you will be able to create what is known as a conditional statement to make the board behave in the manner that you would like, but you would need the logical operator to help you get this finished. To write out your conditional expression with the information that is provided, you can use the following: (pin1 == HIGH || pin2 == HIGH). Inside of this code, you can see the (||) symbols which are logical operators. This one means that if the first or the second condition is true (it doesn't matter which one or if both are true), then the whole expression will be true. If you would like to have both of your pins be at the HIGH setting before anything happens, you would need to change up the conditional statement that you are using. It would now look something like this: (pin1 == HIGH && pin2 == HIGH). These three topics are just the beginning of what you are able to do with the code
we are writing for the Arduino board, but they will help you to write a lot of the different codes that you would like for your projects. You can use the different data types that are available to create expressions, manipulate the data and do so much more. Before we get into some of the codes and projects that we will talk about in this guidebook, open up your IDE and experiment with some of the topics in this chapter so you can become familiar with how the coding works.
Chapter 3:
Learning the Arduino Code Now it is time to work on learning how to write some of the code that is needed for your board and to test to make sure that the board is working properly. By this time the IDE should be set up, and you have had a bit of time to go through and try out a few of the different sketches that we talked about in the last chapter. But now that we have all of that down, it is time to work with using our board and making sure that it works properly. If you are still new to programming, you may be looking at the Arduino board and feel a bit worried about how you will proceed. There are a lot of parts that can come with the board, and it may be a bit confusing to get started. But if you have the IDE set up, you will be just fine, and your projects will come to life in no time. Starting out on your first project is not going to be that difficult. There are a few things that need to be set up before you get going. First, you need to make sure that you have your IDE set up and working. Also, ensure that your computer is able to recognize the Arduino board that you choose to use and then you have to write out the correct code. Once you have these components in place, it is time to start on a project. We need to take a moment to look at the coding a bit more because this is often the most complicated part that comes with using the Arduino system. For those who have been able to work with C++ in the past, you will find that the rules for Arduino are going to be pretty simple so this can help out. Don’t fret too much if you haven’t been able to learn C++ in the past. This language is pretty basic, and most of the projects you work on will use a similar approach, so you will catch up fast. Before we start working on this first project, make sure that the IDE is ready to go. You need it uploaded and turn on the computer so that it will work properly
and will recognize the codes that you want. This seems simple, but it is impossible to work on any of the projects that you want if the IDE isn’t even on your computer. At this point, you should have the hardware in place, and your Arduino IDE set up. We are going to take a moment to test out our program to ensure that it is working properly. This will be the first project that we work with and will test that the board is working and will give you a bit more experience with working in this coding language. Remember that there are a number of different boards that you can work with when creating a project with Arduino, but for this particular test project, we are going to work with the Arduino UNO or the R3 board. This is one of the most popular boards, so you will find that a lot of different projects will work with this type of board. It is possible to use another board if you would like to make this test project work, but you may need to make a few quick modifications to see it work. In addition to getting the UNO board, you will need the following items An LED: You will need to make sure that you have an LED light or that your board comes with one. This needs to work with the particular board that you pick out so that you can see if the board is actually working. A USB Cable: Next on the list is a USB cable. You will need to pick the A to B option because this makes it easier for you to hook up the board to your computer. If you are not able to find this kind of cord, it is also fine to just pick out any type that will hook the board and the computer together. Computer: Of course, you will need to have a computer to work with for this project. The computer doesn't have to be a brand new model, but one that is 20 or more years old and hasn't been updated in years, will probably not work optimally. You can pick from a Windows XP or higher operating system. Linux and Mac work well too.
Once all of these items are gathered together, and you are ready to work on this project, it is time to start testing out the board. This is a simple project, but it will help you to test out any of the boards that you want to work with and will ensure that you get the coding and the system down for when it is time to work on your own projects.
Plugging in the Board The first thing that we need to do is get the board plugged in and recognized by the computer. You can easily use the USB cord that was recommended earlier to help you plug this board into the computer, or another power supply will work in some cases. Some people will start by hooking it to a wall to give it some power, but this will not allow you to hook the board with your IDE which means any code you write will not transfer over, so hooking up with the USB cable is usually the best option. Once the coding is moved over to the board, you can choose whether to hook it up to the wall or to the computer. So, you will need to hook the USB cable up to the right port on the Arduino board and then also hook the other end to the computer. Now that the computer and the board are connected, take a look at your board and see where the ON light is located. If the board is working properly, this light will start blinking quickly. This is known as the default program for the ON light, and it is already placed on a chip inside the board. With this project, we are going to override the default program so that instead of getting an LED light that blinks rapidly, it is going to blink on and off with two seconds occurring between your blinks. It isn’t much, but it is a great way for you to get started. If you look at your board and notice that the ON light is not blinking at all right now, it is time to do some troubleshooting. The first thing to look for is whether
the USB cable has been plugged in properly to the machine. Sometimes it is an issue with using the wrong cord. Check to see if these are both right. In most cases, fixing one of these two issues will turn the ON light on, and it will begin to blink for you.
Install the Drivers Now that you have your Arduino board hooked up to the computer, you will need to take a few minutes to install your drivers so that the program you write actually works. For those using a Windows 7 computer or a Windows operating system that is older, there are a few extra steps that needs to be taken to ensure that the system recognizes the Arduino board. These steps will need to be completed any time that you use a brand new board with your computer. For those using a Windows 8 or higher operating system, Linux, or Mac OS, you will be able to skip over the following steps. Your system will already have the technology present to recognize the Arduino board without these steps. For those using the earlier versions of Windows operating systems, these steps will help you get your drivers onto a computer so that when you write out a code, they will go over to the board the right way. The steps that you need to take include: Make sure that the Arduino board is plugged into the computer correctly. You will notice that your operating system will start going through the process of driver installation, but it won’t be able to finish the process. You should get a message that the installation failed. After this installation process has failed, you should go to your Start Menu before clicking on the Control Panel. Look through your Control Panel until you find the tab for System and Security. Click on the System Tab. After this window has some time to load up, you can search for the Device Manager. Make sure to click on this. From here, there should be a tab for Ports. Look to see if there is a port that is open and which is called Arduino UNO (COMxx). Sometimes, the
Ports tab is not going to show up for the particular device that you are working on. If this happens to you, do a search for Other Devices and then search for Unknown Devices. Once you find your device, you can right click on it. There will be a few options that come up for you to choose from. You should pick Update Driver Software. Finally, it is time to select a file that is named Arduino.inf. This one should be under your Drivers folder for your Arduino Software download. If you are working with one of the older versions of your IDE, you will need to look for a file that is named Arduino UNO.inf. After clicking on these things, your operating system can go through and finish the rest of the installation process without needing anything else. Keep in mind that you will only need to go through these steps if you are working with an operating system from Windows that is older than Windows XP. For any of the newer versions of Windows or the Mac and Linux operating systems, you can skip over these steps because your computer will automatically notice the board. You just need to hook in the USB cable to the right spot and the computer will recognize the device, making it easier for you to start your work right away.
Working on Your First Sketch At this point, regardless of the kind of operating system you are using, you should have the Arduino board hooked up and recognized by your computer. It is now time to do a test drive of your board and try out a simple program for the first time. This program won't make much of a change on the board, we are just changing a blinking light, but it will help you to gain some familiarity with your board and the coding language that we will use when it is time to work on a few of the other projects. When writing one of your own sketches, you need to make sure that there are two void functions inside of the code. These void functions should not be allowed to return a value to you, and they can include the loop() and the setup() functions. With the setup() function, we are going to use it to tell the program that we want to just run through our sketch one time, right after the board has been powered up and is ready to start. On the other hand, we also need the loop() function. This is the one that will tell the board that you want the sketch to continue in a loop until you unplug your board from a computer. Since we are working on a blinking light, these two are going to tell the board to start blinking the light right when you turn on the Arduino board and that you want to keep the blinking going until you unplug the board later on. During our setup() part, we need to make sure that we take care of any and all initialization steps so that when the loop() part comes into play, the code will run properly and keep on going over and over again on the board. There is some basic coding that we are able to use to make this all happen and it includes the following: void setup(){
} void loop(){ } This is the basic syntax that you will use in most codes, and as you can see, it has both of the void functions that you need to make the code work properly. But if you went through and typed this information into your IDE, it wouldn’t know what you wanted to happen because there isn’t any code inside of it. You will need to put in a bit more to the code to make sure that it will tell the board the right stuff to do. Despite this, it is still a good syntax that you can start with. Now that we have the basic syntax that we need to write out a code, it is time to write out our code. Some of the other steps that you need to work on to make this code work is: Make sure that the Arduino board you are using is still hooked up to the computer and that your application for Arduino is launched. Now you can open up the sketch that is for the Blink examples. If you are searching for this, you just need to click on File first, then Examples, and then 1_Basics, and Blink. From here, you are able to pick out the type of board that you will be using on this particular project. To pick out the board you are using, you can click on Tools and then Board, before clicking on the board of your choice. Now it is time to choose whether you are using the serial port or the COM port. You can look to see which one the Arduino board is attached to. You can click on Tools, Port, and finish with COMxx. Sometimes it is hard to figure out which type of serial device you are using on the board, especially if you are a beginner. You can just get into the last part and
take a look to see which ports are available and which one matches up with yours. Sometimes you may need to unplug your board for a second and see which of the ports disappears to help find which one is right for you.
Getting the Light to Work Now we are moving to the final step. If you had to go through and unplug your board in the other step, make sure that it is properly plugged back in so that this works. Make sure that the Blink sketch is still open to use. From here, there should be an Upload button that you are able to press. At this point, you need to wait just a bit before looking to see whether the LED lights near the R and the TX are flashing while your program uploads to the board. If this upload has been successful, it is time to check the computer. The status bar that is found with the Blink Sketch will let you know that the program is Done Uploading if the whole thing was successful. After the uploading is all done, you can look at your Arduino board and check how the LED light for your ON button is working. It should have an orange color and it should start blinking in a slow and steady manner rather than at the rapid pace that it did when we first started. If your light is blinking with about two seconds in between each one, then you were successful, and the program is done. As you can see, working with the Arduino board is not something that has to be over complicated. As long as you have the right steps in place and you get the device all set up in the proper way, you are set to go. And now that you have finished this chapter, you have completed your very first project!
Chapter 4:
How to Read the Analog Sensors The Arduino board is a little bit different from some of the other projects that you have worked on. Instead of being able to look at a computer screen to get the information that you want like with a lot of traditional programming, you are sending things over to a board and getting it to behave. This is how things have to work if you want to get the programming over to a two or another electronic project. But since we are working with the board, there will be a few different things that we have to learn how to do to make it happen. In this chapter, we are going to take a look at some of the analog features that come with the Arduino board. We will look at how to read the input of the analog when it is on pin0, how to convert the values from your analog read() and change it over to voltage, and then get the serial monitor to print off in our IDE. First, you have to make sure that you have the right hardware in place to make this project work. This one will be pretty simple. You need to make sure that you have an Arduino board set up and ready to go. You will also need to have a 10k ohm potentiometer as well. The second thing that we need to work on is getting all the wires hooked up to the right place. We need to take the three wires that come from our potentiometer and get them hooked up to the board. The first of the wires will go to the ground, but it should start with one of the outer pins on your potentiometer. Then you can take the second wire and connect it to the 5 volts on the Arduino board and then to the other outer pin on your potentiometer. Then the third one will start on the middle pin of your potentiometer, and it will be placed in the analog input 2. Now that all of the wires are in place, it is time to turn the shaft of the potentiometer. When you do this, you will change the amount of resistance that is coming through on either side of the wiper, or the part that is connected to your center pin. This will basically change how much voltage is on the center
pin. When you change the voltage so that the resistance between the side that is connected to the 5 volts and the center gets closer to zero, the voltage at the center is going to get close to five volts. When the resistances are reversed, the voltage for your center pin will change to 0, or to the ground. This input that you are reading is known as the analog voltage. When you work on the Arduino board, you will notice that there is a circuit found inside of the microcontroller that is known as the analog-to-digital converter. We are going to call it the ADC. This is going to be in charge of reading the changing voltage and then will convert it to a number that is somewhere between 0 and 1023. If you turn your shaft to one side all the way, there will be 0 volts that will reach the pin, so the input value that goes there is going to be 0. But then if you turn the shaft to the other directions, this means that the pin is going to start receiving 5 volts, so your input value is going to be 1023. Of course, there will be times when the voltage will be somewhere in between 0 and 5, so the analogRead() is going to give you a number that falls between the 0 and 1023 based on how much voltage has been applied to the pin. It is now time to look at the code that we will use to make all of this happen. In the program that we will write below, the first thing that we do will be to use the setup function to begin our serial communication. We will make sure that we have it set up to be 9600 bits of data each second and this will occur between the computer and the board. Once that is done, it is time to work on the main loop for this code. Inside that main loop, we need to work on establishing a variable that will store the resistance value (remember that this is in between 0 and 1023), that is coming from the potentiometer. You can also go through and change the values from 0 to 1023 to a range that will correspond with the voltage your pins are reading. If you do this, you must make sure to create another variable, which is known as a float, and then add in a bit of math. To scale these numbers between 0 and 5, you
need to divide 5 by 1023 and then multiply that by our sensorValue. And finally, we need to make sure that we tell the system that we want to print out the information so that it shows up in our serial window in the end. This is pretty simple to do. Just add the Serial.println() to the last line of the code, and you are all set to go. Once the code has all be completed, you should be able to open up the IDE and then open your Serial Monitor. If you are having trouble finding the Serial Monitor, just click on the icon that is to the right of your top green bar. You can also click on Control, Shift, and M to make this happen. Once the Serial Monitor is all open, you should see a nice steady stream of numbers that range somewhere between 0 and 5. As you turn your little switch from one direction to another, the values are going to change, and you will see that the voltage that corresponds to that change will come up on pin A0. So, when you are ready to write out the code that you would like to use for this serial reading, you will use the following: // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read: Serial.println(voltage); And that is all that you need to do in order to set up your analog pins and get them to work for you. There are other things that you can do with these analog pins, but these basics will help you to learn how they work and how to get it set up so that the IDE is able to read them properly.
Chapter 5:
How to Store Data on Arduino There may be some times when you would like to get the Arduino to save and store your data. The project you have may require the ability to recognize voice patterns later on or some names and passwords depending on the type of project that you want to work with. While there are a few options available to help you store the data, the sketches that seem to be the most useful will be the VemierThermistorStore or the VemierAnalogStore. Both of these are going to work pretty much the same, and they will take your readings from the analog sensor before storing this information inside the EEPROM memory of your Arduino board. One of the nice things about using the EEPROM memory is that it is considered non-volatile. This means that even when you take the power away from your Arduino board, the data will continue to be saved on it. The limit of points that you can use with this option though will be 511. Now, you have to choose which option you would like to work with. Unless you want to keep track of the temperatures with your board, the VemierThermistorStore will probably not be the option that you want to go with. This means that we will focus our energy on using the VemierAnalogStore. This option will be able to handle the analog sensor that has a linear calibration. As it is written, it will be able to collect data from the dual-range force sensor each second. You will find that with some experience, it can be easier to modify this sketch for a different sensor if you would like or even for a different rate of collection. There are going to be a few things that you will need in order to make these sketches work. These things include: To start collecting the data to store, which will also wipe out the data that you have collected and stored in the past, you will just need to press and
hold the push button for about two seconds. Your LED light is going to blink for every time that your data point is taken. If your Arduino is connected to your computer, you can watch the Serial Monitor to see what data has been collected. If you get started with this collection of data and decide that you would like to stop sometime before all the data points are collected, you would just press the same button again. You are successful when the LED flashes three more times quickly. The good news is that you will be able to take the data away from your computer and then bring it back to see again with the help of the Serial Monitor, as long as you make sure the Arduino has power. You can also choose where to place this data, such as inside the Logger Pro file so that you can look at them later. Once your data collection is done, it is time to send your collected and stored data that is inside of the EEPROM memory over to your Serial Monitor. The process for doing this is pretty simple and will just need the following steps: Make sure that your Arduino is connected to your computer with the help of a USB cable. If your IDE is not already up and running, it is time to turn it on and get it ready. Now open up the Serial Monitor for Arduino. Press the button that is on your Arduino but make sure that you do not hold it down for more than two seconds. If you hold it for longer than this time, you will basically be starting the collection of data again, and it will wipe out all the information. All the data that you collected earlier should start to appear in the Serial Monitor after you are done with this step.
If you would like to be able to change the rate that the data is being collected, you will just need to change the variable that you are using under TimeBetweenReadings. Note that you are only able to store up to 511 points in your EEPROM memory while using this sketch. This means that it may be a good idea to increase the amount of time that happens in between your readings. This makes it easier to collect the data over a longer period of time rather than doing it as much as possible. Now that we have taken a look at some of the steps that you need to take in order to start storing and collecting the data on your board, it is time to bring out the code that will help you to get this done. The code is a bit lengthy, but it is going to tell the board exactly what you want to be done. You just need to type it into your IDE, and the board will respond. The code that you need to use includes: int buttonPin= 12; // analog input pin to use as a digital input int ledPin1= 13; // digital output pin for LED 1 indicator int debounce= 20; // ms debounce period to prevent flickering when pressing or releasing the button int holdTime= 2000; // ms hold period: how long to wait for press+hold event #include int base = 0; // the base address in EEPROM for data storage // note first two bytes store the number of points collected // Button variables int buttonVal = 0; // value read from button int buttonLast = 1; // buffered value of the button's previous state long btnDnTime; // time the button was pressed down long btnUpTime; // time the button was released long ReadingTime; //time at which a reading was taken
long ElapsedTime; //time since last reading boolean ignoreUp = false; // whether to ignore the button release because the click+hold was triggered boolean ledVal1 = false; // state of LED 1 int AnalogDataPin = A0; // this may be changed depending on circuit wiring int Count; float Voltage; float SensorReading; unsigned long Time; long unsigned int TimeBetweenReadings = 1000; //in ms int NumberOfPoints= 511; String SensorName = "Dual-Range Force Sensor, 10 N"; String Measurement = "Force"; String ShortMeasurement = "F"; // this is a shortened version of the label String Units = "Newtons"; float Intercept = 12.25; float Slope = -4.9; void setup() { // Set button input pin pinMode(buttonPin, INPUT); digitalWrite(buttonPin, HIGH); pinMode(AnalogDataPin, INPUT); pinMode(ledPin1, OUTPUT);// Set LED output pin Serial.begin(9600);
Serial.println("VernierAnalogStore sketch"); Serial.println("Press and hold to collect new data"); Serial.println("Press button briefly to read data stored in EEPROM"); Serial.println("and send it to the Serial Monitor"); Serial.println(" "); } void loop() { digitalWrite(ledPin1, false); // Read the state of the button buttonVal = digitalRead(buttonPin);// button down is low // Test for button pressed and store the down time if (buttonVal == LOW && buttonLast == HIGH && (millis() - btnUpTime) > long(debounce)) { //button pressed btnDnTime = millis();// note time of press } // Test for button release and store the up time if (buttonVal == HIGH && buttonLast == LOW && (millis() - btnDnTime) > long(debounce)) { if (ignoreUp == false) ReadEEPROMData();// read data from EEPROM and send to Serial Monitor else ignoreUp = false; btnUpTime = millis();// note time of button release
} // Test for button held down for longer than the hold time if (buttonVal == LOW && (millis() - btnDnTime) > long(holdTime)) { CollectData(); //collect new data ignoreUp = true; btnDnTime = millis(); // get new button down time } buttonLast = buttonVal; }
Chapter 6:
USB and Serial Communication on Arduino Throughout this guidebook, we have spent some time talking about a few of the projects that you can execute with the help of your Arduino board. A few of these have required you to use a USB cord to help hook up to a computer so that you can download whatever code you want to use. Now we are going to take this a bit further and work on serial communication and how we can use this to figure out which sensors are working, whether our projects will make the right decisions, to change our variable values, and to control other movements.
Information to get Started Before we are able to get started with this kind of communication, we need to have a good idea of what serial communication is all about. This type of communication is going to work on a series of 1s and 0s or a binary system. The Arduino board will be able to send these bits (which are the 1s and the 0s) serially, one by one. To keep things simple, the 1s are going to be the HIGHs, and the 0s are going to be LOWS, and then these bits will come together to form some bytes. When you see a byte, it means that you have a sequence of 8 bits. Each bit that you work with will represent a number that you need to add. The first bit, or the one that is on the far right, will represent one place, kind of like what you are used to working with in the decimal system. 1 is going to equal 1 and 0 will equal 0. Then when you move to the value of the net bit, you would multiply it by two, so 10 is going to equal 2, 11 will equal 3 and 01 will equal 1 and so on. These bits can go all the way up to 255.
Serial output code Now it is time to work on the code that you want to use in order to help with the serial output. This code is pretty simple, and you will just need to type in the following to make this happen: void setup (){ Serial.begin(9600) } void loop(){ Serial.print(“The analog value is: “);
Serial.println(analogRead(A 0)); delay(100); } As you can see with this one, there is the setup() and the loop() function just like we did with the earlier examples that we showed. In addition, the serial print is going to be a function that is in charge of printing whatever message you specify in your serial monitor. For this specific code, we have decided to print the analog value for the point that is inside of Analog Pin 0. Then we moved on to the void setup. This is where we will tell the serial monitor when it is supposed to start. For this project, it should start up when we reach the baud rate of 9600. During the void loop, there is the function for the Serial println as well. IN here, we are going to print out the value that we find in the A0 part of the Analog Read.
How to Use it So far, we have taken the time to look at a code for the serial communication and to explore what this type of communication is all about, but what is it all about? Why would we want to use this type of communication and how can be it used on the Arduino board? Over the years, serial communication has been used in many ways to help finish out the projects that you would like to work on. In this project, we are going to turn on and off an LED light. This will be similar to what we did before, but we will use the serial numbers rather than the other method that we used before. First, you will need to take the LED and place it with the pin-13 and the ground. Then you can connect the USB cable that you want to use. We can then move on to create a new integer that we will use to store the incoming bytes that are sent over. You can pick the name that you want to call
this integer, but we are going to call it “inByte” for this example. Now we will go back to the void setup, and make sure that we set the pin13 as the output. We will keep the Serial.begin the same since we want to get it to work with 9600bits per second. Now it is time to move to the void loop. In this, we first need to know which byte is around that it can read. So we will use the Serial(available). This function will let you know how many bytes are there for you to read through. So, we can choose to write out something like “if(Serial.avialable() > 0)”, we know that there will be one or more byte that will show up that can be read. Inside of this if statement, we have to read the byte and then make sure that it is stored later for use. We can do this by writing out Serial.read(), which will tell the program to read your byte and then save it over to the inByte. To finalize this line, it is going to say inByte – Serial.read(); While you are still inside your main if statement, we can add in some other if statements if we like. If you want the program to write or read a letter to your variable, you will place that particular letter in some single quotation marks. For this example, we want to let the LED light turn on when we send over an ‘a’ to our boards. This means that the statement we will write to make this happen would include “if(inByte == ‘a’). Next, we will move on to the Serial.printlin(). This is important because it is going to tell Arduino that it should notify us inside of the Serial monitor that the ‘a' has shown up and that our LED light has started. The if statement that we want to work with will be like the following: if(inByte == ‘a’) { // byte is ‘a’ digitalWrite(13, HIGH); Serial.println(“LED – ON”); }
In this project, we need to ensure that the LED will turn off if we put in any of the other letters outside of the ‘a’ that we specified before, so it is important that we add in an else statement. When this happens, the LED light is going to turn itself off.
Putting it all Together Up to this point, we have spent some time talking about the code that is needed to turn the light on and off based on the Serial communication, or the binary code. Now let’s put it all together. This will tell the program that you want to turn the light on when the ‘a’ is put in, and then when any other letter is added to the mix, the LED will be turned off. The code you need to make this happen includes: int inByte; // Stores incoming command void setup() { Serial.begin(9600) pinMode(13, OUTPUT); // Led pin Serial.println(“Ready”); //Ready to receive commands } void loop() { if(Serial.available() > 0) { // A byte is ready to receive inByte = Serial.read(); if(inByte == ‘a’) { // bye is ‘a’
digitalWrite(13, HIGH); Serial.println(“LED – On”) } Else { //byte isn’t ‘a’ digitalWrite(13, LOW); Serial.printlin(“LED – off”); } } } And that is all that you need to do in order to get the Arduino board to work properly and use an LED light with the help of the Serial communication.
Chapter 7:
Can Arduino Work Wirelessly? So far in this guidebook, we have spent some time looking at the Arduino board and how you can send over various codes, but the board has to be connected to the computer to make this work. A USB cable is usually enough to make this happen, but there may be times when you wish you were able to send over information wirelessly between your IDE on the computer and the Arduino board that you are using. The good news is that sending code wirelessly is something that you can do. You can use what is known as the Arduino Wireless Programmer in order to upload some programs from your computer over to the Arduino board with the help of Bluetooth. Before we can work with the wireless capabilities, we need to take the time to update the program inside of our boards. There are some times when we will need to open up the box or the case to do this and times when we are able to just update the program. Any time you want to do this kind of wireless programming without having to use a USB cable, you will find that the Arduino Wireless Programmer is going to be one of the best choices to use. When picking out this program, you should be a bit careful. There are some projects that will not be compatible with this program, and you will still need to plug the board into the computer. For example, if you are working on a project that will need to use D1 or D0 or the hardware RX, TX or UART, you won't be able to use these wireless capabilities. This is because this programmer needs to be able to occupy two of your pins permanently to work, and this can ruin the project in some cases. There are also only a few boards that you can use with this programmer. The Arduino Deumilanove and the Arduino UNO will work with this program. There are some different configurations that will sometimes work with the other
models, but they will only support the mainboard that you are using. So now it is time to work on uploading this wireless program to your board without having to bring on the USB cable. This step can be a bit hard for a beginner, but once you are done, it will make it so much easier for you to work on some of your projects without having to hook it up to the computer for each project. So to start, we need to make sure that we have our Arduino IDE set up. Make sure that when picking out an IDE to use, you should not use the Arduino 00xx version. While this is downloading, you also need to download the rxlxserial.dll file, and this can be used as a replacement for the one that comes with your IDE folder. While you are on your computer, it is time to open up the Bluetooth capabilities, wherever those are located on your computer. You can add a device. After finding the Bluetooth device that you would like to work on, click on "Enter the device's pairing code." You can use the default code "1234" because it is easy to work with. Now you can open up the Bluetooth device that you are working on and choose it. Click the right button on your mouse so that you can select the option for properties. Now that we have added the board we are using for this project, the next step is to actually upload the program that we want to place on the Arduino board. Remember that for these steps, we are going to upload our code to the board without using a USB cord of any type. To get started with this, we need to make sure that our IDE is open. We can then select on Tools and then Board. Then there are a few options we can pick from. We will either pick the Arduino UNO or the Arduino Duemilanove w/Atmega328 depending on the option that we are using for this project. After we have selected the board that we are working with, it is time to click on
Tools again and Serial Port before clicking on COMX. This last part is going to be the specific serial port that will be used for the Bluetooth so clicking on this one is important. For this to work, the program you intend to upload needs to be on the Arduino IDE already. If you haven’t done it, you should go through and write out the code you intend using so that the board has the right commands that it needs to get the work done. Once the program is done and saved, ensure that it is open, or open it if you did the coding earlier. Press the Upload button so that it can be sent wirelessly over to the board you are using. And that is all there is to this project. There will be times when your projects will not like working with the wireless capabilities since this can take up some valuable space on your device and if you need to use all of the pins to make this happen your project will not work. But there are many cases when working wirelessly can save some hassle, especially if you have lost your USB cable and it is hard to always be stuck on a computer!
Chapter 8:
Other Codes for Your Arduino Board We have spent some time talking about the technical things that you can do with the help of the Arduino board. By this time, you should be familiar with some of the coding that comes with this board and how to do a few little projects to store information that you want and even to change how the LED lights work. But most people do not pick to work with an Arduino board because of all the technical stuff. They choose to work on it because they want to learn how to do some neat projects. Now that you have the basics and the technical stuff down, it is time to learn a few projects that can add some fun to working with this technology.
Heating Blanket The first project we are going to take a look at is a heating blanket. These can feel nice and warm when you are dealing with a cold winters’ day, but they are expensive to purchase on your own. The good news is that if you purchase a few parts for the Arduino board and the material that you want to use, you can get this blanket up and running in no time. This one will also need a code to help it get started so make sure that you have a good USB cord to help you get it all done. Some of the materials that you need to make your very own heating blanket include: Red hook up wire LilyPad Arduino board A wall adapter for power supply (5V DC 1A) N-Channel MOSFET 60V 30A 2 5X15 Heating pads Switch
Conductive thread LIlyPad LED light Black hook up water Once you have had a chance to collect all the materials that you need, it is time to get started. So the first step is to sew up the hand warmer blankets that you picked out. You can design this to look any way that you would like so get creative and have some fun. Once that creativity is done, you will need to use your conducting thread to sew onto your board before connecting this to the positive side, which will be where the blue LED lights will be located. You will also need to take some time to sew together the negative parts if you want this to work. Now you can grab your hook up wire, which will be the red wire that you have, and make sure to connect it to the positive contact of the board, making sure that it is on the side that has the positive side of your switch. It is good to use a parallel connection so that it will hook up to the positive part of your pad and also save you some hassle. When you are done getting the positive side all hooked up, the next step is to get the negative part ready. You can bring out the black hook up wire to help connect up these negative parts of the board, so they are hooked up to the power source as well. Continue on so that these parts are all connected to the negative part of the switch. From here, you can work on a parallel connection that will go all the way to the S leg of your MOSFET. When that is done, create another one that will go to the 10k resistor, going parallel as well. Now you need to take your 11th pin from your Arduino board and hook it up, so it connects with the G leg of your MOSFET. There should be a branch when you are done that ends up going parallel to the other end of the resistor. And finally, you will connect the D leg of
the MOSFET to the negative parts that are on the heating blanket. At this point, you will need to turn to your computer and work for a bit inside of the IDE. This will allow you to create the code that is needed for this project. The code that will make the board work and create a great heating blanket for you will include: language:C /* Hardware Connections: -led1 = D9; -led2 = D10; -led3 = D11; -button = D2; -Mofset = D3; */ int btnPin = 2; boolean btnPressed = false; int fetPin = 3; int led1 = 9; int led2 = 10; int led3 = 11; int mode; void setup(){ // initialize the digital pin as an output. pinMode(btnPin, INPUT); pinMode(fetPin, OUTPUT);
pnMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); } // the loop routine runs over and over again forever: void loop(){ // increment mode on depress, unless mode = 3, then reset to 0 if (btnPressed && digitalRead(btnPin) == LOW) mode = mode == 3 ? 0 : mode + 1: // Assign button state btnPressed = digitalRead(btnPin): switch (mode) { case 0: analogWrite(fetPin, 0); // off digitalWrite(led1, LOW) digitalWrite(led2, LOW) digitalWrite(led3, LOW) break; case 1: analogWrite(fetPin, 85); // 33% duty cycle digitalWrite(led1, HIGH); digitalWrite(led2, LOW); digitalWrite(led3, LOW); break; case 2:
analogWrite(fetPin, 170); // 66% duty cycle digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, LOW); break: case 3: analogWrite(fetPin, 255); // 100% duty cycle digitalWrite(led1, HIGH); digitalWrite(led2, HIGH): digitalWrite(led3, HIGH); break; } } Yes, this code may look a little long when getting started, but it does give all of the directions that are needed to get that heating blanket up and started. It will tell your blanket how hot it can get, with a few different settings placed in. The code will also instruct the blanket on how it should turn on and off, so you are able to get it to work for you. This provides you with a lot of different options for the blanket when you are done, and you are sure to stay nice and comfy during winter.
LED Light up Strip The next project that we are going to work on is creating our own light up the strip. This will require the help of something known as an e-textile which can actually make it a bit easier to work on the project. To get this one done, we are going to create an LED light up with the help of LilyPad. The supplies that you
can use to get this project done include: Fabric Embroidery hoop Needle threader Coin cell battery Conduction thread bobbin A LilyPad coin cell battery holder Scissors Rainbow LED strip Needles Once you have had a chance to collect these supplies, it is time to get started. Take the needle and get it all set up with the conductive thread that we are using. You may find that placing the fabric in the embroidery hoop can help because this keeps it all in place while you are doing the work. At this point, we need to work on making a positive trace. What this means is that we have to make a mark that goes from our source of power over to the positive part of our LED strip. You can start on this right beside the battery pack. You will be creating a place for the battery pack (but don't put it in there yet) near where the LED lights should be and make sure both of these are near each other. These will be helpful because you will be able to use them as the negative and the positive pins in your battery pack. Now, we need to ensure that we place the battery pack in the correct space before starting with the sewing process. You can first start with trapping the edge of your board into the fabric. You can do this by wrapping it up in the thread, about four times will be fine on each of your positive pins (there will be the first one that we talked about as well as a second one near the top of the Arduino
board). When these pins are being sewn into place, you need to make sure that you keep the stitches pretty small rather than just doing one long stitch. This helps to ensure that the pack is going to stay in its place and you won't have things moving around and shorting out the circuits. Take some time to finish the stitching all the way through the positive side of your LED strip. You will have to check a few times to make sure that you are on the right pole. If you end up sewing on the wrong pole at any time, you will experience some issues because not all the LED lights will show up. After you are done getting the positive side all sewn up, it is time to start working on the other side. To do this, you need to return from the current side of the LED to the negative part of your pack. You will basically be doing the same steps that we talked about before, but they will be done on the negative side instead to help get the whole package ready to work with the LED lights. Once you reach the end of this, you should take a few seconds to look at the project to see if there is any thread dangling anywhere on the project. If there is, you need to snip it off to avoid problems. You can also double check to see if your negative and positive traces are touching any other parts. If they are, you need to redo some of the stitches because it could lead to several issues when it is time to get the light working again. If you have checked over the whole project and you notice that it all looks good and your sides are placed together properly, it is time to take your cell battery and place it in the pack. Once the battery is inside the pack, the LED lights should start showing up right away. And at this point, you are done with your project!
Conclusion Thanks for making it through to the end of this book, let’s hope it was informative and able to provide you with all of the tools you need to achieve your goals whatever they may be. The next step is to get out there and start finding the Arduino board that you will like to work with. For the most part, we focused on the Arduino UNO board because this is the one that is most commonly used, but there are many great options that you can choose from, and the one that you pick will often depend on the type of project that you are working with. This guidebook has taken some time to look over the various components of the Arduino software and how you are able to use it. Arduino is mostly used to help with some engineering and robotics projects but the board is so simple to use, and the code matches C++, so even beginners are able to get things working easily for them. Inside this guidebook, we explored some of the different topics that we need to know in order to use the Arduino software on any project. From learning what Arduino is all about to looking at the parts of the code and how to work on your own project and even looking at how to work on some of your codes to send them over wirelessly, you will be able to go from beginner to expert with all of your projects in no time. If you have some great ideas to help you with a good engineering project, but you just aren't sure how to get it started, it is time to bring out the Arduino board to help you out. This guidebook will provide you with all the information that you need to get started.