In this lesson, we'll learn below.
* Overall picture from making circuit diagram to making program
* How to use Arduino IDE
* Basic of programming: setup/loop function, digitalWrite, delay, pinMode
-Table of Contents
0:00 Opening
0:26 Material preparation
0:44 Circuit diagram
1:40 Assemble circuit
2:29 Basic of programming
3:27 Make program
4:32 Write to board
5:06 Conclusion
-Introduction
Hardware engineer
9 years experience as a Maker
-SNS
Web : start-electronics.com/
Twitter : / buonoatsushi
#Electronics #Arduino
-Content
Now, let's get things moving with the Arduino. In this lesson 3, you will learn what I have written here while working with your hands.
First, let me show you what we will create in this lesson. As you can see, the LED connected to the breadboard turns on and off repeatedly every second. This is what is called L-chica, and since L-chica is the first step for anyone starting out in electronics, this is where we will start in this course as well.
Let's start by preparing the materials we will use. We will use an Arduino Uno, a breadboard, two male and two female jumper wires, a red LED, and a 330Ω resistor. If you use the ELEGOO kit introduced in Lesson 1, all of these are included in the set.
The schematic of the circuit we are going to make is shown here, with the Arduino's No. 10 digital pin as the power supply, and the LED, resistor, and GND connected to it. The digital pin can be programmed to switch between input and output, and in the case of output, a 5V voltage is output, which can be programmed to switch between output and stop like a switch. Therefore, the schematic can be rewritten as such. By switching this switch at regular intervals, L-tickers can be realized. Also, be sure to connect a resistor to the LED as a set. The LED will turn on without the resistor, but there is a possibility that too much current will flow through the LED, damaging the Arduino and the LED. The resistance value was obtained using Ohm's law as follows. Here, the current to flow is assumed to be about 10mA. The calculation would be about 300Ω, but there was no good resistance value, so we chose 330Ω, which is close to the value.
Next, this circuit is connected using a breadboard like this. A breadboard is an essential tool for electronic construction, intended to make circuits quickly and easily. Note that the holes on the outside of the breadboard with blue and red lines drawn on them are connected vertically, while the holes on the inside are connected horizontally; for LEDs, the longer leg of the component is called the anode and the shorter leg the cathode, so that current can only flow from the anode to the cathode. On the other hand, there is no difference in resistance depending on the orientation, so you do not need to worry about the orientation. Also, if you use components with long legs, they are likely to wobble and cause shorts to other components, so be sure to cut them off as much as possible. With these precautions in mind, we will build the circuit with reference to the breadboard diagram. So, we have built the circuit.
Once the circuit is built, we can finally move on to the programming process. First, if you look at the program screen, you will see that there are two large chunks of code: void setup() and void loop(). This is a function, which is like a box to store the program. The loop function is executed repeatedly after the setup is executed. Generally, setup is used for the initial setup, and loop is used for the main processing. And the program is basically executed in order from the top line. Also, the lines starting with two slashes are called comments, which are like notes written to the person writing the program. Since a program will forget its contents after three days, you should make small notes so that you can quickly recall them when you look back at the program later.
Now let's write the program. First, we write pinMode(10, OUTPUT); in the setup section. pinMode is a function that has been created in advance to set the pin settings for each pin, and writing it like this means to set the number 10 digital pin to the output setting. Next, add four lines to the loop like this: digitalWrite is a function that acts as a switch, turning on the pin with the specified number when HIGH and turning off when LOW. delay is a function that determines how many ms to wait before proceeding to the next process, and here is 1000 ms, which means it waits for 1 second. Finally, select the line of the program you have written, press the tab on the keyboard to make it look better, and you are done. As you can see, the Arduino has many useful functions that are pre-made and can be called at will. Also, don't forget to type a semicolon at the end of each line, as it is a rule. When you have completed this step, save the file by clicking "File" on the menu bar, then "Save As..." to save the file.
Негізгі бет Тәжірибелік нұсқаулар және стиль [First Arduino] 3. LED | Starter course with Hands-on
Пікірлер: 14