You are on page 1of 6

KYAMBOGO UNIVERSITY

FACULTY OF ENGINEERING
DEPARTMENT OF ELECTRICAL AND ELECTRONICS
ENGINEERING
TEEE 3016P MICROCONTROLLERS AND APPLICATIONS
LAB 1: ARDUINO DIGITAL INPUT & OUTPUT

GROUP MEMBERS
NAME REG NO
MANAGER HAMIM BRAN 17/U/252/ETD/GV
ANDEBO HILLARY 17/U/246/ETD/GV
AYIKOBUA GILBERT 17/U/247/ETD/GV
LAB 3. INTRODUCTION TO LIBRARIES
Part 1:

Source Code
//ANDEBO HILLARY 17/U/246/ETD/GV
//AYIKOBUA GILBERT 17/U/247/ETD/GV
//MANAGER HAMIM BRAN 17/U/252/ETD/GV
#include <Servo.h>
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(9); // attaches the servo on pin 9 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'
delay(15); // 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'
delay(15); // waits 15ms for the servo to
reach the position
}
}
Observation
The servo motor rotates from 00 to 1800 in steps of 10 and after an elpase of 15ms it rotates back
from 1800 to 00 in steps of 10
Part 2:

Source Code
//ANDEBO HILLARY 17/U/246/ETD/GV
//AYIKOBUA GILBERT 17/U/247/ETD/GV
//MANAGER HAMIM BRAN 17/U/252/ETD/GV
#include <Servo.h>
Servo myservo1; // create servo object to control a servo
// twelve servo objects can be created on most boards
Servo myservo2;
int push_button = 8;

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


void setup() {
pinMode(push_button,INPUT);
myservo1.attach(9); // attaches the servo on pin 9 to the servo
object
myservo2.attach(7); }
void loop() {
if( digitalRead(push_button)==HIGH){
for (pos1 = 0; pos1 <= 180; pos1 += 1) { // goes from 0 degrees to
180 degrees
// in steps of 1 degree
myservo1.write(pos1);
myservo2.write(180-pos1);// tell servo to go to position in
variable 'pos'
delay(15); // waits 15ms for the servo to
reach the position
}
for (pos1 = 180; pos1 >= 0; pos1 -= 1) { // goes from 180 degrees to
0 degrees
myservo1.write(pos1);
myservo2.write(180-pos1);// tell servo to go to position in
variable 'pos'
delay(15); // waits 15ms for the servo to
reach the position
}}}
Observations
The servo motors 1 and 2 rotate in opposite directions in such a way that when 1 starts from 1800
to 00 in steps of 10 , 2 starts from 00 to 1800 in steps of 10 and the rotations occur after an elapse
of 15ms.

You might also like