Stepper Motor Interrupting Hall effect sensor

I have a hall effect sensor and a stepper motor hooked up to my arduino. Each works fine on their own, but when I try to run code with both of them in action the hall effect sensor dosent work. This is my code.

#include <Stepper.h>

const float STEPS_PER_REV = 32;

const float GEAR_RED = 64;

const float STEPS_PER_OUT_REV = STEPS_PER_REV * GEAR_RED;

int StepsRequired;

Stepper steppermotor(STEPS_PER_REV, 8, 10, 9, 11);

const int LedPin = 7;
const int SensorPin = 2;
int SensorValue = 0;

void setup()
{
Serial.begin(9600);
pinMode (SensorPin,INPUT);
pinMode (LedPin,OUTPUT);

}

void loop()
{

SensorValue=digitalRead(SensorPin);

Serial.println(SensorValue);
digitalWrite(LedPin,HIGH);

if(SensorValue==HIGH) {
digitalWrite(LedPin,HIGH); }
else {
digitalWrite(LedPin,LOW);
}

StepsRequired = -800 ;

steppermotor.setSpeed(100);
steppermotor.step(StepsRequired);

}

When I delete the stepper bit from the loop the hall sensor works fine, but when the motor code is in the loop the motor spins but the hall stops working. I think that it must be something with the timing of the code. But i cannot seem to figure out what.

Any help on this would be greatly appreciated

Thank you

Rory

You should use AccelStepper library, it can be used asychronous and non-blocking. Stepper.h is blocking
so no other code can run while your motor is moving. AccelStepper also ramps the speed which is usually
required for motors to avoid miss-steps.

Great ! I will try that now. Thank you very much :slight_smile: