Pot and Servo

Rotates the servo motor to match the rotation on the potentiometer

Hardware used:
  • Potentiometer
  • Servo
Code Used:
  • analogRead
  • Library Import
  • Servo Object
  • Map function

#include <Servo.h>

/* Rotary encoder read example */
#define SERVO 5
#define POT 2

Servo myservo; // create servo object to control a servo

void setup()
{
   myservo.attach(SERVO, 1000, 2000);
}

void loop()
{
   myservo.write(map( analogRead(POT), 0, 1023, 0, 179));
   // sets the servo position according to the scaled value
   delay(10);
}
									

Leave a Reply

Your email is never published nor shared.

You may use these HTML tags and attributes:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>