Arduino for beginners. Part 1

Foreword


Good day, Habr. I’m starting a series of articles that will help you get acquainted with Arduino. But this does not mean that if you are not new to this business, you will not find anything interesting for yourself.


Introduction


It would be nice to start by exploring the Arduino. Arduino - hardware and software for building automation systems and robotics. The main advantage is that the platform is aimed at non-professional users. That is, anyone can create their own robot, regardless of programming knowledge and their own skills.


Start


Creating a project on Arduino consists of 3 main stages: writing code, prototyping (prototyping) and firmware. In order to write code and then flash the board, we need a development environment. In fact, there are many of them, but we will program in the original environment - Arduino IDE. The code itself will be written in C ++, adapted for Arduino. You can download it on the official website . Sketch (sketch) is a program written in Arduino. Let's look at the structure of the code:


main(){
    void setup(){
    }
    void loop(){
    }
}

It is important to note that the main()Arduino processor creates the mandatory function in C ++ itself. And the result of what the programmer sees is:


void setup(){
}
void loop(){
}

Let's deal with two required functions. The function setup()is called only once at the start of the microcontroller. It is she who sets all the basic settings. The function loop()is cyclic. It is called in an endless cycle throughout the entire operation of the microcontroller.


First program


In order to better understand the principle of the platform, let's write the first program. We will execute this simple program (Blink) in two versions. The difference between them is only in the assembly.


int Led = 13; // объявляем переменную Led на 13 пин (выход)
void setup(){
    pinMode(Led, OUTPUT); // определяем переменную
}
void loop(){
    digitalWrite(Led, HIGH); // подаём напряжение на 13 пин
    delay(1000); // ожидаем 1 секунду
    digitalWrite(Led, LOW); // не подаём напряжение на 13 пин
    delay(1000); // ожидаем 1 секунду
}

The principle of operation of this program is quite simple: the LED lights up for 1 second and goes out for 1 second. For the first option, we do not need to collect the layout. Since in the Arduino platform, a built-in LED is connected to the 13th pin.


Arduino firmware


In order to fill the sketch on the Arduino, we just need to save it first. Further, in order to avoid problems during loading, it is necessary to check the programmer settings. To do this, select the “Tools” tab on the top panel. In the "Payment" section, select your payment. It can be Arduino Uno, Arduino Nano, Arduino Mega, Arduino Leonardo or others. Also, in the "Port" section, you must select your connection port (the port to which you connected your platform). After these steps, you can upload the sketch. To do this, click on the arrow or in the “Sketch” tab select “Download” (you can also use the keyboard shortcut “Ctrl + U”). Board firmware completed successfully.


Prototyping / prototyping


To build the layout, we need the following elements: LED, resistor, wiring (jumpers), breadboard (Breadboard). In order not to burn anything, and in order for everything to work successfully, you need to deal with the LED. He has two paws. Short - minus, long - plus. For a short, we will connect the "ground" (GND) and a resistor (in order to reduce the current strength that goes to the LED so as not to burn it), and for the long we will supply power (connect to 13 pin). After connecting, download the sketch to the board if you have not done so previously. The code remains the same.


This is the end of the first part. Thanks for attention.


Also popular now: