Relay interfering with sensor readings

Hi,

I've got a 5 channel flame sensor, a 4 channel relay, 2 water pumps, a breadboard, and a 6 battery power supply. I've wired the power supply to the breadboard and am using it to power the pumps.

The relay and sensor are both connected to the arduino. Problem is, whenever the sensor reads a positive and tries to turn on the relay for the pumps, it bugs out and doesn't do it properly.

Here's the code:

int relay2 = 2;
int relay3 = 3;
int wait = 2000;

const int sensorPin1 = 8;  // Digital pin for sensor 1
const int sensorPin2 = 9;  // Digital pin for sensor 2
const int sensorPin3 = 10;  // Digital pin for sensor 3
const int sensorPin4 = 11;  // Digital pin for sensor 4
const int sensorPin5 = 12;  // Digital pin for sensor 5

void setup() {
  Serial.begin(9600);
  
  pinMode(relay2, OUTPUT); // set relay pins as output
  digitalWrite(relay2, HIGH); // turn relay off

  pinMode(relay3, OUTPUT); // set relay pins as output
  digitalWrite(relay3, HIGH); // turn relay off

  pinMode(sensorPin1, INPUT);
  pinMode(sensorPin2, INPUT);
  pinMode(sensorPin3, INPUT);
  pinMode(sensorPin4, INPUT);
  pinMode(sensorPin5, INPUT);
}

void loop() {
  int value1 = digitalRead(sensorPin1);
  int value2 = digitalRead(sensorPin2);
  int value3 = digitalRead(sensorPin3);
  int value4 = digitalRead(sensorPin4);
  int value5 = digitalRead(sensorPin5);
  
  Serial.print("Sensor 1: ");
  Serial.println(value1);
  Serial.print("Sensor 2: ");
  Serial.println(value2);
  Serial.print("Sensor 3: ");
  Serial.println(value3);
  Serial.print("Sensor 4: ");
  Serial.println(value4);
  Serial.print("Sensor 5: ");
  Serial.println(value5);

  if ((value1 == 1) || (value2 == 1) || (value3 == 1) || (value4 == 1) || (value5 == 1)) {
    Serial.println("Positive detection!");
    digitalWrite(relay2, LOW); // turn relay on
    
    delay(5000);
    
  } 
  

  delay(wait); // Add a delay to stabilize readings
}

And here are some photos of the wiring(I've only wired one pump to test it):



Welcome to the forums. Great job using code tags!

It is difficult to see all the wiring across multiple photos. How about a nice, hand-drawn schematic. Also, what do you mean by "bugs out"? Does the relay turn on? Does the motor run? You can always replace the motor with and LED and resistor so see if the motor is drawing too much current.

It doesn't look like your code ever turns off your relay, which will be a problem eventually

1 Like

Could You present the data for the pumps? It might be bad to run their current through a breadboard.
A guess is You feed 9 volt to Vin. What things are connected to controller 5 volt? How much current do they use?

1 Like

Hi! Sorry for the very slow reply. I'm a beginner to this stuff and honestly have no idea how to draw a schematic... I also don't have access to any other components since I left them at school... I mean that, after the sensor detects a 1, instead of turning on the relay forever like I told it to, it starts doing stuff like this:

On the site I bought them from they're called submersible water pumps 3-6V even though the stats below show 3-5V so i don't know...
Tension: DC3-5V
Current: 100-200mA

Also when I run just the relay with the pump without any sensor and tell it to turn on and off it does it flawlessly.

That us too much current for the controller 5 volt pin using Vin. Use a separat pump power source. The same for the relay power.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.