0% found this document useful (0 votes)
4 views

Laboratory-7

The document outlines an experiment on servo motors at Iloilo Science and Technology University, detailing objectives, equipment, and procedures for interfacing a servo motor with a Gizduino board. It explains the functionality of servomotors, their applications, and provides sample code for controlling the motor's rotation. Students are guided through programming, connecting components, and observing motor behavior, with questions to reinforce learning.

Uploaded by

khenverlee6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Laboratory-7

The document outlines an experiment on servo motors at Iloilo Science and Technology University, detailing objectives, equipment, and procedures for interfacing a servo motor with a Gizduino board. It explains the functionality of servomotors, their applications, and provides sample code for controlling the motor's rotation. Students are guided through programming, connecting components, and observing motor behavior, with questions to reinforce learning.

Uploaded by

khenverlee6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Experiment

ILOILO SCIENCE AND TECHNOLOGY UNIVERSITY 7


La Paz, Iloilo

Name : ___________________________________________________Year & Sec.:______________


Date Performed: ______________________________________________Rating: __________________
Date finished: ________________________________________________Instructor’s signature :_______

Experiment 7: SERVO MOTORS


Objectives
At the end of the experiment the students were able to:
1. Identify the pins of the servo motors.
2. Use digital I/O pins of the GizDuino in programming.
3. Rotate the servo motors in a precise number of degrees .
4. Program in Arduino IDE and upload it on a Gizduino board.
5. Interface a servo motor with the Gizduino Board.
Equipment and Materials
1 pc Gizduino Board
1 pc USB Standard A-B Cable
1 set Connecting Wires
1 set Desktop computer/Laptop computer
1 pc Bread Board
1 pc Servo Motor

Discussion

A servomotor is a rotary actuator or linear actuator that allows for precise control of angular or
linear
position, velocity and acceleration. It consists of a suitable motor coupled to a sensor for position
feedback. It also requires a relatively sophisticated controller, often a dedicated module designed
specifically for use with servomotors.

Servomotors are not a specific class of motor although the term servomotor is often used to refer
to a
motor suitable for use in a closed-loop control system.

Servomotors are used in applications such as robotics, CNC machinery or automated


manufacturing.

A servomotor is a closed-loop servomechanism that uses position feedback to control its motion
and
final position. The input to its control is a signal, either analogue or digital, representing the position
commanded for the output shaft.

The motor is paired with some type of encoder to provide position and speed feedback. In the
simplest case, only the position is measured. The measured position of the output is compared to the
command position, the external input to the controller. If the output position differs from that required, an
error signal is generated which then causes the motor to rotate in either direction, as needed to bring the
output shaft to the appropriate position. As the positions approach, the error signal reduces to zero and the
motor stops.

57

Figure 8.1. A servo motor.

A servomotor consumes power as it rotates to the commanded position but then the servomotor
rests.
Stepper motors continue to consume power to lock in and hold the commanded position.

Figure 8.2. Servo motor with higher performance.


Servomotors are generally used as a high-performance alternative to the stepper motor. Stepper
motors have some inherent ability to control position, as they have built-in output steps. This often allows
them to be used as an open-loop position control, without any feedback encoder, as their drive signal
specifies the number of steps of movement to rotate, but for this the controller needs to 'know' the position
of the stepper motor on power up. Therefore, on first power up, the controller will have to activate the
stepper motor and turn it to a known position, e.g. until it activates an end limit switch.

Procedures:

1. Encode the sketch below and upload it to the gizDuino board:

#include <Servo.h>

Servo myservo; // create servo object to control a servo


// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo
object }

58
void loop()
{ for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(100); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{ myservo.write(pos); // tell servo
to go to position in variable 'pos' delay(100); // waits 15ms
for the servo to reach the position
}
}
2. After uploading, disconnect first the gizDuino microcontroller to the laptop/computer. Prepare servo
motor and follow the connections of Figure 8.3 below.

Figure 8.3. Servo motor interfaced with a microcontroller.

Servo motors have three wires: power, ground, and signal. The power wire is typically red, and
should be connected to the 5V pin on the Arduino board. The ground wire is typically black or
brown and should be connected to a ground pin on the Arduino board. The signal pin is typically
yellow, orange or white and should be connected to pin 9 on the Arduino board.

4. After connecting all the necessary configurations, connect again the gizDuino microcontroller
to the laptop/computer by a usb-to-serial cord.
5. Observe what is happening on the servo motor. Answer guide questions.
59
6. With the same connections on a seven segment display, upload this source code below the
figure:

Figure 8.4. Schematic diagram of servo motor interfaced with a microcontroller.

#include <Servo.h>

Servo myservo; // create servo object to control a servo


// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{ for(pos = 0; pos < 180; pos += 10) // goes from 0 degrees to 180 degrees
{ // in steps of 10 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(1000); // waits 1s for the servo to reach the position
}
60
for(pos = 180; pos>=1; pos-=10) // goes from 180 degrees to 0 degrees
{ myservo.write(pos); // tell servo
to go to position in variable 'pos' delay(1000); // waits 1s
for the servo to reach the position
}
}
Guide Questions:

1. Describe what is happening on the servo motor on the first source code.
Answer:
In the first source code, the servo motor is being controlled to move to specific angles using
programmed instructions. The code starts by attaching the servo to a pin on the microcontroller (like an
Arduino), then sends angle values to it using the servo.write() function. For example, the code might tell
the servo to move from 0° to 90°, then to 180°, pausing between each move using a delay function. This
cycle might repeat continuously. The motor doesn’t rotate like a DC motor—instead, it turns to and holds
a set angle precisely, which is great for applications like moving arms or controlling levers.

2. What have you noticed on the rotation?


Answer:

I noticed that the servo motor doesn’t rotate in full circles. Instead, it moves back and
forth within a limited range, usually from 0° to 180°. The movement is controlled and stops exactly at
the angle specified in the code. If the code tells it to move from 0° to 90°, it will rotate to 90° and stay
there until it receives another instruction. I also observed that the speed of rotation is affected by how
fast or slow the delay is set in the code. A short delay makes the servo move quickly to the next
position, while a longer delay makes the movement slower and easier to watch. Overall, the rotation is
smooth, and the motor holds its position firmly after reaching the angle.

3. Can we use other pins aside from pin 9 for the attaching servo motor?
Answer:
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
Review Questions:
1. What is the difference between myservo.write and myservo.attach?.
Answer:
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
2. In the source code, how does the servo motor rotates?
Answer:
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
3. What is the maximum turn a servo motor can have?
Answer:
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
Challenge Yourself:
1. Program a gizDuino microcontroller such that the servo motor will rotate every 5 degrees with a gap 1
second form 0 degree to 180 degrees but every time it reaches 60 degrees it will stop for 10 seconds
before proceeding. Present your output to your instructor if done

Conclusion:
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
61

You might also like