0% found this document useful (0 votes)
63 views2 pages

Practical 34: Aim: Demonstrate Servo Motor Sensor Using Arduino Code. Requirements

This document describes an experiment using an Arduino UNO to control the movement of a servo motor between 0 and 180 degrees using code. The code uses a for loop to rotate the servo from 0 to 180 degrees, then back from 180 to 0 degrees over periods of 1 second, demonstrating the use of the servo motor sensor.

Uploaded by

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

Practical 34: Aim: Demonstrate Servo Motor Sensor Using Arduino Code. Requirements

This document describes an experiment using an Arduino UNO to control the movement of a servo motor between 0 and 180 degrees using code. The code uses a for loop to rotate the servo from 0 to 180 degrees, then back from 180 to 0 degrees over periods of 1 second, demonstrating the use of the servo motor sensor.

Uploaded by

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

Practical 34

Aim: Demonstrate Servo Motor sensor using arduino code.

Requirements:

 Servo Motor
 Arduino UNO
 Jumper cables
 Computer or laptop
 USB Cable

Code:

#include <Servo.h> //Servo library

Servo servo_test; //initialize a servo object for the connected servo

int angle = 0;

void setup()
{
servo_test.attach(9); // attach the signal pin of servo to pin9 of arduino
}

void loop()
{
for(angle = 0; angle < 180; angle += 1) // command to move from 0 degrees to 180
degrees
{
servo_test.write(angle); //command to rotate the servo to the specified angle
delay(15);
}

delay(1000);

for(angle = 180; angle>=1; angle-=5) // command to move from 180 degrees to 0


degrees
{
servo_test.write(angle); //command to rotate the servo to the specified angle
delay(5);
}

delay(1000);
}

Output:

You might also like