I am working on a class project that is a rotating wheel like a Ferris wheel, instead of chairs it has dixie cups. There are a total of 12 positions. Here are the logical steps.
Rotate wheel 30 degrees and stop.
Turn on Solid State Relay ,which is attached to a small pump, the pump stays on for 2 seconds adds some water.
Wait 5 seconds for drips to stop.
Rotate to next position and repeat above.
Do this for all 12 positions.
After all cups have water.
Rotate wheel 360 for X number of times.
Start fill sequence again.
I am new to the Arduino platform and have been running into some issues with the stepper motor being able to start and stop. I am using the AccelStepper with the following hardware.
Arduino Uno
Spark Fun Solid State Relay Kit (KIT-10684)
Spark Fun Stepper Motor - 125 oz.in (200 steps/rev) (ROB-10847)
Big Easy Driver (ROB-10735)
I have everything together and working. I can't seem to figure out the code to get the pause to happen for 5 seconds between when the pump turns off and the motor indexes to next position or how to get the second phase to integrated. I have provided the code I am using below. Can one of you pro's take a look and make some suggestions? It seems pretty straight forward.
Thanks in advance for any help or suggestions.
#include <AccelStepper.h>
#define relayPin 2 //Output Pin for the SSR
#define dirPin 9 //Direction Output on pin 8
#define stepPin 8 //Step Output on pin 9
#define relayOn 8000 //Amount of time the SSR stays on
#define relayOff 4000 //Amount of time the SSR stays off
#define maxSpeed 4000
#define shaftSpeed 4000
const int steps = 200;
AccelStepper stepper(1, dirPin, stepPin);
int Distance;
unsigned long ms; //time from millis()
unsigned long msLast; //last time the relay changed state
boolean relayState; //current state of relay on or off
void setup()
{
Serial.begin(9600);
stepper.setMaxSpeed(maxSpeed);
stepper.setSpeed(shaftSpeed);
relayState = 0;
}
void loop()
{
ms = millis();
changeRelayState();
if (relayState == 0)
{
stepper.runSpeed();
}
else
{
digitalWrite(dirPin, LOW);
digitalWrite(stepPin, LOW);
}
}
void changeRelayState()
{
if (ms - msLast > (relayState ? relayOn : relayOff))
{
digitalWrite(relayPin, relayState = !relayState);
msLast = ms;
}
}
Hi Nick. All I did was substitute your recommended code change into my changeRelayState and the relay wouldn't come on afterwards. I put original code back and it comes on. As you are probably aware I am new to all this. So please go easy on me.
What Nick is asking is that you post (in it's entireity) the latest sketch that you're having problems with. It's too hard to help if we're guessing what you changed.
The comments on the #define statements indicate that relayOn and relayOff are times, not states. So, comparing relayState to relayOn or relayOff doesn't make a lot of sense.