problem with motor stopping?

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);
}
}

Not sure what could cause it. How is the solenoid powered and how is it actually controlled from the Arduino pin?

This line of code:

if (startButtonStatus == HIGH && stopButtonStatus == HIGH || runStatus == true)
{
runStatus = true;

Makes me wonder what actually happens. Did you print the values on the monitor to be sure?

A note, you only need to set the stepper enable to high once. Probably in setup, since you never set it low.

More debug Serial.print may show the bug.

Paul

if (startButtonStatus == HIGH && stopButtonStatus == HIGH || runStatus == true)
{
runStatus = true;

The above line is part of a latch circuit for the motor to continue running after the momentry Start switch is pushed.

The solenoid is a 24 volt soenoid controlled with a transistor TIP120,pin11 sends a signal to the base pin and turns the transistor on? could that have anything to do with it?

I got all the elements working seperately (start/stop, inductive sensor and solenoid) and then put tem all together in the script, all i can think of is that the code to tell the solenoid what to do is over-riding the script for the motor or somthing like that?

Paulie

Then debugging is what is needed.

Set a boolean to true after you turn the solenoid off.

Back in your stepper motor logic, begin to Serial.print() some of the values you are testing for, but only if your new boolean is true. That way you will avoid all the unnecessary stuff on the monitor.

Paul