safwan092

Untitled

Dec 19th, 2020
97
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Example sketch to control a 28BYJ-48 stepper motor with ULN2003 driver board and Arduino UNO. More info: https://www.makerguides.com */
  2.  
  3. // Include the Arduino Stepper.h library:
  4. #include <Stepper.h>
  5.  
  6. // Define number of steps per rotation:
  7. const int stepsPerRevolution = 2048;
  8.  
  9. // Wiring:
  10. // Pin 8 to IN1 on the ULN2003 driver
  11. // Pin 9 to IN2 on the ULN2003 driver
  12. // Pin 10 to IN3 on the ULN2003 driver
  13. // Pin 11 to IN4 on the ULN2003 driver
  14.  
  15. // Create stepper object called 'myStepper', note the pin order:
  16. Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);
  17.  
  18. void setup() {
  19. // Set the speed to 5 rpm:
  20. myStepper.setSpeed(5);
  21.  
  22. // Begin Serial communication at a baud rate of 9600:
  23. Serial.begin(9600);
  24. }
  25.  
  26. void loop() {
  27. // Step one revolution in one direction:
  28. Serial.println("clockwise");
  29. myStepper.step(stepsPerRevolution);
  30. delay(500);
  31.  
  32. // Step one revolution in the other direction:
  33. Serial.println("counterclockwise");
  34. myStepper.step(-stepsPerRevolution);
  35. delay(500);
  36. }
RAW Paste Data