I have very primitive knowledge of Arduino coding and I am looking to write a program to control the automation of a telescopic mast for amateur radio with an Uno board and six relays. The set up includes a winch, two electric actuators and four limit switches. I am looking for help to at the least provide the rough framework, then I can go in and tweak the pins and time delays as needed. The basic premise is that I need a sequence of events to occur after pressing a button (mast up), then a another sequence of events to occur after pressing a second button (mast down). I just have no idea if this can be done with just if statements or maybe something like a switch-case might be needed. Below are the inputs/outputs along with the sequence of events that I need to happen. Any help would be greatly appreciated!
Thank you!
Pin for Switch One---- Mast UP switch
Pin for Switch Two---- Mast Down switch
Pin for Limit Switch One ----Tilt Up limit switch
Pin for Limit Switch Two----Vertical Up limit switch
Pin for Limit Switch Three---- Vertical Down limit switch
Pin for Limit Switch Four----Tilt Down limit switch
Pin for Relay One----Motor Up
Pin for Relay Two----Motor Down
Pin for Relay Three----Cable clamp on actuator
Pin for Relay Four----Cable clamp Off actuator
Pin for Relay Five----Base Lock actuator
Pin for Relay Six----Base Unlock actuator
Sequence #1
Nothing happens and nothing on until:
Switch One triggered (HIGH)
o Relay one turns on (HIGH) until: limit switch one is triggered (HIGH)
o Then: Relay Five turns on (HIGH) for 8 seconds, then turns off (LOW)
o Then: Relay Four Turns on (HIGH) for 8 seconds, then turns off (LOW)
o Then: relay one turns on (HIGH) until: Limit Switch Two is triggered
(HIGH)
o Then: Relay Three turns on (HIGH) for 8 seconds, then turns off (LOW)
Nothing else should happen (Switch one is still triggered (HIGH))
Sequence #2
Switch One turned off (LOW) (nothing should happen)
Switch Two is triggered (HIGH)
o Relay Four turns on (HIGH) for 8 seconds, then turns off (LOW)
o Then: Relay Two turns on (HIGH) until: Limit Switch Three is triggered
(HIGH)
o Then: Relay Three turns on (HIGH) for 8 seconds, then turns off (LOW)
o Then: Relay Six turns on (HIGH) for 8 seconds, then turns off (LOW)
o Then: Relay Two turns on (HIGH) until: Limit Switch Four is triggered
(HIGH)
Nothing else should happen (Switch one can go to (LOW) with no action
Here's a simple, brain-dead implementation of that. The problems will arise once you start using it and see that stuff needs to change
Assuming everything is setup properly:
// Switch One triggered (HIGH)
while (digitalRead(SW_1) != HIGH);
// Relay one turns on (HIGH) until: limit switch one is triggered (HIGH)
digitalWrite(RLY_1, HIGH);
while (digitalRead(LIMIT1) != HIGH);
// Then: Relay Five turns on (HIGH) for 8 seconds, then turns off (LOW)
digitalWrite(RLY_5, HIGH);
delay(8000);
digitalWrite(RLY_5, LOW);
// Then: Relay Four Turns on (HIGH) for 8 seconds, then turns off (LOW)
digitalWrite(RLY_4, HIGH);
delay(8000);
digitalWrite(RLY_4, LOW);
// Then: relay one turns on (HIGH) until: Limit Switch Two is triggered (HIGH)
digitalWrite(RLY_1, HIGH);
while(digitalRead(LIMIT2) != HIGH);
// Then: Relay Three Turns on (HIGH) for 8 seconds, then turns off (LOW)
digitalWrite(RLY_3, HIGH);
delay(8000);
digitalWrite(RLY_3, LOW);
// Nothing else should happen (Switch one is still triggered (HIGH))
while (digitalRead(SW_1) == HIGH);
Um, maybe I am missing something, but what are all the delays for. The limit switches need to be checked 'frequently' as in every pass thru the main loop with NO delays.
Thank you to everyone who posted suggestions and help!
I'm working on a schematic of my wiring and hope to post that shortly. In the meantime I've included my rough drawing of the setup.
From the comments, it sounds like I need a state machine, but with my limited knowledge I'm struggling to understand how I get that to work. I'll be doing more reading to hopefully figure it out on my own, but any more tips would be greatly appreciated! Mast Drawing.pdf (332.4 KB)
To those that emailed me that i put this in the wrong section of "jobs and paid consultancy". If I cant fugure this out on my own, yes, im willing to pay someone to help me or do it for me, because i ultimately have a deadline. Problem is im already over budget by $2k.. and this is a personal project. Hence I'll take any advice and/or i am looking for someone who knows what they're doing and willing to make $50 to help someone whos trying to learn but cant dedicate the time to do so right now. Thanks again to everyone who has added valuable input!