Hey guys and gals,
Full disclaimer…code is NOT my thing. I’m a mechanic. Robots and computers are cool and fun but code…I don’t get it. I’m trying and I’ve read a lot here on the forum but I’m running out of time.
So I need help with wiring & code for a single axis stepper motor control using Arduino Uno and Big Easy Driver running a Mercury stepper motor.
The basic code is working, running the motor between two micro switches but I need to introduce a solenoid after the left switch is ‘tripped’. I found this circuit (link) and ordered the components >
[
My solenoid is 12V, 24W, 2.0A.
I think what I need to do is assign or define an output as LOW but I need for the solenoid to remain energized for 500 milliseconds while the motor begins its trip to the right limit switch.
In the code below, after the left limit switch is tripped, there’s a delay(1000); then I need to engage my solenoid for 500ms and at the same time, spin the motor to the right limit switch. Maybe all I really need to do is pull the output LOW after the delay and the motor will start?
Can someone help with the code? What pin should I use? Do I need to pull it LOW? Can you weigh in on the wiring schematic? Does it look good?
Thank you! - Rich
#define stepPin 2
#define dirPin 3
#define pinLimitswitchLeft 4 // these can be either left or right depending on motor wiring and dir pin.
#define pinLimitswitchRight 5 // these switches must be N.O. types
int stepDelay = 100; // this is the step delay in microseconds. Reduce this to speed up motor rotation and vice versa.
void setup()
{
pinMode (stepPin, OUTPUT);
pinMode (dirPin, OUTPUT);
pinMode (pinLimitswitchLeft, INPUT_PULLUP);
pinMode (pinLimitswitchRight, INPUT_PULLUP);
}
void loop()
{
digitalWrite(dirPin, HIGH); // set direction pin, the direction that the motor will rotate is dictated by it's wiring
while (digitalRead(pinLimitswitchLeft) == HIGH) // move motor until left limit switch is pressed.
{
stepMotor();
}
delay(1000);
digitalWrite(dirPin, LOW); // set direction pin, the direction that the motor will rotate is dictated by it's wiring
while (digitalRead(pinLimitswitchRight) == HIGH) // move motor until right limit switch is pressed.
{
stepMotor();
}
delay(500);
}
void stepMotor()
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(stepDelay);
digitalWrite(stepPin, LOW);
delayMicroseconds(stepDelay);
}
solenoid_driver.pdf (17 KB)](http://playground.arduino.cc/uploads/Learning/solenoid_driver.pdf)