Skip to content

Servo Motor

Component Servo Motor
Type Output
Function Rotational movement

Introduction

A servo motor is a type of motor that is used to control the position of an object. It is commonly used in applications such as robotics, remote control vehicles, and industrial automation. Servo motors are available in various sizes and configurations, and they can be controlled using a microcontroller or a servo motor driver.

The servo motor in your kit is a small, lightweight motor that can rotate from 0° to 180°. It is controlled using a pulse width modulation (PWM) signal, which allows you to set the position of the motor by varying the width of the pulse.

Pin Description

A servo motor has three wires: power, ground, and signal. You connect the power (5v) and ground wires to a power supply, and the signal wire to a digital pin on a microcontroller. You can use the Servo library in the Arduino IDE to control the position of the servo motor.

Code Example

The following code example demonstrates how to control the position of a servo motor using the Servo library in the Arduino IDE.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <Servo.h>

#define SERVO_PIN 9 // define the servo pin

Servo servo; // create a servo object

void setup() {
  servo.attach(SERVO_PIN); // attach the servo to the servo pin
}

void loop() {
  servo.write(0); // set the position of the servo to 0°
  delay(1000); // wait for 1 second
  servo.write(90); // set the position of the servo to 90°
  delay(1000); // wait for 1 second
  servo.write(180); // set the position of the servo to 180°
  delay(1000); // wait for 1 second
}

This example uses the Servo library to control the position of the servo motor. You can change the position of the servo by calling the write method with the desired angle as an argument.