How to control servo motor with Potentiometer








Materials:-
Diagram:-






Connections:-

Servo to arduino
  • Servo Yellow = Arduino D7
  • Servo Red = Arduino 5v
  • Servo Brown = Arduino GND
Potentiometer to arduino
  • Potentiometer Left = Arduino 5V
  • Potentiometer Right = Arduino GND
  • Potentiometer Center = Arduino A5
Downloads:-


#include <Servo.h>
Servo myservo;
int pot=A5;
int val;
void setup() {
  myservo.attach(7);

}

void loop() {
val=analogRead(pot);
val=map(val,0,1023,0,180);
myservo.write(val);
delay(25);

}