I was wondering if it was possible to work, in the same Arduino board, both Transmitter and Receiver RF 433 MHz modules. Is it feasible?
Here is the schematics I tried:
1) a pushbutton toggles a state value (0 or 1) and triggers the RF transmitter to send it as a message to the receiver module
2) the RF receiver, whenever reading the message, turns on or off a LED according to the corresponding value (0 or 1)
Here is the source code I wrote:
#include <VirtualWire.h>
#define BTN_PIN A0 // pushbutton que aciona a transmissao
#define LED_PIN 13 // LED aceso ao receber o sinal
#define TX_PIN 4 // ligado ao pino DATA do transmissor RF
#define RX_PIN 7 // ligado ao pino DATA do receptor RF
#define SPEED 5000 // velocidade de comunicacao (bits por segundo)
int estado = 0;
void setup() {
pinMode(BTN_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
vw_set_tx_pin(TX_PIN); // transmissor
vw_set_rx_pin(RX_PIN); // receptor
vw_setup(SPEED);
vw_rx_start();
Serial.begin(9600);
}
void loop() {
int pressionado = !digitalRead(BTN_PIN);
char msg[4];
if (pressionado) {
estado = !estado;
itoa(estado, msg, 10);
vw_send((uint8_t *) msg, strlen(msg));
vw_wait_tx();
Serial.print("Mensagem enviada: [");
Serial.print(msg);
Serial.println("]");
delay(500);
}
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
int recebido = 0;
memset(msg, 0, 4);
if (vw_get_message(buf, &buflen)) {
for (int i = 0; i < buflen; i++)
msg[i] = char(buf[i]);
msg[buflen] = '\0';
Serial.print("Mensagem recebida: [");
Serial.print(msg);
Serial.println("]");
recebido = atoi(msg);
Serial.print("recebido = ");
Serial.println(recebido);
digitalWrite(LED_PIN, recebido);
}
}
When I run it, according to Serial Monitor it sends the message. The problem is no message comes to the RF receiver.
Does anyone have an idea of what could be wrong?