Motors wont stop... :(

Hey guys. I have a little robot on 4 wheels (stepper… kinda) , and i have a problem.
The commands to drive are send via a transmitter sending decimals (look into the code)… the transmitter code is fine and my robot is receiving it without any problems.
. So you can give the bot the command to start driving forward… its working fine. BUT… in the code… when no button is pressed. the transmitter is automaticly sending a command which should make by bot stop. and the command is being received correctly. (already did some tests)… the motors just dont want to stop. they continuie driving for like 10-20 seconds, its random and then they stop… so… whats wrong with my motor…i can change it from doing nothing to driving forward. but i cant change from driving forward to standing still. help…

code of transmitter:

#include <RCSwitch.h>


RCSwitch mySwitch = RCSwitch();

const int forward = 5;
const int left = 6;
const int right = 4;
const int backward = 7;
int mode = 1;

void setup() {
 
  mySwitch.enableTransmit(10);
  
  Serial.begin(9600);         //    1
  pinMode(forward,INPUT);     // 2     3
  pinMode(backward,INPUT);    //    4
  pinMode(left, INPUT);
  pinMode(right,INPUT);
 
}

void loop() {
  
  if(digitalRead(forward)==LOW){
  if(digitalRead(backward)==LOW){
  if(digitalRead(left)==LOW){
  if(digitalRead(right)==LOW){  
    mySwitch.send(1234,24);
  }
}
}
}
   
  
  if(digitalRead(forward)==HIGH){
    Serial.println("Forward");
 
    mySwitch.send(1111,24);
  } 
  
  if(digitalRead(backward)==HIGH){
     Serial.println("Backward");
   mySwitch.send(4444,24);
    } 

    
  if(digitalRead(left)==HIGH){
      Serial.println("Left");
   mySwitch.send(2222,24);
      } 
      
   if (digitalRead(right)==HIGH){
      
     Serial.println("Right");
     mySwitch.send(3333,24);
        
        } 
          

}

Code of the bot:

#include <RCSwitch.h>


RCSwitch mySwitch = RCSwitch();


int mode = 1;
// connect motor controller pins to Arduino digital pins
// motor one
int enA = 10;
int in1 = 9;
int in2 = 8;
// motor two
int enB = 5;
int in3 = 7;
int in4 = 6;
void setup()
{
  
   mySwitch.enableReceive(0);
  // set all the motor control pins to outputs
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
}


void slow(){
  
 
  // now turn off motors
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);  
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);  
  
  }

void drive(){
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);  
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW); 

  
  }

void loop()
{
  
  
  if(mySwitch.available()){
     int request = mySwitch.getReceivedValue();
 
         if(request==1234){
         
         slow();
           
         }

       if(request==1111){
         
    drive();

    
         }
 
    }
}

oh wrong section. please move.

You say you have tested it but give no information on the tests or results.

Weedpharma

How are your buttons connected? Are you using pull-up or pull-down resistors?

You have interference when the motors are running meaning the receiver is struggling to get a clean signal from the transmitter, accounting for the randomish delay responding.

You need to reduce the EMI put out from your motors by adding an RF blocking capacitor across the terminals of each motor, and probably add more decoupling to the motor supply (1000uF or more).

Keep the receiver well away from the motors too.

All the motor power wiring (from battery pack to motor controller and from motor controller to motors) should ideally be shielded twisted pair, but definitely twisted pair at a minimum to reduce radiation.