miklik

Arduino servo 0-90-180

Sep 29th, 2025 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | Source Code | 0 0
  1. #include <Servo.h>
  2.  
  3. Servo myservo;  // create Servo object to control a servo
  4.  
  5.  
  6. void setup() {
  7.   myservo.attach(2);                  // attaches the servo on pin 2 to the Servo object
  8.   myservo.write(90);                  // sets the servo position to midle 90
  9. }
  10.  
  11. void loop() {
  12.   myservo.write(0);                  // sets the servo position 0
  13.   delay(1000);                       // waits 1s
  14.   myservo.write(90);                 // sets the servo position 90
  15.   delay(1000);                       // waits 1s
  16.   myservo.write(180);                // sets the servo position 180
  17.   delay(1000);                       // waits 1s
  18. }
  19.  
Advertisement
Add Comment
Please, Sign In to add comment