Relay's working the wrong way

hey folks i’m currently facing a problem which is not logical for me.
i’m currently building a rudder pilot using a joystick and a rudder positioner that’s working fine!
but the relay’s who need’s to control the actuator are behaving weird.
i have 2 relay’s both controlled using the digital pins and a simple code.
one of the relay’s is working fine … it switch and it switch off the other one … well he likes flashing.
it doesnt switch ofc but the signal led flashes pretty fast.
and that’s the point where i am stuck. here’s the current code:

 int ledPin = 13;
 int joyPin1 = 0;                
 int joypin2 = 1;
 int links = 7;
 int rechts = 8;
 int value1 = 0;
 int value2 = 1;
 
 void setup() {
  pinMode(ledPin, OUTPUT);     
  pinMode(links, OUTPUT);
  pinMode(rechts, OUTPUT);
 }

 int treatValue(int data) {
  return (data * 9 / 500) + 48;
 }

 void loop() { 
  // reads the value of the variable resistor 
  value1 = analogRead(joyPin1);  
  value2 = analogRead(joypin2); 
  delay(100);             

if (treatValue(value2) < treatValue(value1))
{ 
 digitalWrite(links,LOW);
 digitalWrite(rechts,HIGH);
} 
if (treatValue(value2) > treatValue(value1))  
{ 
 digitalWrite(links,HIGH);
 digitalWrite(rechts,LOW);
} 
else 
{ 
 digitalWrite(links,HIGH);
 digitalWrite(rechts,HIGH);
} 

}

and the project it self.

i’ll hope that someone has some expierence with this.

Hi Hurde, welcome.

Seeing your name, your post and sketch, i guess you're from some German speaking country (or possibly Dutch like me).
Did you know there's sections for these languages ?

I'm not sure what problem you are describing, and the information about how things are connected is missing in your post.
But i can guess.
If you see LEDs flashing while you are controlling a relay, the power supply might fail due to a too large current drawn by that relay.
Are you by any chance controlling the relays from the 5 volt of the Arduino board ?
I'm sure the on board power supply can't handle that.
And did you use a transistor per relay to control the relay instead of putting those relays directly to an Arduino output ?
If you didn't know that yet: never connect a relay directly to an Arduino output, you'll destroy that output or more.

You might try something like this (increase value of window as needed):

int ledPin = 13;

int joyPin1 = 0;                
int joypin2 = 1;

int links = 7;
int rechts = 8;

int value1 = 0;
int value2 = 0;

int window = 10;
 
void setup() {
  pinMode(ledPin, OUTPUT);     

  pinMode(links, OUTPUT);
  pinMode(rechts, OUTPUT);
}

int treatValue(int data) {
  return (data * 9 / 500) + 48;
}

void loop() { 
    // reads the value of the variable resistor
    value1 = analogRead(joyPin1);  
    value2 = analogRead(joypin2); 

    delay(100);             

    if (treatValue(value2) < treatValue(value1) - window) { 
        digitalWrite(links,LOW);
        digitalWrite(rechts,HIGH);
    } 

    if (treatValue(value2) > treatValue(value1) + window) { 
        digitalWrite(links,HIGH);
        digitalWrite(rechts,LOW);
    } 
    else { 
        digitalWrite(links,HIGH);
        digitalWrite(rechts,HIGH);
    } 
}

I suspect that what may be happening is that you are expecting the values from the pots to become equal, when in reality noise from them makes that less likely to occur. By adding a “window” around the values, this becomes less of an issue (it’s similar to “deadband” on an analog servo).

Other ways of doing things might be to implement a rolling average of the read values for each potentiometer (basically creating a low-pass filter) or implementing a PID algorithm.

PID is very likely to improve stability and controlability - bang-bang control is hard to
stabilize because full drive is always applied. For PID control you'll want to use PWM
output drive to your actuator(s) and that means replacing the relays with MOSFETs or
similar.

But you haven't really explained what you are driving so its hard to help with any detail.