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