Activity-3A-Servo-Motors-1
Activity-3A-Servo-Motors-1
ca
Description The purpose of these projects is to help students learn about new technologies
and concepts.
The module “Motion” will be broken up into three main activities. The first project
is titled “Servo Motors” and it will be followed by two additional activities- 3B:
Distance Sensor, and 3C: Motion Alarm.
Outcome(s) Supports:
PAA - Electronics Modules - ELEC02A, ELEC04A; Robotics Modules -
ROBA49, ROBA63, ROBA8-13; Science - CE9.1, CE9.2, PW1
Math P7.3, SS7.1, SS7.3, SS7.4, P8.1, N8.3, SS9.1
Required Prior Getting Started: Activity One - Downloading Programs for Arduino
Learning
Materials Computer, Arduino Uno Board, USB cable, Breadboard, Potentiometer, Servo,
Six jumper wires, Scissors
Assessment Review lesson ending questions with students for understanding and future
application.
2
Procedure
Review the organization of the kit and how groups need to be careful with all the components,
how they are used, and how they need to be kept organized and put back into their place when
done.
Divide your class into groups of two (Paired Programming). Paired programming is highly
recommended when working with coding and robotics so that students can piggyback off each
others ideas and strengths.
Students will learn how to control a servo. In simple terms it is a simple motor which tracks the
angle. It is very useful in robotics to control steering or direction. Most servos have a limited
range. It is best to use them between 20 and 160 degrees (although they can go from 0 to
180 degrees.)It may damage them to go outside this range. The servos tend to “stutter” and get
damaged at the extreme range.
Extension
Students can complete the extension challenges once they have done the first program
Student Handouts
Activity - Servo Motors
Assessment Guide
Circulate the room observing and assisting with students so that they can complete the project.
Correct the assignment sheet as a class ensuring that students share their errors and
successes while reinforcing the importance of persistence and patience in programming.
3
Materials:
Computer, Arduino Uno Board, USB cable, Breadboard, Potentiometer, Servo, Six jumper
wires, Scissors
New Components:
Servo Motor: Servo motors have three wires: one for power, one for
ground and one for signal. When you send the right signal through the
signal wire, the servo will move to a specific angle and stay there.
Common servos rotate over a range of about 0° to 180°.
BROWN is GROUND
RED is POSITIVE
ORANGE is DATA (assigned to a pin on the Arduino)
Note: It’s best to avoid driving the servo all the way to 0 or 180 degrees. It can cause the motor
to jitter, which is bad for the servo. So typically a range of 20-170 works best.
Procedure:
1. Wire the project using the following schematic.
4
Code
You can create your code in the BlocklyDuino then paste it to the Arduino IDE. Click
BlocklyDuino Reference for a link to all the blockly codes. Here are the blocks you will need.
1. Select the servo from the blocks menu and assign it to pin 9. Servo has its own set of
blocks and they are found under “SERVO” on the left hand side of the menu. We are
then going to assign a map function to the angle in the next step.
2. The code below uses the “MAP” function. The MAP function converts the resistance of
the potentiometer (0-1024) to an angle (0-180). You will find the map block in “MATH.”
Drag the block into the blockly editor and attach it to the angle of the servo. Therefore,
the angle of the servo will depend on a value that the potentiometer gives. We will add
the “pot’ with the next step. 7
3. The potentiometer (rotary angle) controls the resistance. Select “rotary angle” from the
GROVE menu under “INPUTS” and assign it to pin A0
4. If the servo motor is jittery when you moving it, switch your angles in your code from (0-
180) to (20-160). Your code should look like this:
5
5. Once your blockly code is finished, click on the arduino to transfer the information in the
blocks to Arduino.
CLICK
You can now copy the Arduino code by using “ctrl A” then “ctrl C”. Then paste this into the
Arduino IDE. Click the arrow to upload the following sketch onto your board.
Turning the potentiometer will cause the servo arm to turn. The servo will mimic the movement
of the potentiometer, twisting in the same clockwise or counterclockwise
direction. If you’ve attached a servo mount to the arm as shown, this movement will be easier to
see.
Assignment: SERVO
Attach a servo mount to the arm so that you can observe the motion of the servo motor to
answer the following questions:
6
1. What did the servo do when you turned the potentiometer clockwise? Counter
clockwise?
3. What are some real life applications would incorporate a servo and a potentiometer?
CHALLENGE
4. Servos can be controlled using code to move at different degrees without the use of a
potentiometer. Copy and paste the following code to operate a servo without a pot.
○ Remove the potentiometer from your wiring. You will now code your arduino to
operate a servo using code (automation).
b. Change your code to make your servo rotate 170 degrees, wait for ½ a second
and rotate to 90 degrees, wait for 2 seconds and rotate back to 10 degrees.
Note: It's best to avoid driving the servo all the way to 0 or 180 degrees. It can cause
the motor to jitter, which is bad for the servo. So typically a range of 20-170 works best.
7
5. Code and wire two servos to work in succession. Have one servo turn to 90
degrees. Input a wait time so that another servo can turn to 120 degrees and
then back to 0 degrees. Then have the first servo return back to 0 degrees.
(“Dancing Servos:)”