0% found this document useful (0 votes)
4 views4 pages

Lab 5 - EENG312

The document outlines a laboratory study for EENG312 focused on controlling servo motors using Arduino. Students will complete two lab exercises: one involving a servo motor sweep and another using buttons for directional control. Additionally, a homework assignment is given to design a turret that aims at detected movement using multiple sensors.

Uploaded by

Zeynep Bayram
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 views4 pages

Lab 5 - EENG312

The document outlines a laboratory study for EENG312 focused on controlling servo motors using Arduino. Students will complete two lab exercises: one involving a servo motor sweep and another using buttons for directional control. Additionally, a homework assignment is given to design a turret that aims at detected movement using multiple sensors.

Uploaded by

Zeynep Bayram
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/ 4

EENG312: Microcontroller Applications

Laboratory Study: Experiment 5


Servo Motor Control

Objective: The students will be introduced to motor control using servo motors. The
students learn about library usage via the servo library.

Lab Work - 1: Each group of students will edit and run the following Program in the IDE and
Tinkercad and debug to make it ready to be uploaded to Arduino Uno. The program controls
a servo motor, doing sweeps across its range of motion.
// C++ code
//using the servo library!
#include <Servo.h>
#define servo_pin 9

int pos = 0;

Servo servo_1;

void setup()
{
//defining the pin the servo will be attached to
servo_1.attach(servo_pin);
}

void loop()
{
// sweep the servo from 0 to 180 degrees in steps
// of 1 degrees
for (pos = 0; pos <= 180; pos += 1) {
// tell servo to go to position in variable 'pos'
servo_1.write(pos);
delay(15);
}
for (pos = 180; pos >= 0; pos -= 1) {
servo_1.write(pos);
delay(15);
}
}
Lab Work - 2: Each group of students will edit and run the following Program in the IDE and
Tinkercad and debug to make it ready to be uploaded to Arduino Uno. The program controls
a servo motor, whose arm can be rotated clockwise and anticlockwise using two buttons.

#include <Servo.h>
#define servo_pin 9
#define left_button 4
#define right_button 3

int pos = 90;

Servo servo_1;

void setup()
{
servo_1.attach(servo_pin);
servo_1.write(pos); // Start servo at midpoint
pinMode(left_button, INPUT);
pinMode(right_button, INPUT);
}
void loop()
{
while (digitalRead(left_button) == HIGH)
{

servo_1.write(--pos);
delay(15);

while (digitalRead(right_button) == HIGH)


{

servo_1.write(++pos);
delay(15);

}
}
HW 5. (Due Next Friday)
Write a program with the respective Tinkercad circuit design to control a turret that aims
toward movement. You will need to use multiple sensors. You could use PIR or Ultrasonic
distance sensors.
An example design would be:
 3 sensors for left, middle, and right sides.
 Servo arm points towards the direction of the detected movement.

You might also like