3 switch 3 relay control

I am new to all this and this is the first program I have tried on my own

Ok i am driving a high current motor with relays when the unit boots I need it to be in the home position when the start switch is pressed the motor runs (by turning the enable relay c on) right until it hits the right limit switch. Then the motor enable relay turns off while the control relays flip reversing the motor
then turns the enable relay back on until it hits the left/home limit switch where it stops until the start button is pressed any help is appreciated i have attached my complete sketch
I am using 3 micro switches and a relay shield and Arduino duo
My problem is that it loads and it boots but when it boots the enable relay is on and nothing happens when any of the the switches are pressed.
Thanks John

sketch_project04.ino (1.94 KB)

You didn't say what's working and what's not working... Does the motor run at all? Can you reverse it?

Take it one step at a time (that's how all software is developed).

For example, just make the motor start when you push the button.

When you get that working, try to make the motor stop (or reverse) when you hit the "far limit".

Etc., 'till you're done.

...As far as I can tell, I don't think you need to know the previous switch states. You need to start when you hit the start switch, then you can ignore that switch for awhile. And, you need to know when the limit switches are "tripped".

...I also think you need more loops. Probably [u]while() loops[/u].

For example, start-out with a "do-nothing" while() loop that just sits there looping while the start switch is not pressed. When you press the start button break-out of the loop and start the motor going forward.

Enter another while() loop and let the motor run while limit switch is not activated, etc.

Please edit your post to embed your sketch in code tags. Also post a schematic so we can see what relay A, relay B and so on, actually do. It would even be great if you could name the relay variables for what they actually do, for example directionRelay...

You are checking rightSwitchState twice and never checking leftSwitchState

Thanks for your recommendations I think I will start with just the one switch and work my way up I will also draw out a schematic and post and redefine the relays . All great tips.
Thanks Again John

Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile: