Advertisement
jmyean

Adding a Potentiometer to the Servo Motor Circuit

Apr 21st, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. /* Jung Min Yean
  3.  *  Using the Servo Motor
  4.  *  Using the for loop
  5.  *  04/18/19
  6.  */
  7.  
  8. #include <Servo.h> // the servo library (every time this is included, you must add an object
  9.  const int servoPin = 3;
  10.  Servo myservito;
  11.  const int PotPin = A0;
  12.  int PotVal = 0;
  13.  int angle = 0;
  14.  
  15.  void setup()
  16. {
  17.   myservito.attach(servoPin);
  18.   pinMode(PotPin, INPUT);
  19. }
  20.  
  21. void loop()
  22. {
  23.   PotVal = analogRead(PotPin);
  24.   angle = map(PotVal,0,1023,0,179);
  25.   myservito.write(angle);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement