CCCPaste

"Stepper Trigger" rev_01

/********* Pleasedontcode.com **********

	Pleasedontcode thanks you for automatic code generation! Enjoy your code!

	- Terms and Conditions:
	You have a non-exclusive, revocable, worldwide, royalty-free license
	for personal and commercial use. Attribution is optional; modifications
	are allowed, but you're responsible for code maintenance. We're not
	liable for any loss or damage. For full terms,
	please visit pleasedontcode.com/termsandconditions.

	- Project: "Stepper Trigger"
	- Source Code compiled for: Arduino Nano
	- Source Code created on: 2024-01-28 19:35:49

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* Create an Arduino Nano code that controls a */
	/* 28BYJ-48 stepper motor using a digital sensor (pin */
	/* 4) and a hall sensor (analog 3). When the digital */
	/* sensor is pressed, the stepper motor should */
	/* continuously rotate until the hall sensor detects */
	/* a magnet. U */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include 
#include 

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t Steppermotor_PIN_D7 = 7;
const uint8_t Digitalsensor_PIN_D4 = 4;

/***** DEFINITION OF ANALOG INPUT PINS *****/
const uint8_t Halleffectsensor_PIN_A3 = A3;

// Define the number of steps per revolution for the stepper motor
const int stepsPerRevolution = 2048;

// Initialize the stepper motor object
Stepper myStepper(stepsPerRevolution, Steppermotor_PIN_D7, Steppermotor_PIN_D7);

void setup(void)
{
  // put your setup code here, to run once:
  pinMode(Digitalsensor_PIN_D4, INPUT);
  pinMode(Halleffectsensor_PIN_A3, INPUT);

  // Set the speed of the stepper motor
  myStepper.setSpeed(5);
}

void loop(void)
{
  // put your main code here, to run repeatedly:
  if (digitalRead(Digitalsensor_PIN_D4) == HIGH)
  {
    // Rotate the stepper motor continuously until the hall sensor detects a magnet
    while (analogRead(Halleffectsensor_PIN_A3) < 500)
    {
      myStepper.step(1);
    }
  }
}