Hi dudes,
I have a stepper motor hooked up to an inductive sensor, the motor is turning a flywheel that has steel and non steel items in it, what is supposed to happen is the sensor picks up steel and after a delay a solenoid triggers and puts the steel seperate from the rest, now the problem I have is when my sensor picks up any steel the motor turns off while the solenoid does its thing but the steel will still be infront of the sensor all the time now because the sensor kills the motor when it detects steel?
Any reason anyone can think of for doing this? i cant see anything in the code (attached) to stop the motor? Could it be where the sensor code is placed in the sketch?
Any help is appreciated!
Cheers,
Paulie
Code below:
int pulsePin = 7;
int directionPin = 6;
int enablePin = 5;
int startButtonPin = 2;
int stopButtonPin = 3;
int solenoidPin = 11;
int sensor = 12;
int sensorVal;
boolean startButtonStatus = HIGH;
boolean stopButtonStatus = HIGH;
boolean runStatus = false;
bool pulseRunning = false;
void setup(){
pinMode(pulsePin,OUTPUT);
pinMode(directionPin,OUTPUT);
pinMode(enablePin,OUTPUT);
pinMode(startButtonPin,INPUT_PULLUP);
pinMode(stopButtonPin,INPUT_PULLUP);
pinMode(sensor, INPUT_PULLUP);
pinMode(solenoidPin, OUTPUT);
}
void loop(){
startButtonStatus = digitalRead(startButtonPin);
stopButtonStatus = digitalRead(stopButtonPin);
if (startButtonStatus == HIGH && stopButtonStatus == HIGH || runStatus == true)
{
runStatus = true;
for (int i = 0; i < 400; i++)
pulseRunning = ! pulseRunning;
digitalWrite(pulsePin, pulseRunning);
digitalWrite(directionPin, LOW);
digitalWrite(enablePin,HIGH);
digitalWrite(pulsePin, HIGH);
delayMicroseconds(50);
}
if (startButtonStatus == LOW && stopButtonStatus == LOW)
{
runStatus = false;
digitalWrite(directionPin, LOW);
digitalWrite(enablePin, HIGH);
digitalWrite(pulsePin, LOW);
delayMicroseconds(50);
}
sensorVal = digitalRead(sensor );
if (sensorVal == HIGH) {
//delay(1000);
digitalWrite(solenoidPin, HIGH);
delay(1000);
digitalWrite(solenoidPin,LOW);
}
else { //sensorVal = LOW
digitalWrite(solenoidPin, LOW);
}
}