Книга: Arduino: Master The Arduino Basics
Назад: Install the Drivers
Дальше: Chapter 4: How to Read the Analog Sensors

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:


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!

Назад: Install the Drivers
Дальше: Chapter 4: How to Read the Analog Sensors