Introduction

Have you ever wondered how to start the adventure with microcontrollers? Check Arduino. This open platform has been prepared for all DIY enthusiasts, including robot builders. The first part of the book discusses the basics required for further lessons.
If you are interested in electronics at least to a small degree and would like to start programming your own systems, then Arduino will be the perfect solution to start with. You won't have to waste time designing your own tiles, choosing the right programmer, and tedious environment configurations. Everything will work almost immediately.
This book has been planned for 11 parts (with possible continuation). Of book, he does not discuss the whole Arduino, and the subject is so extensive that you can write about it (several) books. The purpose of this book is to explain the basics in practice and to interest the reader in further exploring this platform.
What is Arduino?
For a beginner, Arduino is a ready "development kit" with the popular AVR microcontroller. Created according to the relevant assumptions, thanks to which:
  1. Does not require an external programmer
  2. Works well with a dedicated compiler
  3. You can buy an "infinite" number of expansion boards (e.g., motor controllers, displays, executive modules)
However, the true power of Arduino lies in a dedicated programming language based on C / C ++. Starting the adventure with microcontrollers, it's worth learning at least the basics about their construction and how they work.
Fortunately, in the case of Arduino, to program your system, you do not need to know the microcontroller registers. Everything is based on friendly libraries, thanks to which the creation of even a complicated program is within reach of a novice programmer.
In short, Arduino is modules with microcontrollers that can be easily programmed using generally available libraries in a language similar to C / C ++.
Advantages of Arduino
The project began to be developed in 2005 in Italy. Since then, he has gathered a mass of supporters and fanatical users. From the very beginning, Arduino was prepared for people who did not have much in common with programming microcontrollers.
Excellent environment, friendly syntax, and low prices have made Ardunio extremely popular. The community built around this project is huge. This brings many benefits. From a beginner's point of view, three are most important:
Arduino - Choosing a Hardware Platform
Arduino is an Open Hardware platform. This means that all materials needed to create your own development kit operating in this standard are available. For this reason, you can find many different tiles compatible with Arduino.
At the moment, Arduino officially talks about 20 available models on its websites. In every good store, you will find at least a few different sets. For the needs of the book, I decided to choose the most popular tile - Arduino UNO R3.
Arduino is a project that is constantly growing - both in programming and hardware. The UNO version 3 board is currently prompted by Arudino, like the one on which the latest libraries and expansion boards can be used for a long time.
Equipment Arduino UNO R3
The heart of the system is the popular 8-bit microcontroller from Atmel, AVR ATmega328, operating at a frequency of 16 MHz.
Working at such a frequency in a simplified way means that the microcontroller can perform 16 million operations per second. It's a lot.
Special connectors, placed characteristically on the sides of the board, are the outputs of the most important signals. There we will find 14 programmable digital inputs/outputs. Six of them can be used as PWM outputs (e.g., for motor control), and another six as analog inputs. We will also find there a reset signal and power supply.
Arduino can be powered in several ways. The most popular methods are:
  1. Power supply via USB cable
  2. Powered by a plug-in power supply (optimally 7V - 12V) or batteries
The most important elements are marked on the graphic below:
  1. USB connector - used for power supply, programming, and communication with a computer
  2. Power connector  (optimally 7V - 12V)
  3. Voltage stabilizer - the input voltage from connector 2 is reduced to 5V thanks to this system
  4. Reset button - resets the Arduino board
  5. Microcontroller responsible for communication with the computer via USB
  6. Programming connector for the microcontroller from step 5.
  7. Signal connector *
  8. Signal connector *
  9. LED diode signaling connection of voltage to Arduino
  10. Programmer output for the microcontroller from point 13.
  11. Signal connector *
  12. Power connector *
  13. Arduino heart, AVR ATmega328 main microcontroller
  14. LEDs signaling transmission to/from the computer
  15. LED at the user's disposal
  16. Ceramic resonator  clocking the microcontroller (point 13) with a frequency of 16MHz
  17. A jumper that when cut off disables Arduino's automatic reset.
  18. Solder pads with derived microcontroller signals from point 5, used extremely rarely in very specific and non-standard situations.
Clones, or Arduino (un) Original
As I mentioned, Arduino is an open-hardware platform. This means that anyone can make their own Arduino or design a tile per this standard. Sets from other companies operating, such as Arduino, are commonly called clones.
Clones can be divided into two types:
For example, if you are looking for the Arduino UNO mentioned above and you find a plate identical to my photos at a price of less than $120, it will be 100% fake. You can take a chance and buy one. The choice is yours, whether you want to support companies that earn dishonestly or choose those that have put a little more effort into the production of their version.
Warning.   The cheap imitation ones are often made of inferior quality elements that can damage the entire system.
Materials you need to program Arduino
In addition to the Arduino UNO mentioned above, a handful of additional elements will be used in the first seven parts of the book. A USB cable and connection cables will definitely be useful. Plus colored LEDs and buttons. We will present more complicated items on a 2x16 character text display.
In the further chapters of the book, we will also discuss controlling actuators such as servos and motors. Sensors will also be useful. We will use light sensors ( photoresistors ) and an ultrasonic distance sensor.
The set of necessary elements is visible in the photo below:
Now we will deal with the installation of the environment. I assume you don't have the equipment you need yet. However, Arduino will be necessary for further learning.
Arduino IDE Installation
The appropriate environment must be installed before programming. The latest Arduino IDE can be downloaded from the project's official website . The installer takes about 53 MB.
Warning. Update (14.04.2015)
Due to the conflict, two versions of the environment appeared within the Arduino team. Fortunately, this doesn't matter much to the end-user. However, if you purchased the original board, check the address on its back before installing the environment.
There you will find a reference to one of the following pages:
If the first address occurs, download the environment from here . However, if you find a second address on the back of the tile, get it from here .
What happens when you install the wrong IDE?
Note - You will only be notified that the tile you have does not come from an authorized source. You can turn off this message with one click. Everything will work without problems.
Download the latest version.
Installation is standard. In the beginning, we accept the product license:
Then click a few times Next, and we become happy users of the Arduino IDE. Along the way, pay attention to the components installed:
If we choose to install the USB driver (which is recommended), we will see a system warning at the end of the installation.
Click " Install this driver software anyway, " you don't have to worry about anything. After the installation is complete, a new icon should appear on your desktop:
If the software has been installed correctly, we will see the welcome screen after starting it:
And after a while the editor:
If you already have Arduino
I wrote earlier that we would not program in this part. However, if you already have Arduino, you can do something very simple to check if everything works. First, start the Arduino IDE editor. Then from the menu select:
File -> Examples -> 01. Basics -> Blink
A separate window will open with the program code (do not temporarily penetrate its structure). It should look similar to the following:
Now connect your Arduino to the computer. Use a USB cable for this, and you do not need to connect battery power. You only need this one cable. Now the computer will detect new hardware and install drivers.
When the equipment is ready for use, check which COM port has been assigned to your board. You can do this by going to the device manager:
Computer -> Properties -> Device Manager
Now we can go back to the Arduino IDE settings. Here we have to choose two options. First of all, we tell the compiler which board we use. Then indicate the previously checked COM port number.
The Arduino IDE only shows the available COM ports. For me it was COM1 and COM21, you can have many more. The main thing is to choose the right one.
Board connected and set up. Now we can proceed to upload the program. To do this, we need to choose two options:
The first one is the equivalent of "Compiles" found in other environments. This process is responsible for checking the correctness of the code and its compilation, or conversion into a language understandable for programmed electronic devices.
The second command is responsible for sending the program to the Arduino UNO board. After clicking the Load button, the LEDs labeled TX and RX should flash on the board. This means that the data is transferred from/to the computer.
When the process is done correctly, you'll find the appropriate message at the bottom of the Arduino IDE. There will be information that the program has been sent and how much space has taken up in the memory of our microcontroller - in this case, it was 1 084 bytes.
The fact that the program has been sent correctly can also be seen on Arduino. As I mentioned earlier, we have 1 LED on the board. After uploading the program, it should flash.
The effect is not thrilling, but we know that everything works. Next, we'll start writing programs ourselves. In the meantime, you can try to edit the code we have downloaded and test how the system will behave.
Now here it’s enough "long introduction" to the book. I hope that it explains the basic issues and encourages you to follow the next chapter.