hi everybody, i just started my journy into electronique and i have trouble with my circuit.
ok so to start, my project is a arduino bar, so basicaly a have 4 push botton that control 4 relay to control 4 pump, the probleme is that i am running into noise, when i press 1 button, randomly multiple relay whould active. so i look on the internet for solution, first i put flyback diode on each pump and it help but i was still having the same probleme, then i protected the arduino by seperating the alimentation for the relays with a buck converter , but it didnt change a thing. so this is where i am stuck right now. so that where i need help, what could i add or modify to save my project, i will give you all the electronique, code and a drawing i did of the circuit
PS: its a arduino mega

const int PB_1 = 2; // Button1
const int RLY_1 = 12; //relay 1
const int PB_2 = 3; // Button2
const int RLY_2 = 11; //relay 2
const int PB_3 = 4; // Button3
const int RLY_3 = 10; //relay 3
const int PB_4 = 5; // Button4
const int RLY_4 = 9; //relay 4
//VARIABLES
int buttonState1 = 0;
// current state of the button
bool relay1 = false;
int buttonState2 = 0;
// current state of the button
bool relay2 = false;
int buttonState3 = 0;
// current state of the button
bool relay3 = false;
int buttonState4 = 0;
// current state of the button
bool relay4 = false;
//MILLIS
unsigned long previousMillis1 = 0;
unsigned long previousMillis2 = 0;
unsigned long previousMillis3 = 0;
unsigned long previousMillis4 = 0;
const unsigned long interval1 = 2000;
const unsigned long interval2 = 3000;
const unsigned long interval3 = 4000;
const unsigned long interval4 = 5000;
void setup()
{
pinMode(PB_1, INPUT);
digitalWrite(PB_1, HIGH); // pull-up
pinMode(PB_2, INPUT);
digitalWrite(PB_2, HIGH); // pull-up
pinMode(PB_3, INPUT);
digitalWrite(PB_3, HIGH); // pull-up
pinMode(PB_4, INPUT);
digitalWrite(PB_4, HIGH); // pull-up
pinMode(RLY_1, OUTPUT);
digitalWrite(RLY_1, HIGH);
pinMode(RLY_2, OUTPUT);
digitalWrite(RLY_2, HIGH);
pinMode(RLY_3, OUTPUT);
digitalWrite(RLY_3, HIGH);
pinMode(RLY_4, OUTPUT);
digitalWrite(RLY_4, HIGH);
Serial.begin(9600);
}
void loop(){
// read the pushbutton input pin:
buttonState1 = digitalRead(PB_1);
buttonState2 = digitalRead(PB_2);
buttonState3 = digitalRead(PB_3);
buttonState4 = digitalRead(PB_4);
unsigned long currentMillis = millis();
// if button is pressed, turn relay on (if it wasn't already on), and reset the timer
if( buttonState1==HIGH ) // no need to check for previous state, in this specific case
{
previousMillis1 = currentMillis;
digitalWrite(RLY_1, LOW);
relay1 = true;
}
if( relay1 )
{
// turn red led on, if close to turning off the relay
// if enough time has elapsed, turn of the relay
if (currentMillis - previousMillis1 >= interval1)
{
// .. turn of relay
digitalWrite(RLY_1, HIGH);
relay1 = false;
}
}
if( buttonState2==HIGH ) // no need to check for previous state, in this specific case
{
previousMillis2 = currentMillis;
digitalWrite(RLY_2, LOW);
relay2 = true;
}
if( relay2 )
{
// turn red led on, if close to turning off the relay
// if enough time has elapsed, turn of the relay
if (currentMillis - previousMillis2 >= interval2)
{
// .. turn of relay
digitalWrite(RLY_2, HIGH);
relay2 = false;
}
}
if( buttonState3==HIGH ) // no need to check for previous state, in this specific case
{
previousMillis3 = currentMillis;
digitalWrite(RLY_3, LOW);
relay3 = true;
}
if( relay3 )
{
// turn red led on, if close to turning off the relay
// if enough time has elapsed, turn of the relay
if (currentMillis - previousMillis3 >= interval3)
{
// .. turn of relay
digitalWrite(RLY_3, HIGH);
relay3 = false;
}
}
if( buttonState4==HIGH ) // no need to check for previous state, in this specific case
{
previousMillis4 = currentMillis;
digitalWrite(RLY_4, LOW);
relay4 = true;
}
if( relay4 )
{
// turn red led on, if close to turning off the relay
// if enough time has elapsed, turn of the relay
if (currentMillis - previousMillis4 >= interval4)
{
// .. turn of relay
digitalWrite(RLY_4, HIGH);
relay4 = false;
}
}
}





