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");
}
}