Help With Multiple Switches

I am trying to use the Arduino to control multiple relays based on multiple inputs. For instance, turning on one switch turns on two relays, etc. I based the code off of a push button code I came across, but I'm not having any luck. Can anyone give me any suggestions or some help. Thanks!!

Here's what I have so far:

// set pin numbers: const int leftbuttonPin = 11; const int leftbackwardPin = 2; const int rightforwardPin = 1; const int rightbuttonPin = 10; const int leftforwardPin = 4; const int rightbackwardPin = 3; const int surfacebuttonPin = 13; const int balupPin = 5; const int divebuttonPin = 12; const int baldownPin = 6; const int forwardbuttonPin = 9; const int backwardbuttonPin = 8; const int lightbuttonPin = 7; const int lightonPin = 0;

// variables will change: int leftbuttonState = 0; int rightbuttonState = 0; int surfacebuttonState = 0; int divebuttonState = 0; int forwardbuttonState = 0; int backwardbuttonState = 0; int lightbuttonState = 0;

void setup() { pinMode(leftbuttonPin,INPUT); pinMode(rightbuttonPin,INPUT); pinMode(forwardbuttonPin,INPUT); pinMode(backwardbuttonPin,INPUT); pinMode(surfacebuttonPin,INPUT); pinMode(divebuttonPin,INPUT); pinMode(leftbackwardPin,OUTPUT); pinMode(rightforwardPin,OUTPUT); pinMode(leftforwardPin,OUTPUT); pinMode(rightbackwardPin,OUTPUT); pinMode(balupPin,OUTPUT); pinMode(baldownPin,OUTPUT); pinMode(lightbuttonPin,INPUT); pinMode(lightonPin,OUTPUT); }

void loop() {

leftbuttonState = digitalRead(leftbuttonPin); rightbuttonState = digitalRead(rightbuttonPin); surfacebuttonState = digitalRead(surfacebuttonPin); divebuttonState = digitalRead(divebuttonPin); forwardbuttonState = digitalRead(forwardbuttonPin); backwardbuttonState = digitalRead(backwardbuttonPin); lightbuttonState = digitalRead(lightbuttonPin);

if (leftbuttonState == HIGH) { digitalWrite(leftbackwardPin, HIGH); digitalWrite(rightforwardPin, HIGH); } else{if (rightbuttonState == HIGH) { digitalWrite(leftforwardPin, HIGH); digitalWrite(rightbackwardPin, HIGH); } else{if (surfacebuttonState == HIGH) { digitalWrite(balupPin, HIGH); } else{if (divebuttonState == HIGH) { digitalWrite(baldownPin, HIGH); } else{if (forwardbuttonState == HIGH) { digitalWrite(leftforwardPin, HIGH); digitalWrite(rightforwardPin, HIGH); } else{if (backwardbuttonState == HIGH) { digitalWrite(leftbackwardPin, HIGH); digitalWrite(rightbackwardPin, HIGH); } else{if (lightbuttonState == HIGH) { digitalWrite(lightonPin, HIGH); } else{ digitalWrite(leftforwardPin, LOW); digitalWrite(leftbackwardPin, LOW); digitalWrite(rightforwardPin, LOW); digitalWrite(rightbackwardPin, LOW); digitalWrite(balupPin, LOW); digitalWrite(baldownPin, LOW); digitalWrite(lightonPin, LOW); } }}}}}}}

but I'm not having any luck

Buy a rabbit's foot?

What is not working? How does the behaviour differ from what you expect? How are your switches wired? You don't show any pull-ups being enabled - have you got external pull-ups?

I am with Groove, its difficult to help without knowing more about what you are trying to do and how you have things connected.

But I guess you want to whichever switch is pressed to turn on the associated pins. If so, you need external pull down resistors for this to work. (see fig 5.5 in this tutorial: Arduino Tutorial - Lesson 5)

If you use pull ups (internal or external) you should test the switches for LOW instead of HIGH

BTW, its difficult to follow the nesting of your else statments, here is a more conventional way to code your logic.

void loop()
{
  leftbuttonState = digitalRead(leftbuttonPin);     
  rightbuttonState = digitalRead(rightbuttonPin);
  surfacebuttonState = digitalRead(surfacebuttonPin);
  divebuttonState = digitalRead(divebuttonPin);
  forwardbuttonState = digitalRead(forwardbuttonPin);
  backwardbuttonState = digitalRead(backwardbuttonPin);
  lightbuttonState = digitalRead(lightbuttonPin);


  if (leftbuttonState == HIGH) 
  {        
    digitalWrite(leftbackwardPin, HIGH);
    digitalWrite(rightforwardPin, HIGH);  
  } 
  else if (rightbuttonState == HIGH) 
  {        
    digitalWrite(leftforwardPin, HIGH);
    digitalWrite(rightbackwardPin, HIGH);  
  }
  else if (surfacebuttonState == HIGH) 
  {        
    digitalWrite(balupPin, HIGH);  
  } 
  else if (divebuttonState == HIGH) 
  {        
    digitalWrite(baldownPin, HIGH); 
  } 
  else if (forwardbuttonState == HIGH) 
  {        
    digitalWrite(leftforwardPin, HIGH);
    digitalWrite(rightforwardPin, HIGH);  
  }  
  else if (backwardbuttonState == HIGH) 
  {        
    digitalWrite(leftbackwardPin, HIGH);
    digitalWrite(rightbackwardPin, HIGH);  
  }
  else if (lightbuttonState == HIGH) 
  {        
    digitalWrite(lightonPin, HIGH);  
  }  
  else{
    digitalWrite(leftforwardPin, LOW);
    digitalWrite(leftbackwardPin, LOW);
    digitalWrite(rightforwardPin, LOW);
    digitalWrite(rightbackwardPin, LOW);
    digitalWrite(balupPin, LOW);
    digitalWrite(baldownPin, LOW);
    digitalWrite(lightonPin, LOW);
  }
}

The switches are wired with a 10K ohm pull-down resistor as shown in this schematic: http://arduino.cc/en/uploads/Tutorial/button_schem.png

Each of the output pins is wired to the positive leg of a relay with all the ground legs wired in series to the grnd pin on the Arduino.

No matter which button I push pins 6, 4, 2 and 1 are all set to HIGH and that is the problem I am having.

Sorry for the earlier lack of info.

You don't say if you tried the loop code posted in reply #2, but if you did and that didn't help, try a simple test with just one switch and just one output to see if you can get that going. If so, add a second switch and output.

Using loop code in reply #2 still left pins 1 and 2 HIGH at all times.

pin 1 is connected to the hardware uart, try using pins other than 0 and 1

othat than those two pins, do the other switches now work as expected?