Lab 8: Servo Motors

Yuetian Wang
2 min readOct 26, 2021

--

Yuetian Wang. Professor Kimiko Ryokai. Tangbile User Interface. Fall 2021.

Description

In this lab, I try to use a servo motor to make a crawler that can move forward. I cutted a chopstick into 4 sections. Two sections worked as the arms and two sections functioned as the legs. The “legs” played the role of moving, the “arms” played the role of supporting body. However, after I run the code and let the servo moter move, only the “legs” can move the servo moter forward, the “arms” failed to support the body.

In terms of the movement rhythm, I adjusted the code posted on bcourse to make the servo motor sweep back and forth repeatedly and adjusted its velocity through potentiometer. During my experiment, I found that only the servo motor reaches the certain speed, it can sweep. If the speed is too slow, the servo motor can only move, but cannot sweep.

Picture

Code

#include <Servo.h>

int servoPin = 7; // pin for the servo motor
int potpin = 0;
int val;

Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position

void setup() {
myservo.attach(servoPin); // attaches the servo on pin servoPin to the servo object
}

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’
val = analogRead(potpin);
delay(val); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable ‘pos’
val = analogRead(potpin);
delay(val); // waits 15ms for the servo to reach the position
}
}

Video

Components

1-Arduino

1-Breadboard

1-Servo Motor

1-Potentiometer

4- Chopsticks

1- Double-sided tape

--

--