Help with the code?

Hi, Am trying to build a unit that cuts the power when there is salt water connecting the two wires. Have GND and 7 that works fine and turn on off the built in led. Then I connect the relay to 5v, GND and dig 8. The relay then starts vibrating, I am guessing on/off cycles which I couldnt see the led doing. Added a delay, which "cools" things down... But same result....

I sincerly hope now that I didnt post this the wrong way, have even tried to format the code better....

const int floodSensors = 7;   
 const int ledPin =  13;    
 #define RELAY_PIN 8

 // variables will change:
 int floodSensorState = 0;         

 void setup() {
   pinMode(ledPin, OUTPUT);      
   pinMode(floodSensors, INPUT);
   pinMode(RELAY_PIN, OUTPUT);     
 }

 void loop(){
   floodSensorState = digitalRead(floodSensors);
   
   if (floodSensorState == HIGH) {     
     digitalWrite(ledPin, HIGH); 
     digitalWrite(RELAY_PIN, HIGH); 
   } 
   else {
     digitalWrite(ledPin, LOW); 
     digitalWrite(RELAY_PIN, LOW);
   }
 }
![20240107_182419|666x500](upload://3jMa9uiKcVsuyDO3rp2fQ8kTJwv.jpeg)

What's controlling the relay? DO you have a controller board for it?

It's a small relay for direct connection to an Arduino. Think there is a controller board on with 3 connectors S, + and -.

Always show us a good schematic of your proposed circuit.

Show us good images of your ‘actual’ wiring.

Give links to components.

This is a quick sketch of the very easy setup.

Here is a link to the Velleman relay: Velleman for Makers VMA406: 5 V RELAY MODULE – Velleman – Wholesaler and developer of electronics

Supply the relay with power from the power source (5vdc, or whatever your relay wants). Only use the Arduino for signaling.


[edit]... but when this detector conducts, the sketch is setting and resetting every time through loop() ... trying to turn the relay and LED on and off, each time.more like a shorted button.

Is the relay activated when the input pin (S) is connected to 5V (HIGH) or GND (LOW)?