Hi,
I am new to Arduino and programming. I built my card and tested it it is working. For now, I only sucseeded to control one relay with one button.
What I'm doing is:
I have three voltage cutter boards for battery low voltage cutting. They work as buttons at my setup and they stop sending 5V to arduinos digital input when the connected batteries voltage drops.
My aim is to activate and de-activate these relays whenever voltage cutters send signal to Arduino.
Here is my sketch:
int role1 = 1;
int role2 = 2;
int role3 = 3;
int role4 = 4;
int role5 = 5;
int role6 = 6;
int volt1 = 45;
int volt2 = 49;
int volt3 = 53;
int voltstate1 = HIGH;
int voltstate2 = HIGH;
int voltstate3 = HIGH;
int reading1 ;
int reading2 ;
int reading3 ;
int previous1 = LOW;
int previous2 = LOW;
int previous3 = LOW;
long time1 = 0;
long time2 = 0;
long time3 = 0;
long debounce1 = 200;
long debounce2 = 200;
long debounce3 = 200;
void setup() {
pinMode(role1, OUTPUT);
pinMode(role2, OUTPUT);
pinMode(role3, OUTPUT);
pinMode(role4, OUTPUT);
pinMode(role5, OUTPUT);
pinMode(role6, OUTPUT);
pinMode(volt1, INPUT);
pinMode(volt2, INPUT);
pinMode(volt3, INPUT);
}
void loop() {
reading1 = digitalRead(volt1);
if (reading1 == HIGH && previous1 == LOW && millis() - time1 > debounce1) {
delay (2000);
if (voltstate1 == HIGH) {
voltstate1 = LOW;
}
else {
voltstate1 = HIGH;
}
time1 = millis();
}
digitalWrite(role3, voltstate1);
previous1 = reading1;
}
In this sketch, not used other three relays (role4, 5 and 6) will be used to activate the battery chargers later. (this is kind of easy to do)
I just need a three button, three relay (or led, actually it doesn't matter) sketch example. Using if statements inside if statements is not practical for my approach. I guess there should be an easier way. If you can help me I will really appriciate it.