interfacing a 433Mhz RF transmitter and Receiver with a DC motor

Hi everyone,

i am trying to control a 2 dc motors with w Seed motor Shield 2.0 through the 433Mhz. Rf transmitter and Receiver. I have had no problem transmitting data from transmitter to receiverer. When I transmit just a simple value and not have it do anything else but output it, everything prints out fine. However, once I combine the transmitting/receiving code with the motor library it freezes.

for example if I send a value of 1 and receiver reads a 1 it outputs “49=”. It doesn’t even go to the " motordriver.goForward() " function and it just stays there if I send another value it just freezes there.I am very new to all this and really don know where to go from here. I dont know if its a timing issue between the Transmission and the motor function or what. Can anyone please help? Below is a sample of the code im using for the receiver:

#include <VirtualWire.h>
#include "MotorDriver.h"

void setup()
{
    Serial.begin(9600); // Debugging only
    Serial.println("setup");
   
    motordriver.init();
    motordriver.setSpeed(200,MOTORB);
    motordriver.setSpeed(200,MOTORA);

    vw_setup(2000); // Bits per sec
    vw_set_rx_pin(2);    //Rx Data pin to Digital  Pin 2
    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
  {
      int i;

      digitalWrite(13, true); // Flash a light to show received good message
// Message with a good checksum received, dump it.
      for (i = 0; i < buflen; i++)
     {
         Serial.print(buf[i]);//print received command
         if(buf[i] == '1')//if button 1 is pressed.... i.e.forward buton
         {
            motordriver.goForward();
            Serial.println(" = forward");
            delay (100);
          }

         if(buf[i] == '2')//if button 2 is pressed.... i.e.back buton
         {
             motordriver.goBackward();//go backward
             Serial.println(" = backward");
          }
         if(buf[i] == '3')//if button 3 is pressed.... i.e.left buton
         {
             motordriver.goLeft();//go left
             Serial.println(" = left");
         }
         if(buf[i] == '4')//if button 4 is pressed.... i.e.right buton
        {
            motordriver.goRight();//go right
            Serial.println(" = right");
        }
      if(buf[i] == '5')//if button 5 is pressed.... i.e.stop buton
        {
            motordriver.stop();//stop/brake
            Serial.println(" = stopped");
        }
      Serial.print(" ");
    }
 Serial.println("");
 digitalWrite(13, false);

 }//close if
}//close loop

in case its needed here is the transmitter code:

#include <VirtualWire.h>

//Assigning controller buttons to Digital Pins
int forward = 8;
int backward = 9;
int rightTurn = 10;
int leftTurn = 11;
int stopMotor = 12;
int remotePins[]= {8,9,10,11,12};//array to store pin nos

void setup()
{
   Serial.begin(9600);  // Debugging only
   Serial.println("setup");
   // Initialise the IO and ISR
   vw_setup(2000); // Bits per sec
   vw_set_tx_pin(3); //Transmitter Data Pin to Digital Pin 3
       

   for(int i = 0; i<6 ; i++)
   {
     pinMode(remotePins[i], INPUT);
     digitalWrite(remotePins[i],HIGH);
   }
     /*
     This is what the loop above does :-
       pinMode(8, INPUT);
       pinMode(9, INPUT);
       pinMode(10, INPUT);
       pinMode(11, INPUT);
       pinMode(12, INPUT);

       digitalWrite(8, HIGH);
       digitalWrite(9, HIGH);
       digitalWrite(10, HIGH);
       digitalWrite(11, HIGH);
       digitalWrite(12, HIGH);*/
}//close setup

void loop()
{
   char *msg2;
 
   if(digitalRead(forward) == LOW)//if the forward button is pressed
   {
     char *msg2 = "1";//send 1 to the receiver
     digitalWrite(13, true); // Flash a light to show transmitting
     vw_send((uint8_t *)msg2, strlen(msg2));//send the byte to the receiver
     vw_wait_tx(); // Wait until the whole message is gone
     digitalWrite(13, false);
   }
 
   if(digitalRead(backward) == LOW)//if the back button is pressed
   {
     char *msg2 = "2";///send 2 to the receiver
     digitalWrite(13, true); // Flash a light to show transmitting
     vw_send((uint8_t *)msg2, strlen(msg2));//send the byte to the receiver
     vw_wait_tx(); // Wait until the whole message is gone
     digitalWrite(13, false);
   }
 
   if(digitalRead(leftTurn) == LOW)//if the left button is pressed
   {
     char *msg2 = "3";//send 3 to the receiver
     digitalWrite(13, true); // Flash a light to show transmitting
     vw_send((uint8_t *)msg2, strlen(msg2));//send the byte to the receiver
     vw_wait_tx(); // Wait until the whole message is gone
     digitalWrite(13, false);
   }
 
   if(digitalRead(rightTurn) == LOW)//if the right button is pressed
   {
     char *msg2 = "4";//send 4 to the receiver
     digitalWrite(13, true); // Flash a light to show transmitting
     vw_send((uint8_t *)msg2, strlen(msg2));//send the message to the receiver
     vw_wait_tx(); // Wait until the whole message is gone
     digitalWrite(13, false);
   }
 
   if(digitalRead(stopMotor)==LOW)//if the stop button is pressed
   {
     char *msg2 = "5";//send 5 to the receiver
     digitalWrite(13, true); // Flash a light to show transmitting
     vw_send((uint8_t *)msg2, strlen(msg2));//send the message to the receiver
     vw_wait_tx(); // Wait until the whole message is gone
     digitalWrite(13, false);
 } 
}//close loop

However, once I combine the transmitting/receiving code with the motor library it freezes.

A link to the library would be useful. What pins does the shield use?

Posting your code in code tags, by using the leftmost icon on the first row above the text entry field, would stop the forum from mangling your code.

Using Tools + Auto Format to correct the indenting would be good, too.

Thanks for your advice I revised my post. Way easier to read now.

Here is the link to the virtual wire library:

http://www.airspayce.com/mikem/arduino/VirtualWire/

from what I've seen from others that use the shield: Pins 8,11 got to one motor pins 12, 13 to the other motor and pins 9 and 10 seem to have this code " analogWrite(pin, 255)" which I think its like PWM signal but like I said im kind of new to this so it might be something else.

hope it helps because Im still having problems and I really dont know where to look anymore.

and I really dont know where to look anymore.

         Serial.print(buf[i]);//print received command

Anonymous printing is a bad idea.

Serial.print("buf[");
Serial.print(i);
Serial.print("] = [");
Serial.print(buf[i]);
Serial.println("]");

Conveys an order of magnitude more data. Perhaps even enough to reveal a clue or two.

 digitalWrite(13, false);

Since you say that 13 is a motor shield pin, diddling with the state of pin 13 is probably not a great move.

Thanks Paul, I have tried taking out that line

digitalWrite(13, false);

because I thought it might cause issues but it still didnt help. I am not sure what you mean by anonymous printing. I thougth that that was just there to help in debugging.

would you happen to know what these lines do:

uint8_t buf[VW_MAX_MESSAGE_LEN];

   uint8_t buflen = VW_MAX_MESSAGE_LEN;

   if (vw_get_message(buf, &buflen))

?