Hello, I am trying to control an arduino using virtual wire and I'm having trouble with my code. My transmitter is connected to the computer and I'm trying to send things like: 'a' or 'b' through the serial. The second arduino should receive these and turn an led on and off. What could be the problem?
Transmitter:
#include <VirtualWire.h>
#undef int
#undef abs
#undef double
#undef float
#undef round
void setup()
{
Serial.begin(9600);
Serial.println("Activated");
vw_set_ptt_inverted(true);
vw_setup(2000);
vw_set_tx_pin(13);
}
void loop()
{
if (Serial.available() > 0)
{
char message = Serial.read();
vw_send((uint8_t *)&message, 1);
vw_wait_tx();
}
}
Receiver:
#include <VirtualWire.h>
#undef int
#undef abs
#undef double
#undef float
#undef round
void setup()
{
vw_set_ptt_inverted(true);
vw_setup(2000);
vw_set_rx_pin(12);
vw_rx_start();
pinMode(13, OUTPUT);
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen))
{
if (buf[buflen] == 'a') {
digitalWrite(13, HIGH);
}
if (buf[buflen] == 'b') {
digitalWrite(13, LOW);
}
}
}