Problem with Brushless DC-motor and infrared sensor

Hi guys,

I’m currently working on a project for the university where I want to control a pump with a remote control via an infrared sensor.

The motor is controlled by a relay. The relay does not correspond to the relay in my schematic. It’s a 4 channel relay, which was built with two different options

1 - normal circuit as in circuit-figure

2 - circuit with galvanic isolation as in link under option 3 → Relay Tutorial

The problem is the following. Without a motor, the relay switches correctly after the infrared sensor receives the corresponding code. However, after I connect the motor, the relay can only be switched on but not off. Once the engine is running, the infrared sensor cannot receive correct signals. I’ve been working on the problem for over a week and I can’t figure out why the infrared sensor is malfunctioning. I have separated the power sources, experimented with resistors and built in transistors. All without success. Unfortunately I have very bad knowledge in the field of electrical engineering, so I would be very grateful for any help.

Code:

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <IRremote.h>

//______INFRAFREDSENSOR_______________________________
const int RECV_PIN = 8;
IRrecv irrecv(RECV_PIN);   // An dieser Stelle wird ein Objekt definiert, dass den Infrarotsensor an Pin 11 ausliest.
decode_results results; 
int tasterLinks=5;
int tasterRechts=4;

//______LCD___________________________________________
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);


void setup()
{
  Serial.begin(9600);  
  pinMode(tasterLinks, INPUT);
  pinMode(tasterRechts, INPUT);
  
  pinMode(2, OUTPUT);
  irrecv.enableIRIn();
  
	// initialize the LCD
	lcd.begin();
	lcd.backlight();
//	lcd.print("TEST");
}

void loop()
{
  Serial.println(results.value, DEC);
  if (irrecv.decode(&results)){

    //Serial.println(results.value, DEC);
   if(results.value==16734885){
      lcd.clear();
      lcd.print("RECHTS");
      delay(100);
      digitalWrite(2, HIGH);
    }
    if(results.value==16716015){
      lcd.clear();
      lcd.print("LINKS");
      delay(100);
      digitalWrite(2, LOW);
    }
    if(results.value==16718055){
      lcd.clear();
      lcd.print("OBEN");
    }
    if(results.value==16730805){
      lcd.clear();
      lcd.print("UNTEN");
    }
    if(results.value==16726215){
      lcd.clear();
      lcd.print("ENTER");
    }
    if(results.value==16728765){
      lcd.clear();
      lcd.print("BACK");
    }
    irrecv.resume();        
  }

}

Parts:

IR-Sensor

Brushless DC Motor 5V

Circuit:

Circuit

Please note, that I’ve used another Relay than in the shown circuit. The correct one is in the amazon link and was used with a galvanic isolation like here:

Relay Tutorial Galvanic Isolation

You can also see a video of the Problem here:

video

Solved!

I connected the Pins of the Motor and Relay directly to the external power supply (not via breadboard).