B8: Servo Motor Connection diagram for all servo codes

AR-B8: Servo Motor Basic Code

This entry is part 8 of 13 in the series Arduino Basic Circuits

In this code the servo motor is controlled in required angle. We can change the value of the angle in the code either positive or negative angle.

Required Material

Arduino UNO Board – 1, data cable – 1, Servo Motor – 1, Jumper wires – 3.

Working

Servo motor is used in humanoid robots and automatic machines in industries.  Servo motor rotates only from 0° to 180° i.e. half circle. When you upload the code in Arduino, the motor start rotating. First it resets back to 0° from any previous position. Then after 1 second it turns in 90° and then after 1 second again it rotates in 90° and finally it comes back to 0°.

Precautions

  1. DO NOT ROTATE THE SHAFT OF THE SERVO MOTOR WITH YOUR HANDS. IT WILL DAMAGE THE SERVO MOTOR.
  2. Connect the orange wire of servo motor to any Pulse Width Modulation pin i.e. PWM pin like pin-3, pin-5, pin-6, pin-9, pin-10 or pin-11. These pins are marked as (~) on the Arduino board.
image 19 Vidyasagar Academy
Connect servo motor wires as shown above. WRONG CONNECTIONS WILL DISTROY THE SERVO MOTOR.

Procedure

  1. After uploading the code, connect the 3 wires of servo motor as shown in the diagram on next page.
  2. Then connect Arduino to USB port through data cable.
  3. The motor will start rotating as per the angles set in the program.

The Code

Servo motor is very useful in robotics to get the machine level action of a robotic arm or automated system. Just copy the following code and upload in Arduino UNO to run the project successfully.

#include <Servo.h>
Servo i;

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

void loop()
{
  i.write(0);
  delay(1000);
  i.write(90);
  delay(1000);
  i.write(180);
  delay(1000);  
}


Circuit Diagram

This circuit diagram is applicable to all the servo motor projects in this series.

B8: Servo Motor Connection diagram for all servo codes

Important Note: Project #B9 is removed due to similar content like B8

Share on your network!
Prof. Dattaraj Vidyasagar
Prof. Dattaraj Vidyasagar

Author on this website. He is veteran of Core Electronics since last 36+ years. ATL Mentor of Change, Niti Ayog, Govt. of India, Google Certified Educator, International Robotics Trainer and author of 18 books on electronics, robotics, programming languages and web designing... ➤➤

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x