Advertisement
pleasedontcode

"Stepper Trigger" rev_01

Jan 28th, 2024
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Stepper Trigger"
  13.     - Source Code compiled for: Arduino Nano
  14.     - Source Code created on: 2024-01-28 19:35:49
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Create an Arduino Nano code that controls a */
  21.     /* 28BYJ-48 stepper motor using a digital sensor (pin */
  22.     /* 4) and a hall sensor (analog 3). When the digital */
  23.     /* sensor is pressed, the stepper motor should */
  24.     /* continuously rotate until the hall sensor detects */
  25.     /* a magnet. U */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <Arduino.h>
  30. #include <Stepper.h>
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35.  
  36. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  37. const uint8_t Steppermotor_PIN_D7 = 7;
  38. const uint8_t Digitalsensor_PIN_D4 = 4;
  39.  
  40. /***** DEFINITION OF ANALOG INPUT PINS *****/
  41. const uint8_t Halleffectsensor_PIN_A3 = A3;
  42.  
  43. // Define the number of steps per revolution for the stepper motor
  44. const int stepsPerRevolution = 2048;
  45.  
  46. // Initialize the stepper motor object
  47. Stepper myStepper(stepsPerRevolution, Steppermotor_PIN_D7, Steppermotor_PIN_D7);
  48.  
  49. void setup(void)
  50. {
  51.   // put your setup code here, to run once:
  52.   pinMode(Digitalsensor_PIN_D4, INPUT);
  53.   pinMode(Halleffectsensor_PIN_A3, INPUT);
  54.  
  55.   // Set the speed of the stepper motor
  56.   myStepper.setSpeed(5);
  57. }
  58.  
  59. void loop(void)
  60. {
  61.   // put your main code here, to run repeatedly:
  62.   if (digitalRead(Digitalsensor_PIN_D4) == HIGH)
  63.   {
  64.     // Rotate the stepper motor continuously until the hall sensor detects a magnet
  65.     while (analogRead(Halleffectsensor_PIN_A3) < 500)
  66.     {
  67.       myStepper.step(1);
  68.     }
  69.   }
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement