Last time I left you at the setting your Arduino for Mac or Windows and download a simple test app that flashes a built-in LED. Today I am going to explain the code you have uploaded, the structure of the Arduino software and a bit more about the electronic bits on the board itself.
This article is part of an introduction to the Arduino series. Other articles in this series:
- What is an Arduino and what can you do with it What is an Arduino and what can you do with it ?
- What is an Arduino starter kit and what does it contain?
- More cool components to buy with your starter kit.
- Getting Started with the Arduino Starter Kit — Installing Drivers and Configuring the Board and Port
Hardware
Let’s take a closer look at what the Arduino Uno has in terms of bits on the board.
Here is an enlarged diagram for reference:
- Along the top are 14 digital inputs/outputs (numbered 0-13). These are the most versatile pins on your Arduino that can work as both input and output and will be the backbone of your projects. Digital means that the signal that these pins can write or read will be turned on or off.
- 6 of these digital pins marked with a tilde ~ are capable of doing what is called pulse-width modulation. I’m not an electrical engineer, so I won’t be embarrassed to explain the science behind this, but for you and me, this means that we can provide a range of output levels — like dimming an LED, or driving a motor at different speeds. ,
- Pin 13 is different in that it has a built-in LED. This is for convenience and testing purposes only. You can use this built-in LED, as you did in the Blink application example, by simply outputting to pin 13 — or it can be used as a standard input/output pin.
- At the bottom right are 6 analog input pins. They will read the values of analog sensors such as a light meter or variable resistors.
- On the bottom left next to the analog input pins are the power pins. The only thing you really need to worry about is the ground (GND) lines, the 3.3V and 5V supply lines.
- Finally, the only switch found on the Arduino is the reset switch. This will restart any program in its memory.
- The Arduino has a certain amount of memory, and if your program gets too big, the compiler will give you an error.
Arduino Program Structure
Every Arduino program consists of at least two functions (if you don’t know what a function is, be sure to read my Basic Programming Tutorial Part 2 — Function and Control Operators and Part 1 where we discussed variables before continuing).
The first is the customization feature. This runs initially — once only — and is used to tell the Arduino what is connected and where, as well as initialize any variables you might need in your program.
Second cycle. It is the core of every Arduino program. When the Arduino is running, after the setup function is complete, the loop will loop through all the code and then do it all over again — until either power is lost or the reset button is pressed. The time it takes to complete one complete cycle depends on the code. You can write code that says «wait 6 hours» in which case the loop won’t repeat very often.