In this lesson, we'll learn below.
* For: Frequentry used in cyclic process
* Import library
* Serial monitor (Graph)
-Table of Contents
0:00 What's servo motor
0:51 What we make
0:58 Material preparation
1:03 Circuit diagram
1:27 Assemble circuit
1:55 Make program
4:07 Write to board
4:30 Conclusion
-Introduction
Hardware engineer
9 years experience as a Maker
-SNS
Web : start-electronics.com/
Twitter : / buonoatsushi
#Electronics #Arduino
-Content
Servo motors are motors that can control the angle of rotation and speed, and are widely used in applications such as joints of robots and opening/closing of railroad crossings, where you want to move an object with high precision within a certain angular range. The structure of a servomotor consists of an ordinary brushed DC motor, some gears, a control board, and a potentiometer that detects the amount of rotation. Here is a simple system of a servo motor: When a controller such as Arduino sends a rotation angle instruction, the brushed DC motor rotates. The amount of rotation is detected by the potentiometer, and the motor is stopped when it reaches the specified angle. This system of detecting the amount of change and determining the next action is generally called feedback control.
In the circuit we have created this time, the motor rotates 180 degrees every 5 seconds. Now let's make this circuit.
The materials we will use this time are an Arduino Uno, a servo motor, and three male and three female jumper wires.
Here is the circuit diagram we will create. The servo motor is powered by the Arduino's 5V output terminal, which is directly connected to the USB port, so it can draw up to 500mA, which is the USB standard. Although large motors cannot be driven, small servo motors for hobby use, such as the one used in this project, can be used with no problem.
Next, a breadboard diagram is shown here, following the circuit diagram. Most servo motors, including the type used in this project, have three wires: orange, red, and brown. In this case, orange represents the signal, red represents the power, and brown represents the GND line, so be sure not to make a mistake. Now let's build the circuit according to this diagram. Yes, so we have built the circuit.
Now let's start coding: open the Arduino IDE, click File→New File, and type in the program shown in this screen. Here, we first import a library for servo motor control called Servo.h using the code #include in the first line. A library is a collection of code that is provided to run a module, and Arduino comes with several libraries by default, including Servo.h. By using these libraries, you can write code from scratch. By using these libraries, you can write code more easily than by writing code from scratch, so you should make active use of them. Incidentally, servo.h, which we will use this time, has the following six functions, so please take a quick look at them before using them. In order to be able to use the library read out, an object is created in this section as a preliminary step. An object is a bit of a difficult concept, but it is something that is called out from the blueprint state into the real world in order to actually be able to use the functionality.
In the setup function, we use a function called attach in the servo library and assign pin 9 as a pin for signals. Also, in order to monitor the value using the serial plotter function this time, the Serial.begin function is used as well as the serial monitor function.
Next, in the loop function, we write a process that repeats itself using a "for" statement, in which the program repeats itself as long as the condition in the round brackets is satisfied, using the part enclosed in braces. Inside the round brackets are three sections: the initialization process, the conditional expression, and the increment. There are several ways to write increments, but they all mean the same thing, so keep them in mind. In this case, the variable angle, which represents the angle of rotation of the servo motor, is first assigned 0, and the process is repeated, adding one increment at a time, until it reaches 180, and so on. Then, in that part of the processing, the function "write" in the servo library is used to rotate the servo motor so that it reaches the angle of each angle. After that, it waits for 30ms and also allows the current angle value to be viewed on the serial plotter. Simply put, this means that the angle is rotated from 0 to 180 degrees, one degree at a time. After rotating to 180 degrees, it waits for 1 second and then repeats the same operation starting from 0 degrees again.
Негізгі бет Тәжірибелік нұсқаулар және стиль [First Arduino] 7. Servo Motor | Starter course with Hands-on
Пікірлер: 5