Blink the LED

We’ll start programming the Arduino!

In this chapter, we are going to start to see how the Arduino controls electronics with the programs that we write. First we’ll set up the software to program the Arduino on a computer, then we’ll connect your Arduino to a breadboard. We’ll build an SOS signal light with an LED. We’ll learn some basic rules about writing code and get familiar with writing code in the Arduino environment. For this chapter, you need to know how to hook up your Arduino to a computer and how to build a basic circuit on a breadboard.

Arduino, circuits and code: bringing everything together

This is our first opportunity to combine building circuits with basic programming. When we add programming and the Arduino to our circuit, we have more control over the circuit; our LED can flash on and off in different patterns. You will learn how to program the Arduino and connect it to a breadboard to build a complex circuit in which the timing of the components in the circuit is controlled by the series of instructions loaded onto the Arduino. To learn this, we will create an SOS signal light with an LED which flashes on and off according to timing controlled by the Arduino.

From this point on, all of our projects will include the three parts shown here; the code, the Arduino, and a circuit on a breadboard. We will discuss the combination of all three elements and how they interact with each other in this chapter.

We looked at the Arduino and some of it’s features in chapter one. In chapter two, you learned a bit about small scale electronics and circuits. We will walk you through downloading and using the Arduino IDE in this chapter, which will allow us to upload code, changing the behavior of the Arduino.

Just as we will show you the necessary circuits throughout the book, we will also include all the code examples you will need in order to run your projects.

In order to code, we will need to have software from Arduino installed on our computer. We will download and install the Arduino IDE or integrated development environment. What’s an IDE? Let’s take a look.

What’s an IDE? Looking at the integrated development environment.

An IDE, or integrated development environment, is a software application that allows you to write code and test that code out in the programming language the IDE supports.

If you have experience programming, you may have used another IDE to write, test, debug, and turn your code into something the computer understands. If you haven’t, the Arduino IDE is a good place to start, as it is relatively simple and easy to understand.

The Arduino team has designed an IDE for use with their devices that has all the features you need. It has a built-in code editor, which is a program used to write the code files that you create when programming. You can test your code in the IDE and solve any emergent problems with the help of a message area that shows errors in your code and a console that provides more detail about the nature of these errors. It has buttons so you can check your code, save it, create a new code window, upload it to your Arduino and more. (What do we mean by upload? Uploading is transferring the instructions you write in the text editor to the “brains’ of the Arduino so that your code controls the Arduino.)

ch3-codeflowchart-01

The IDE is freely available on the Arduino website. (http://www.arduino.cc/en/Main/Software) It is possible to program an Arduino using another text editor or IDE, but we will stick with using the Arduino IDE in this book.

What’s in the Arduino IDE?

  • A code editor window where you write your code
  • A message area that gives information about your code
  • An error console that gives detailed information, helps in debugging
  • Menus that allow you to set properties for your Uno and load code examples and other functions
  • Buttons to check code, upload it to Arduino, save code, create a new code window and more

What is code?

In basic terms code is used to give instructions to the computer. We use code to speak in the language the computer understands (in this case Arduino) in order to accomplish a set of tasks or set up a series of programmed responses. Computers have a hard time understanding what you mean, imply, or suggest. They are not capable of the finer points of language, so we use code to simplify the instructions to a set of commands at a fundamental level.

We’ve seen what’s in an IDE, and a basic description of code. Let’s take a quick look at the Arduino IDE.

Arduino IDE: first glance

Here’s your first look at the Arduino IDE. Don’t worry about memorizing any of the parts or what they do, this is just a first glance. We will cover all of the parts in detail later in this chapter and in the rest of the book.

As you can see, there are menus at the top of the window. There are also buttons for frequently used functions such as save, an area where you can write code, and some message areas.

Now that we have an idea about what’s in an IDE (and, specifically, in the Arduino IDE), let’s download it and install it on our computers.

Downloading and installing the softwareUsing the multimeter

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>