Hallo All
i am new to Arduino
i'm trying to get button1 to use relay1 and button2 to use relay2 and button3 to use both relays. relays is only on when button is presed.
i got code to work with relay 1 and 2 but i need help with button 3.
i started 2 hours ago looking at this forum boy you can learn mutch looking at codes.
Thanks in front for your help.
const int buttonPin_1 = 7; // the number of the pushbutton pin
const int buttonPin_2 = 6;
const int buttonPin_3 = 5; // Use for both relays?
const int Light_1 = 2; // Relay 2 pin
const int Light_2 = 3; // Relay 3 pin
const int Light_3 = 8; // Relay 8 pin
// variables will change:
boolean buttonState = LOW; // variable for reading the pushbutton status
boolean buttonState2 = LOW; //variable for reading the second buttons state
boolean buttonState3 = LOW;
void setup() {
// initialize the LED pin as an output:
pinMode(Light_1, OUTPUT);
pinMode(Light_2, OUTPUT);
pinMode(Light_3, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin_1, INPUT);
pinMode(buttonPin_2, INPUT);
pinMode(buttonPin_3, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin_1);
buttonState2 = digitalRead(buttonPin_2);
buttonState3 = digitalRead(buttonPin_3);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
// Light 1
if (buttonState == HIGH) {
// turn relay on:
digitalWrite(Light_1, HIGH);
}
else {
// turn relay off:
digitalWrite(Light_1, LOW);
}
// Light 2
if (buttonState2 == HIGH) {
// turn relay 2 on:
digitalWrite(Light_2, HIGH);
}
else {
// turn relay off:
digitalWrite(Light_2, LOW);
// Light 3
if (buttonState3 == HIGH) {
// turn relay 3 on:
digitalWrite(Light_3, HIGH);
}
else {
// turn turn off:
digitalWrite(Light_3, LOW);
}
}
}