Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
50 views1 page

Servo Motor W/ Potentiometer

The document contains code snippets for controlling a servo motor using Arduino. It includes examples for sweeping the servo from 0 to 180 degrees, responding to a switch input, and using a potentiometer to set the servo position. Each example demonstrates different functionalities and setups for servo motor control.
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)
50 views1 page

Servo Motor W/ Potentiometer

The document contains code snippets for controlling a servo motor using Arduino. It includes examples for sweeping the servo from 0 to 180 degrees, responding to a switch input, and using a potentiometer to set the servo position. Each example demonstrates different functionalities and setups for servo motor control.
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/ 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