Using Virtual Wire with RF Transmitters

I am using a 433 Mhz RF transmitter and receiver with the Virtual Wire library. I had it working sending single characters before, but once I implemented that code for use in the actual project, it stopped working. Now I am going back to square one to troubleshoot and for some reason I can only receive the character ‘a’. So here is code I’m using right now which sends ‘a’, ‘b’, ‘a’, ‘b’… and so on. And it’s supposed to receive that and print it back.

TRANSMITTER:

#include <VirtualWire.h>

void setup() {
vw_setup(2000);
vw_set_tx_pin(7);
vw_set_ptt_inverted(true);

}

void loop() {
char c = ‘a’;
digitalWrite(13, HIGH);
vw_send((uint8_t *)c, 1);
vw_wait_tx();
digitalWrite(13, LOW);
delay(100);

c = ‘b’;
digitalWrite(13, HIGH);
vw_send((uint8_t *)c, 1);
vw_wait_tx();
digitalWrite(13, LOW);
delay(100);
}


RECEIVER:

#include <VirtualWire.h>

void setup() {
Serial.begin(9600);

vw_setup(2000);
vw_set_rx_pin(7);
vw_set_ptt_inverted(true);
vw_rx_start();

Serial.println(“Setup”);

}

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

if(vw_get_message(buf, &buflen)){
for(int i = 0; i<buflen; i++){
if(buf == ‘a’){

  • Serial.println(“a”);*
  • }*
    _ else if(buf == ‘b’){_
    * Serial.println(“b”);*
    * }*
    * }*
    * }*
    }
    I would expect to get an output of:
    Setup
    a
    b
    a
    b
    But instead I just get:
    Setup
    a
    a
    a
    a
    I have tried sending many other bytes as well and it seems that ‘a’ is the only message its capable of sending successfully. If anyone has some idea of what is wrong please help.

Some suggestions.

Send '1' and '2'. See what happens. Serial.print() what you receive. Post code in code tags. I doubt that your code has italics in it.

I'm working on a project using 433Mhz, if your not to embedded with your existing code this thread helped me http://forum.arduino.cc/index.php?topic=313587.0 , it uses the more recent library "RadioHead". Virtual Wire is redundant.