help with code

I am new to Arduino. I have an UNO that I want to use for a project. I want to use a push button as an INPUT to initiate a loop to run an 8-channel relay sequence just once. Please help with writing the code to run this sequence. The help will be sincerely appreciated.

My setup right now is:
I have a prototype shield on the UNO. I have 5v from the UNO shield to one side of the switch. The other end of the switch going to digital I/O pin 1 of the shield. The relay has 10 pins. 1 pin is VCC which is connected to another 5v pin on the shield. 1 pin of the relay is ground which I have connected to a ground pin on the shield. The 8 IN(IN1-IN8) pins of the relay are connected to digital I/O pins 2-9. If I need to make changes to this setup please let me know.

The relay model is: HL-58S V1.2

Please help with writing the code to run this sequence. The help will be sincerely appreciated.

We are here to help, not write your code.
What have you written so far.

int switchstate = 0;

void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT); // outputs for each relay

pinMode(1, INPUT); //declare switch pin as input

}

void loop() {
switchstate = digitalRead(1); //read the value of the switch
if(switchstate == LOW) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
}
// if the switch is not LOW(button is pressed)
// the code below will run
else {
digitalWrite(2, HIGH);
delay(500);
digitalWrite(2, LOW);
delay(50);
digitalWrite(3, HIGH);
delay(500);
digitalWrite(3, LOW);
delay(50);
digitalWrite(4, HIGH);
delay(500);
digitalWrite(4, LOW);
delay(50);
digitalWrite(5, HIGH);
delay(500);
digitalWrite(5, LOW);
delay(50);
digitalWrite(6, HIGH);
delay(500);
digitalWrite(6, LOW);
delay(50);
digitalWrite(7, HIGH);
delay(500);
digitalWrite(7, LOW);
delay(50);
digitalWrite(8, HIGH);
delay(500);
digitalWrite(8, LOW);
delay(50);
digitalWrite(9, HIGH);
delay(500);
digitalWrite(9, LOW);

}

Get that switch off digital pin 1 as it is used by the Serial interface which you will almost certainly need to output to the Serial monitor for debugging.

Wire one side of the switch to a digital pin and the other side to GND so that the pin is taken LOW when the switch is closed. Use

pinMode(switchPin, INPUT_PULLUP);

so that the input is at a known state at all times.

Forget the relays for now and use the switch to turn the LED on pin 13 on and off. Look at the Button example in the IDE to see how to do it. Once that works substitute a single relay for the LED and get that working.

What sequence of relay outputs do you want, both the order of operation and the timing.

The order of operation for the relay is not really that important, as long as I know which relay goes on first and next and so on. The timing will have to be tweaked in the code later while I am building the project to ensure proper sequence timing. The relays will be used to turn different servos that have different functions in the project. Thanks for the help.

I want to use a push button as an INPUT to initiate a loop to run an 8-channel relay sequence just once.

By just once ,what do you mean?

It's nice to always see a schematic as some of us old guys are visual.

Also rather than saying I have this part, give us a link to a PDF so we don't have to search for it.

By "just once" I mean, that when the button is pressed, the loop will run and open and close each relay in turn and then stop, not running the loop a second time. But, be able to push the button again to do the same thing as many times as the button is pressed. I believe I need to put and "stop" in the loop in order for the loop to not run again. Not sure how to write that though. Can you help with that?

The order of operation for the relay is not really that important

It will be for the better solutions using a for loop and an array of relay pins and timing periods to replace the clumsy serial code that you have now. For instance will 2 relays ever be on at the same time and will any relays turn on more than once in the sequence ?

I believe I need to put and "stop" in the loop in order for the loop to not run again. Not sure how to write that though.

No need for a stop command. Detect the change of pin state from off to on instead of just detecting that it is on. Look at the StateChangeDetection example in the IDE.

You are right. A relay will have to be run a second time in the sequence but also change direction of the servo. Man, I am way out of my league here but I am determined to do this project. And I really don't understand alot of the terminology in the replies that I am getting. Can anyone recommend a book on Arduino and/or electronics to help me understand?

Good for you that you realize you need to learn the basics.
Also, try to go through the examples which come with the IDE.

What type of servos are involved in this project ?

Draw up timelines showing which actions happen and in what order. Put time on the X axis and each thing to be controlled on the Y axis. This will help clarify your requirements and help to suggest solutions. Will it ever be a requirement to terminate the sequence early or maybe halt it and continue ? This could affect the approach taken in programming the solution.

Ok. Yes, one part of the sequence will be halted by a sensor. Once the sensor makes the connection the sequence will continue. I can share the details of the project if you want them. I have a really good idea of the project and the sequence of steps. And a general idea of the parts I will need to buy or fabricate. The finished project will be a voice activated mini-fridge that dispenses a bottle of beer with the cap removed through the top of the fridge.

Thank you LarryD for the link to the book.

As for the type of servos: I don't really know what is available or really how to select the proper one for each piece of work being done in the project. I do know that I will need a few continuous rotation bi-directional servos for a few of the parts.

The reason that I asked about the type of servos is that using a relay to drive a servo seems perverse, and actually quite difficult, when the Arduino can control them directly. Please note that an external power supply other than the Arduino will be necessary.