Light controll problem

Hi everybody. I am new in the Arduino community an I have a problem runing my program.

Waht it schuold du: Pressing the button -> 5v into digital od analog pin -> Relai turns on -> else Relai turns off.

my code

const int buttonPin1 = 52; // the number of the pushbutton pin
const int ledPin1 = 22; // the number of the LED pin
const int ledPin2 = 23;
const int ledPin3 = 24;
const int ledPin4 = 25;
const int ledPin5 = 26;
const int ledPin6 = 27;
const int ledPin7 = 28;
const int ledPin8 = 29;
const int ledPin9 = 30;
const int ledPin10 = 31;
const int ledPin11 = 32;
const int ledPin12 = 33;
// variables will change:
int buttonState1 = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
pinMode(ledPin7, OUTPUT);
pinMode(ledPin8, OUTPUT);
pinMode(ledPin9, OUTPUT);
pinMode(ledPin10, OUTPUT);
pinMode(ledPin11, OUTPUT);
pinMode(ledPin12, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT);
}

void loop(){
// read the state of the pushbutton value:
buttonState1 = digitalRead(buttonPin1);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState1 == HIGH)
{
// turn LED on:
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
delay(1000); // waits for a second
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
delay(1000);
digitalWrite(ledPin5, HIGH);
digitalWrite(ledPin6, HIGH);
digitalWrite(ledPin7, HIGH);
digitalWrite(ledPin8, HIGH);
delay(1000);
digitalWrite(ledPin9, HIGH);
digitalWrite(ledPin10, HIGH);
delay(1000);
digitalWrite(ledPin11, HIGH);
digitalWrite(ledPin12, HIGH);
}

else
{
// turn LED off:
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
delay(1000);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
delay(1000);
digitalWrite(ledPin5, LOW);
digitalWrite(ledPin6, LOW);
digitalWrite(ledPin7, LOW);
digitalWrite(ledPin8, LOW);
delay(1000);
digitalWrite(ledPin9, LOW);
digitalWrite(ledPin10, LOW);
delay(1000);
digitalWrite(ledPin11, LOW);
digitalWrite(ledPin12, LOW);
}
}

Please Help. or post some suggestions.

thanks.

I don't see any sign of a relay in that program. Have you posted the right code ?

What is should do is barely adequately described.

What is actually does is not even hinted at.

The digital pins 22-33 are connected to relays and Pin 52 to the buton

my problem is when i turn of the button the loop funktion goes on and on and on.

This means: Lichts turn on and off it waits 5-7 sec. and it starts from begining. (not OK) it should torn off and stay off til i torn on the button

If the button in on -> light turns on and stays (OK)

please help

While the program is doing 'delay', it's not able to do anything else, like reading the state of the button, so your button will only be read every 4 seconds.

Look at the 'Blink without delay' sketch.

Another question for you. How is the button wired ? Do you have a resistor attached to it to ensure that the Arduino pin is held high or low when the button is not pressed ?

The description is a bit hard to follow, but if I understood you correctly you want a set of relays to turn on when a switch is closed and turn off when the switch is opened.

Why don't you simply power all the relay coils via the switch?

Fisrt af all thanks for the answers.

@UKHeliBob. I use a simply on/of switch with no resistor

@PeterH What do <ou mean tich a switch? Like a switch from a network?

I will read trough the Blink without delay.

If you have no resistor connected to the switch then when the switch is not closed the input pin to the Arduino (pin 52) will be 'floating' and have an uncertain voltage applied to it. This can cause the program to behave as though the switch is closed when, in fact, it is not.

It seems from your code that the switch connects pin 52 to 5V when it is closed. If this is the case, then connect a 10K resistor from the pin to GND to hold it LOW except when it is explicitly taken HIGH by closing the switch.