Hello! In this article, we will blink an LED! Now for many of you, this will seem banal and a mere trifle, you will laugh at those who repeat it again and again. Now, remember how you yourself tried to do it a few years ago?
Perhaps it did not work out the first time: the incorrect setting of the board in the development environment, searching for the desired resistor, installing drivers on the board, etc. But when the LED started to flash … Oh, yes! And if we compare the people who lived in the Soviet Union with the current generation, then ours had the best childhood — they blinked with a LED 🙂
Let’s go back to this “golden time” and once again feel this sweet taste of victory!
Blink we will be the LED built into the Arduino board. It is also indicated on the board by the letter L.
Actually, in addition to the board, we will need a computer with an installed Arduino IDE development environment and a USB cable for interfacing our devices.
Go to the Arduino IDE. There is no need to install anything else. Now we go to the file -> examples -> built-in examples -> Basics -> Blink.
What is in the archive? To begin with, I note that in any code for Arduino there must be two mandatory functions: void setup () and void loop (). The first one registers what is executed only once when the board is turned on. In the second, that will be performed continuously, cyclically. Before the void setup () function, variables are written that need to be used in the code (sketch), various libraries are connected, arrays are specified – in general, any data that we will use in the code. As you understand, in our code, nothing like this is required.
There are 14 digital pins on the Arduino Uno board (from D0 to D13). Analog contacts are also available (labeled A0 to A5). At the outputs of digital contacts can be two values
Therefore, we will connect it to a digital contact. To contacts from 0 to 12, you can connect external LEDs through a 220 Ohm resistor. Pin 13 includes the LED already built into the board, which we talked about earlier. Using the pinMode function, we specify the type of digital output as output, since the LED will execute our commands, this is the load that waits for instructions (the same is indicated, for example, when the relay is connected).
Next is the cycle. As mentioned earlier, on the digital contact we can adjust two values. High logic level (HiGH) and low logic level (LOW) set the maximum value of the voltage (5V) on it and the minimum (0V), respectively.
When HiGH is set, the maximum voltage is applied and the LED is on. If LOW, the minimum value is applied and the LED goes out.
In order to see how it flashes – set the delay using the function delay (1000). This command pauses the operation of the code for the time that is written in brackets, in other words, it pauses our code. The time in milliseconds is indicated in brackets (1000 milliseconds = 1 second). When the HIGH state turns on, and then a pause of 1 second turns on, then, since the state on the LED output has not changed, the LED will light for exactly 1 second. Then it turns off for 1 second, turns on again, and so on. So we get, it flashes. Happened!
I have it all. If you liked the article, then look at other, more informative articles in our blog. Thank you all for your attention and successful compilation!