Advertisement
microrobotics

DS3115-360

Apr 26th, 2023
2,770
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Below is an example using an Arduino board and the Servo library.
  3.  
  4. Before you start, make sure you have the following components:
  5.  
  6. Arduino board (e.g., Arduino Uno, Mega, or Nano)
  7. 360-degree servo motor with a torque rating of 15kg.cm
  8. Jumper wires
  9. Power supply (if needed, depending on the servo motor requirements)
  10. To control the servo motor, follow these steps:
  11.  
  12. Connect the servo motor to the Arduino board:
  13.  
  14. Connect the servo's signal pin (usually orange or yellow) to a PWM pin on the Arduino (e.g., pin 9)
  15. Connect the servo's power pin (usually red) to a 5V pin on the Arduino or an external power supply if needed
  16. Connect the servo's ground pin (usually black or brown) to one of the ground pins on the Arduino or the external power supply's ground
  17. Upload the following code to your Arduino board:
  18.  
  19. This example code will rotate the servo motor from 0 to 180 degrees and then back to 0 degrees in a continuous loop. You can modify the values in the for loops to control the servo's rotation range.
  20.  
  21. Please note that for continuous rotation servo motors, writing an angle of 90 degrees usually means stopping the motor, while writing angles greater or lower than 90 degrees will result in continuous rotation in one direction or the other. You can calibrate the values in the code based on the specific behavior of your servo motor.
  22. */
  23.  
  24. #include <Servo.h>
  25.  
  26. Servo myServo;  // create a servo object
  27.  
  28. int servoPin = 9;  // the pin that the servo's signal wire is connected to
  29. int angle = 0;     // variable to store the desired angle
  30.  
  31. void setup() {
  32.   myServo.attach(servoPin);  // attach the servo object to the servoPin
  33. }
  34.  
  35. void loop() {
  36.   // Rotate the servo motor from 0 to 180 degrees
  37.   for (angle = 0; angle <= 180; angle++) {
  38.     myServo.write(angle);
  39.     delay(15); // Wait 15ms for the servo to reach the desired angle
  40.   }
  41.  
  42.   // Rotate the servo motor from 180 to 0 degrees
  43.   for (angle = 180; angle >= 0; angle--) {
  44.     myServo.write(angle);
  45.     delay(15); // Wait 15ms for the servo to reach the desired angle
  46.   }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement