Using an RF 433Mhz module

Hello,

I am working on a project to build an RC toy vehicle that has 2 wheels.

I am trying to test a simple wireless communication between the controller and the vehicle.

(I am using 2 arduino uno's)

I fabricated a dc motor driver with 2 h-bridges (A953) that has pins to connect to an arduino to control 2 motors.

The motors work great.

I am using a 2-axis parallax joystick on another arduino uno and i want it to control the 2 motors.

For the RF part i am using this module :

RF 433MHZ module

I am trying VirtualWire as the library after trying other libraries which were less intuitive,

This is the transmitter code:

#include <VirtualWire.h>

int UD = 0;
int LR = 0;

char *controller;

void setup() {
 Serial.begin(9600);  
 pinMode(13,OUTPUT);
 vw_set_ptt_inverted(true); //
 vw_set_tx_pin(12);
 vw_setup(4000);// speed of data transfer Kbps
}

void loop() {

 UD = analogRead(A0);
 LR = analogRead(A1);
 
 Serial.print("UD = ");
 Serial.print(UD, DEC);
 Serial.print(", LR = ");
 Serial.println(LR, DEC);   

if(UD>531)//Drive forward
{ 
  controller="1";
  vw_send((uint8_t *)controller, strlen(controller));
  vw_wait_tx(); // Wait until the whole message is gone
  digitalWrite(13,1);
  delay(2000);
}
else if(UD<531)//Drive backwards
{
  controller="2";
  vw_send((uint8_t *)controller, strlen(controller));
  vw_wait_tx(); // Wait until the whole message is gone
  digitalWrite(13,1);
  delay(2000);
}
else if(UD==531)
{
 controller="0";
  vw_send((uint8_t *)controller, strlen(controller));
  vw_wait_tx(); // Wait until the whole message is gone
  digitalWrite(13,1);
  delay(2000);
}
else
{
digitalWrite(13,0);
}
}

This is the receiver code:

const int motor1PinA = 7;    // H-bridge leg 1 
const int motor1PinB = 8;    // H-bridge leg 2 

const int motor2PinA = 2;    // H-bridge leg 1 
const int motor2PinB = 3;    // H-bridge leg 2 

#include <VirtualWire.h>
void setup()
{
   pinMode(motor1PinA, OUTPUT);
   pinMode(motor1PinB, OUTPUT);
   pinMode(motor2PinA, OUTPUT);
   pinMode(motor2PinB, OUTPUT);

   vw_set_ptt_inverted(true); // Required for DR3100
   vw_set_rx_pin(12);
   vw_setup(4000);  // Bits per sec
   pinMode(13, OUTPUT);

   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(motor1PinA, HIGH);   // set leg 1 of the H-bridge low
     digitalWrite(motor1PinB, LOW);  // set leg 2 of the H-bridge high
     digitalWrite(motor2PinA, LOW);   // set leg 1 of the H-bridge low
     digitalWrite(motor2PinB, HIGH);  // set leg 2 of the H-bridge high
     }  
     if(buf[0]=='2'){
        digitalWrite(motor1PinB, LOW);   // set leg 1 of the H-bridge low
     digitalWrite(motor1PinA, HIGH);  // set leg 2 of the H-bridge high
     digitalWrite(motor2PinB, HIGH);   // set leg 1 of the H-bridge low
     digitalWrite(motor2PinA, LOW);  // set leg 2 of the H-bridge high

   }

  if(buf[0]=='0'){
        digitalWrite(motor1PinB, LOW);   // set leg 1 of the H-bridge low
     digitalWrite(motor1PinA, LOW);  // set leg 2 of the H-bridge high
     digitalWrite(motor2PinB, LOW);   // set leg 1 of the H-bridge low
     digitalWrite(motor2PinA, LOW);  // set leg 2 of the H-bridge high

   }

}

}

Nothing happens when i run it and try to move the joystick.

I did try the simple example in the library and it seemed to work (led's on each arduino blinked simultaneously).

Each of the settings work great separately (i.e motors on the arduino , joystick on an arduino)

I appreciate any help, if there is anymore info needed let me know

Thanks,

Roy.

Nothing jumps out at me, although 4000 bits/second is fast for these modules and may be error prone. Do you have 17 cm straight wire antennas on each module?

The most straightforward way to debug problems like this is to put print statements at various places in the code, to make sure that each part is working as intended.

For example, put a print statement in the receiver code to see what characters are actually received.

if(UD>531)//Drive forward
else if(UD<531)//Drive backwards
else if(UD==531)
else
{
}
}

If the value is not greater than 531, is not less than 531, and is not 531, what else is there? Under what circumstances will the else block ever be executed?

The zero value of the U/D reading is 531 all the time, so when i am not moving the joystick its 531.

if i move it upwards the value increases so its either 531 or over it or under it

jremington:
Nothing jumps out at me, although 4000 bits/second is fast for these modules and may be error prone. Do you have 17 cm straight wire antennas on each module?

I dont have the antennas connected....but they are both on the same computer and very close to each other...you think that could be the problem ?

I will try and debug it and also connect 2 antennas...

Thanks

Add some sort of debugging. For example,

const int motor1PinA = 7;    // H-bridge leg 1 
const int motor1PinB = 8;    // H-bridge leg 2 

const int motor2PinA = 2;    // H-bridge leg 1 
const int motor2PinB = 3;    // H-bridge leg 2 

#include <VirtualWire.h>
void setup()
{
Serial.begin(9600);
   pinMode(motor1PinA, OUTPUT);
   pinMode(motor1PinB, OUTPUT);
   pinMode(motor2PinA, OUTPUT);
   pinMode(motor2PinB, OUTPUT);

   vw_set_ptt_inverted(true); // Required for DR3100
   vw_set_rx_pin(12);
   vw_setup(4000);  // Bits per sec
   pinMode(13, OUTPUT);

   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
   {
     Serial.println(buf[0]);
     if(buf[0]=='1'){

 
     digitalWrite(motor1PinA, HIGH);   // set leg 1 of the H-bridge low
     digitalWrite(motor1PinB, LOW);  // set leg 2 of the H-bridge high
     digitalWrite(motor2PinA, LOW);   // set leg 1 of the H-bridge low
     digitalWrite(motor2PinB, HIGH);  // set leg 2 of the H-bridge high
     }  
     if(buf[0]=='2'){
        digitalWrite(motor1PinB, LOW);   // set leg 1 of the H-bridge low
     digitalWrite(motor1PinA, HIGH);  // set leg 2 of the H-bridge high
     digitalWrite(motor2PinB, HIGH);   // set leg 1 of the H-bridge low
     digitalWrite(motor2PinA, LOW);  // set leg 2 of the H-bridge high

   }

  if(buf[0]=='0'){
        digitalWrite(motor1PinB, LOW);   // set leg 1 of the H-bridge low
     digitalWrite(motor1PinA, LOW);  // set leg 2 of the H-bridge high
     digitalWrite(motor2PinB, LOW);   // set leg 1 of the H-bridge low
     digitalWrite(motor2PinA, LOW);  // set leg 2 of the H-bridge high

   }

}

}