090-PostLab21
090-PostLab21
A servo motor is an electric device used for precise control of angular rotation. It is used in applications that
demand precise control over motion, like in the case of control of the robotic arm. The rotation angle of the servo
motor is controlled by applying a PWM signal to it. By varying the width of the PWM signal, we can change the
rotation angle and direction of the motor. Mostly 50Hz PWM is used to control the shaft position of the servo
motor.
A servo motor is a rotary actuator that allows precise control of angular position, speed, and acceleration. It
consists of three main components:
1. DC Motor: Provides the rotational motion.
2. Gearbox: Reduces speed and increases torque.
3. Control Circuit: Processes input signals to position the motor accurately.
Servo motors are widely used in robotics, drones, industrial automation, and home automation due to their
precision and ease of control.
• The servo motor is controlled using a Pulse Width Modulation (PWM) signal.
• A PWM signal is a square wave signal where the width of the "ON" period determines the position of the
servo motor.
• The duration of the pulse within the 20ms period determines the angle:
Feedback Mechanism:
• A potentiometer inside the servo provides feedback about its current position.
• The control circuit adjusts the motor’s position until the desired angle is achieved.
Introduction to PWM
Pulse Width Modulation (PWM) is a technique by which the width of a pulse is varied while keeping the
frequency of the wave constant.
PWM Generation
A period of a pulse consists of an ON cycle (VCC) and an OFF cycle (GND). The fraction for which the signal
is ON over a period is known as a duty cycle.
E.g. A pulse with a period of 10ms will remain ON (high) for 2ms.Therefore, the duty cycle will be
D = 2ms / 10ms = 20%
Through the PWM technique, we can control the power delivered to the load by using the ON-OFF signal. The
PWM signals can be used to control the speed of DC motors and to change the intensity of the LED. Moreover,
it can also be used to generate sine signals. Pulse Width Modulated signals with different duty cycle are shown
below.
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Aim: Interfacing Servo Motor with NodeMCU
sensor interfacing (01CT1103)
Experiment No: 21 Date: 4 Dec’24 Enrollment No:92400133090
NodeMCU based ESP8266 has the functionality of PWM interfaces via software programming. It is achieved
with the timer interruption method. The PWM frequency range for ESP8266 is adjustable up to 1KHz.
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Aim: Interfacing Servo Motor with NodeMCU
sensor interfacing (01CT1103)
Experiment No: 21 Date: 4 Dec’24 Enrollment No:92400133090
analogWrite(pin, dutycycle): Enables software PWM on the specified pin. duty cycle is in the range
from 0 to PWMRANGE, i.e. 1023 by default.
analogWriteRange(new_range): This function is used to change the PWM range (duty cycle).
Code:
#include <Servo.h> // Include the Servo library
void setup() {
myServo.attach(5); // Attach the servo to pin 9
myServo.write(0);
delay(2000);
}
void loop() {
// Rotate servo to 90°
myServo.write(90);
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Aim: Interfacing Servo Motor with NodeMCU
sensor interfacing (01CT1103)
Experiment No: 21 Date: 4 Dec’24 Enrollment No:92400133090
// Rotate servo to 0°
myServo.write(0);
delay(1000); // Wait for 1 second
Post-Lab:
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Aim: Interfacing Servo Motor with NodeMCU
sensor interfacing (01CT1103)
Experiment No: 21 Date: 4 Dec’24 Enrollment No:92400133090
Code
void setup() {
myServo.write(0);
delay(2000);
void loop() {
myServo.write(90);
// Rotate servo to 0°
myServo.write(0);
Marwadi University
Faculty of Engineering & Technology
Department of Information and Communication Technology
Subject: Foundation skills in
Aim: Interfacing Servo Motor with NodeMCU
sensor interfacing (01CT1103)
Experiment No: 21 Date: 4 Dec’24 Enrollment No:92400133090
//myServo.write(180);