SHARE
TWEET

Adding a Potentiometer to the Servo Motor Circuit

jmyean Apr 21st, 2019 (edited) 75 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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top