Problem with VirtualWire (I think)

So, I’m making an RC Car using a motor shield V1 and some 433MHz RF Modules, but I’m having a problem.

This is the code i used to test the reciever:

#include <VirtualWire.h>
void setup()
{
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_set_rx_pin(17);
    vw_setup(4000);  // Bits per sec
    pinMode(13, OUTPUT);
  
    Serial.begin(9600);

    vw_rx_start();       // Start the receiver PLL running
}
    void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    if (vw_get_message(buf, &buflen)) // Non-blocking
    {
      if(buf[0]=='1'){

  
   digitalWrite(13,1);
   Serial.println("1");
      }  
   if(buf[0]=='0'){
  digitalWrite(13,0);
  Serial.println("0");
    }

}
}

It works very well and recieves the 1’s and 0’s that I’m sending.

The problem is when i implement the car’s movement in the sketch, the code looks like this.

#include <AFMotor.h>
#include <VirtualWire.h>

AF_DCMotor m1(1);
AF_DCMotor m2(2);
AF_DCMotor m3(3);
AF_DCMotor m4(4);

void setup()
{
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_set_rx_pin(17);
    vw_setup(4000);  // Bits per sec
  
    Serial.begin(9600);

    vw_rx_start();       // Start the receiver PLL running
}

void loop() {
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    if (vw_get_message(buf, &buflen)) // Non-blocking
    {
      if(buf[0]=='0') { mRelease(); Serial.println("release"); }
      if(buf[0]=='1') { mForward(); Serial.println("forward"); }
      if(buf[0]=='2') { mBackward(); Serial.println("backward"); }
      if(buf[0]=='3') { mRight(); Serial.println("right"); }
      if(buf[0]=='4') { mLeft(); Serial.println("left"); }
    }
}

void mRelease(){
  m1.setSpeed(255);
  m2.setSpeed(255);
  m3.setSpeed(255);
  m4.setSpeed(255);
  
  m1.run(RELEASE);
  m2.run(RELEASE);
  m3.run(RELEASE);
  m4.run(RELEASE);
 }

 void mForward(){
  m1.setSpeed(255);
  m2.setSpeed(255);
  m3.setSpeed(255);
  m4.setSpeed(255);
  
  m1.run(FORWARD);
  m2.run(FORWARD);
  m3.run(FORWARD);
  m4.run(FORWARD);
 }

 void mBackward(){
  m1.setSpeed(255);
  m2.setSpeed(255);
  m3.setSpeed(255);
  m4.setSpeed(255);
  
  m1.run(BACKWARD);
  m2.run(BACKWARD);
  m3.run(BACKWARD);
  m4.run(BACKWARD);
 }

 void mLeft(){
  m1.setSpeed(255);
  m2.setSpeed(200);
  m3.setSpeed(200);
  m4.setSpeed(255);
  
  m1.run(FORWARD);
  m2.run(BACKWARD);
  m3.run(BACKWARD);
  m4.run(FORWARD);
  }

 void mRight(){
  m1.setSpeed(200);
  m2.setSpeed(255);
  m3.setSpeed(255);
  m4.setSpeed(200);
  
  m1.run(BACKWARD);
  m2.run(FORWARD);
  m3.run(FORWARD);
  m4.run(BACKWARD);
  }

When i upload this sketch to the Arduino (It’s a MEGA), it dosen’t recieve anything from the transmitter.

Any idea on what’s happening?

So i was troubleshooting it and discovered the problem, it recieves one message, triggers the state on the motor, and stops recieving. Just need to solve it now. Any ideas?

Please read and follow the directions in the "How to use this forum" post.

Most likely not with VirtualWire, but you have not provided enough information to troubleshoot the problem: wiring diagrams, power supplies, motor, motor driver and battery specs, etc.