Advertisement

Arduino nano project with servo motor | How does work servo motor.

    Arduino nano project with servo motor

    
        Hello guys, Welcome back to my blog. We have already described 10 posts on this Arduino. These posts are created to be very easy to learn. Today we are going to talk about the servo motor that many people like to learn.OK, let's go to today's post.

What is the servo motor?

    A servo motor usually includes a simple DC motor but it has a gear wheel system. Also, the servo motor includes a sensor system for measuring gear wheel rotation. So we can rotate it to the desired digress. Usually, the servo motor can rotate 0 to 180 degrees. You can also buy 360-degree servo motors in the market if you want. These servo motors are mainly used to make robotic arms. We can buy servo motors of different sizes in the market. It depends on the project we are doing. These servo motors can be rotated by the PWM signal on the Arduino board. You can use PWM pins on the Arduino board for that. The servo motor consists of three wires. The wire colors are orange, red, and brown. The red and brown wires are used to power the servo motor. The orange wire is used to rotate the servo motor to the required number of degrees. We can use a PWM signal for this purpose. These points are common to all servo motors.

Okay, let's do a simple project using a servo motor. We use a very cheap servo motor for this project. The required components and how to do it step by step are as follows.

Components


Step 1
Let's identify these components.

Arduino Uno



You can use any other Arduino board.

Servo Motor


This is described above.

Jumper wires


Three jumper wires from MALE to MALE have been used for this project.

Step 2
Connect the servo motor to your Arduino board using the circuit diagram below.



Step 3
Look at the code below.

#include <Servo.h>
Servo sritutech;

void setup() {
  sritutech.attach(3);
}

void loop() {
  sritutech.write(0);
  delay(400);
  sritutech.write(180);
  delay(400);
}

Let's look at this code one by one.

#include <Servo.h>
Let us learn something new from this code. It's about libraries.
What is the Arduino library file?
   A library is a file containing code issued by a company to make it easier for us to work with a device. The servo motor library file is included in the Arduino IDE. Include it as follows.


Create an object using any name you like.
Servo sritutech;


This code informs us about the PWM pin we are using.
void setup() {
  sritutech.attach(3);
}

This code will be inserted into the Arduino board in the number of degrees required for the servo motor to rotate.
void loop() {
  sritutech.write(0);
  delay(400);
  sritutech.write(180);
  delay(400);
}

Step 4
Select board and port.




Step 5
Upload this code and enjoy it.






OK, let's do this project using the Arduino Nano board. Follow the steps below.

Components

Step 1
Let us identify these components.

Arduino Nano



Servo Motor


Jumper Wires


Three MALE to FEMALE jumper wires were used for this project.

Step 2
Connect the servo motor to your Arduino board.



Step 3
Use the code above for this project. The D9 PIN was used for this project.

#include <Servo.h>
Servo sritutech;

void setup() {
  sritutech.attach(9);
}

void loop() {
  sritutech.write(0);
  delay(400);
  sritutech.write(180);
  delay(400);
}

Step 4
Select board and port.




Step 5
Upload this code.


The full video of this article is below. Watch it.


Understand the code below and upload it to your Arduino board. Please comment on your questions below. We will meet in the next post. Have a good day. Bye-bye.  

#include <Servo.h>
Servo sritutech;

void setup() {
  sritutech.attach(9);//set arduino PWM pin D9
}
void loop() {
  for (int a = 0 ; a <= 180 ; a++) {
      sritutech.write(a);
    delay(10);
  }
  for (int k = 179; k > 0 ; k--) {
   sritutech.write(k);
   delay(10);
 }
}

Post a Comment

0 Comments