Advertisement
microrobotics

Arduino sample Code for 360 Degree Servo

Sep 21st, 2024
540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Servo.h>
  2.  
  3. Servo myServo;
  4.  
  5. void setup() {
  6.   myServo.attach(9);  // Attach the servo to pin 9
  7. }
  8.  
  9. void loop() {
  10.   // Turn left
  11.   myServo.write(0);  // 0 = full speed counterclockwise
  12.   delay(3000);       // Rotate for 3 seconds
  13.  
  14.   // Stop
  15.   myServo.write(90); // 90 = stop
  16.   delay(1000);       // Wait for 1 second
  17.  
  18.   // Turn right
  19.   myServo.write(180); // 180 = full speed clockwise
  20.   delay(3000);        // Rotate for 3 seconds
  21.  
  22.   // Stop
  23.   myServo.write(90);  // Stop again
  24.   delay(1000);        // Wait for 1 second
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement