You are on page 1of 1

Servo Motor

#include<Servo.h>
Servo servo 1 ;
Int pos = 0;

Void setup(){
Servo 1. Attach (4);
}

Void loop()
{
For (pos = 0; pos,= 180; pos++)
{
Servo 1. Write (pos);
Delay (15);
}
For (pos=180; pos>= 0; pos--)
{
Servo1. Write (pos);
Delay(15);
}
}

Servo motor switches *lcd tilt swtches

#include <Servo.h>Servo myservo; int inPin = 2;int reading; void setup() { myservo.attach(9);
pinMode(inPin, INPUT); Serial.begin(9600); } void loop() { reading = digitalRead(inPin); if
(reading == HIGH){ myservo.write(90); delay (150); } else { myservo.write(0); delay (150); } }

Servo motor w/ potentiometer

#include <Servo.h> Servo myservo; // create servo object to control a servo int potpin = A0; //
analog pin used to connect the potentiometer int val; // variable to read the value from the
analog pin void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object }
void loop() { val = analogRead(potpin); // reads the value of the potentiometer (value between
0 and 1023) val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value)

You might also like