help with multiple inputs to multiple outputs

Hey guys,

This is my first attempt at using the arduino board (UNO).
my goal is to make a water level/control system for my Christmas tree.
It will consist of two tanks one with 5 leds that show the water level and tell when to turn the refill pump on.
The first tank I want as follows:

I want 5 leds to turn on when the water is full.
I want 4 leds to turn on when the water is 75%full.
I want 3 leds to turn on when the water is 50%full.
I want 2 leds to turn on when the water is 25%full.
and I want 1 led and the pump to turn on when the water is at 0%.

The second tank i want as follows:
I want the motor/pump to remain off if water is empty in tank #2 and I want an LED and buzzer to sound.

attached is a copy of my sketch. Like I said I am new to the microcontroller programming so any help would be appreciated.

int ledPinbuzz = 2;
int ledPin0 = 3;
int ledPin25 = 4;
int ledPin50 = 5;
int ledPin75 = 6;
int ledPin100 = 7;
int ledPinref = 8;
int sensePinbuzz =A0;
int sensePin0 =A1;
int sensePin25 =A2;
int sensePin50 =A3;
int sensePin75 =A4;
int sensePin100 =A5;
int motorPin = 9;
int x=850;

void setup() {
analogReference(DEFAULT);

pinMode(ledPinbuzz, OUTPUT);
pinMode(ledPin0, OUTPUT);
pinMode(ledPin25, OUTPUT);
pinMode(ledPin50, OUTPUT);
pinMode(ledPin75, OUTPUT);
pinMode(ledPin100, OUTPUT);
pinMode(ledPinref, OUTPUT);
pinMode (motorPin, OUTPUT);
pinMode(sensePinbuzz, INPUT);
pinMode (sensePin0, INPUT);
pinMode (sensePin25, INPUT);
pinMode (sensePin50, INPUT);
pinMode (sensePin75, INPUT);
pinMode (sensePin100, INPUT);

int valbuzz = analogRead(sensePinbuzz);
int val0 = analogRead (sensePin0);
int val25 = analogRead (sensePin25);
int val50 = analogRead (sensePin50);
int val75 = analogRead (sensePin75);
int val100 = analogRead (sensePin100);
digitalWrite(ledPinref, HIGH);
Serial.begin(9600);
}

// the loop function runs over and over again forever
void loop() {
int valbuzz = analogRead(sensePinbuzz);
int val0 = analogRead (sensePin0);
int val25 = analogRead (sensePin25);
int val50 = analogRead (sensePin50);
int val75 = analogRead (sensePin75);
int val100 = analogRead (sensePin100);

Serial.println(val0);
delay(1000);

if (valbuzz>x && val0<x && val25<x && val50<x && val75<x && val100<x)
digitalWrite(motorPin,HIGH),(ledPin0 && ledPin25 && ledPin50 && ledPin75 && ledPin100,LOW);

else if (valbuzz>x && val0>x && val25<x && val50<x && val75<x && val100<x)
digitalWrite(ledPin0,HIGH),(motorPin && ledPin25 && ledPin50 && ledPin75 && ledPin100,LOW);

else if (valbuzz>x && val0>x && val25>x && val50<x && val75<x && val100<x)
digitalWrite(ledPin0 && ledPin25,HIGH),(motorPin && ledPin50 && ledPin75 && ledPin100,LOW);

else if (valbuzz>x && val0>x && val25>x && val50>x && val75<x && val100<x)
digitalWrite(ledPin0 && ledPin25 && ledPin50,HIGH),(motorPin && ledPin75 && ledPin100,LOW);

else if (valbuzz>x && val0>x && val25>x && val50>x && val75>x && val100<x)
digitalWrite(ledPin0 && ledPin25 && ledPin50 && ledPin75,HIGH),(motorPin && ledPin100,LOW);

else if (valbuzz>x && val0>x && val25>x && val50>x && val75>x && val100>x)
digitalWrite(motorPin,HIGH),(ledPin0 && ledPin25 && ledPin50 && ledPin75 && ledPin100,HIGH);

}

Christmas_Tree_Monitor_Circuit.ino (4.29 KB)

Here is a rough drawing of the basic hook ups

circuit.gif

digitalWrite(motorPin,HIGH),(ledPin0 && ledPin25 && ledPin50 && ledPin75 && ledPin100,LOW);

This looks wrong.
You can only set one pin with digitalWrite()
If you want to light ledPin0 you need another digitalWrite(lepPin0, HIGH); etc.

And the correct way to do an IF statement is

if (x >y ) {
 //stuff to do
}

Note the {}

If you have a variable representing the state of each LED which is set in accordance with the analog reading you can eliminate all the complex IF statements. Something like this

led0State = 0;
led1State = 0;
// etc
val0 = analogRead(sensePin0);
// etc
if (val0 > x) {
   led0State = HIGH;
}
if (val1 > x) {
  led1State = HIGH;
}
// etc

digitalWrite(ledPin0, led0State);
// etc

If you store the ledPins, states etc in arrays you can shorten the code even more and avoid repeated typing that may have errors.

Please use the code button (the scroll with <>) to make your code easier to read and to copy to text editor.

...R