📜 ⬆️ ⬇️

Arduino for beginners. Part 1

Foreword


Good day, Habr. I run a series of articles that will help you in acquaintance 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 not be bad to start with an acquaintance with 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 the Arduino consists of 3 main stages: writing code, prototyping (prototyping) and firmware. In order to write the code and then flash the board, we need a development environment. In fact, there are a lot of them, but we will program in the original environment - the Arduino IDE. The code itself will be written in C ++, adapted for Arduino. You can download it on the official site . Sketch (sketch) - 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 Arduino processor itself is required in the C ++ function of main() . And the result of what the programmer sees is:


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

Let's deal with the two mandatory functions. The setup() function is called only once when the microcontroller starts. It is she who sets all the basic settings. The loop() function is cyclic. It is called in an infinite loop during the entire time 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 simplest 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 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 build a layout. As in the Arduino platform, pin 13 is connected to the built-in LED.


Arduino firmware


In order to upload a sketch to the Arduino, we just need to save it first. Further, in order to avoid problems when loading, it is necessary to check the settings of the programmer. To do this, select the "Tools" tab on the top panel. In the "Fee" section, choose your fee. 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 actions, you can upload a sketch. To do this, click on the arrow or in the “Sketch” tab select “Download” (you can also use the key combination “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 to not burn anything, and in order for everything to work successfully, you need to deal with the LED. He has two legs. Short - minus, long - plus. We will connect a ground (GND) and a resistor to a short one (in order to reduce the current that goes to the LED so as not to burn it), and we will supply power to the long one (we will connect it to pin 13). After connecting, upload a sketch to the board, if you have not done it before. The code remains the same.


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


')

Source: https://habr.com/ru/post/352806/


All Articles