Its in the code...

Ive tested the relays OMR-C-105H... they work. But I cant for the life of me make the relays correspond to the mode. The LED indicator lights work fine but the relays (all of them) are always ON. Any ideas?

const int buttonPin = A3;    // pin to read button
const int mode1 = 2;       // relay 1
const int mode2 = 7;     // relay 2
const int mode3 = 8;       // relay 3\
const int L1 = 1;       // relay 1
const int L2 = 0;     // relay 2
const int L3 = 9;       // relay 3
const int SL = 3;       // relay for save/load button
int state = 1;           // Which relay is currently on.
 
void setup()
{
  Serial.begin(9600);
  const int L1 = 1;
  pinMode(buttonPin, INPUT);
  pinMode(mode1, OUTPUT);
  pinMode(mode2, OUTPUT);
  pinMode(mode3, OUTPUT);
  pinMode(L1, OUTPUT);
  pinMode(L2, OUTPUT);
  pinMode(L3, OUTPUT);
  pinMode(SL, OUTPUT);
  digitalWrite(mode1, HIGH);
  digitalWrite(SL, HIGH);
}
 
void loop()
{
  if( analogRead(buttonPin) ) {
   const int L1 = 1;
    // debounce
    delay(200);
    
    if (state == 1) {
      digitalWrite(mode3, LOW);
      state = 2;
       digitalWrite(L2, LOW);
      digitalWrite(L3, LOW);
       delay(200);
      digitalWrite(L1, HIGH);
      digitalWrite(mode1, HIGH);
       delay(200);
      digitalWrite(SL, HIGH);
      delay(50);
      digitalWrite(SL, LOW);
      delay(50);
      digitalWrite(SL, HIGH);
      delay(50);
      digitalWrite(SL, LOW);
      delay(50);
      digitalWrite(SL, HIGH);
    }
    else if (state == 2) {
      digitalWrite(mode1, LOW);
      state = 3;
      digitalWrite(L1, LOW);
       delay(200);
      digitalWrite(L2, HIGH);
      digitalWrite(mode2, HIGH);
       delay(200);
       digitalWrite(SL, HIGH);
      delay(50);
      digitalWrite(SL, LOW);
      delay(50);
      digitalWrite(SL, HIGH);
      delay(50);
      digitalWrite(SL, LOW);
      delay(50);
      digitalWrite(SL, HIGH);
    }
    else if (state == 3) {
      digitalWrite(mode2, LOW);
      state = 1;
      digitalWrite(L2, LOW);
       delay(200);
      digitalWrite(L3, HIGH);
      digitalWrite(mode3, HIGH);
       delay(200);
      digitalWrite(SL, HIGH);
      delay(50);
      digitalWrite(SL, LOW);
      delay(50);
      digitalWrite(SL, HIGH);
      delay(50);
      digitalWrite(SL, LOW);
      delay(50);
      digitalWrite(SL, HIGH);
    }
    
    while(digitalRead(buttonPin));  // wait until the button is released
    delay(200);      // debounce
  Serial.print(digitalRead(2));
  Serial.print("\t");  
  Serial.print(digitalRead(7));
  Serial.print("\t");  
  Serial.print(digitalRead(8));
  Serial.println("\t");  
  
}
}

If you connect the relays directly to the Arduino they might draw too much current..

You need separate powersupply (Connect GND's for a common voltage reference ) for the relays
use a transistor or optocoupler in between

I spot a digitalRead(buttonPin) and a analogRead( buttonPin) with the buttonPin = A3

Also with the analogread of a button , I'm not always sure if you get a clean 0 'false' for IF() evaluation.

Also take a peek at the switch-case http://arduino.cc/en/Reference/SwitchCase for your state structure, don't forget to catch unwanted/illogical states for code stability.

if you strip all the code and simply make a loop that switches the relays , does that work ?. e.g. does the hardware work?.

 if( analogRead(buttonPin) ) {
   const int L1 = 1;

Why keep rescoping a constant?

AWOL:

 if( analogRead(buttonPin) ) {

const int L1 = 1;


Why keep rescoping a constant?

Yep. Not sure what the OP is trying to do there. L1 is the pin number for one of the relays. Pin 1? The serial pin? I also notice that he/she is using pins 0 and 1 for the relays, but intializing the serial port with Serial.begin(9600);

This code is all kinds of screwed up. We have two groups here: MODEn and Ln. Both groups are configured as output. But at the end of the loop, the OP is trying ti digitalRead the Mode pins (2, 7, 8).

Finall, the reason your relays are always high is that you have probably connected your buttonpin with a pullup which is the proper way to connect a switch. But you are testing for it to be HIGH, which it always will be EXCEPT when you press it. So, your code is starting with state=1, then going through the states and ending up back at state=1. And since it always sees your pin as HIGH, the code just keep running forever regardless of your button presses.

I would recommend sitting down and writing up some psuedo-code for what you want to do and rewrite this. Use case statements instead of IF statements. Properly think out your pin assignments and whether they are inputs or outputs. Rethink that "debounce" code (which isn't actually doing anything here other than delaying... for deounce, you check the pin again after the delay and only register the HIGH or LOW if it is the same state after the delay.)