Hi everyone,
I have 2 Arduinos (one Arduino Nano connected to my PC, and an Arduino pro Mini which will receive the data through RF)
I bought a pair of transmitter/receiver 433Mhz, and I’m using Virtualwire libraries. The models are:
- receiver: RX-XD 5v
- transmitter: XD-FST (FS1000A)
I’m sending data from hyperterminal to my Arduino Nano, and it lights a led when it receives string “ocho” (ok).
The problem is I can’t make the transmision work!! I attach the code of the rx and tx, and 2 photos of the protoboards with the Arduinos. I hope someone can help! I suspect of the antennas, I tried different lenghts (18 cm, 30 cm, eg), but i’m using small wires, maybe this is a problem? Or using jumper wires can make them not work at all? (I tried bringing them very close and nothing…)
// RX:
#include <VirtualWire.h>
int pos = 0;
int ledOcho=3;
int ledRx=5;
int ledGrabOK=10;
int pataRx=8;
void setup()
{
vw_set_ptt_inverted(true);
vw_setup(2000);
vw_set_rx_pin(pataRx);
vw_rx_start();
pinMode(ledOcho, OUTPUT);
pinMode(ledRx,OUTPUT);
pinMode(ledGrabOK,OUTPUT);
}
void loop()
{
byte buf[VW_MAX_MESSAGE_LEN];
byte buflen = VW_MAX_MESSAGE_LEN;
int i;
String numeroPedido="";
digitalWrite(ledGrabOK,HIGH);
// enters if receives data:
if( vw_get_message(buf, &buflen) )
{
digitalWrite(ledRx,HIGH);
for (i = 0; i < buflen; i++)
{
if ((char)buf[i]=='.'){ break; }
numeroPedido= numeroPedido +(char)buf[i];
}
if (numeroPedido=="ocho"){ digitalWrite(ledOcho,HIGH); }
else{digitalWrite( ledOcho,LOW); }
numeroPedido="";
digitalWrite(ledRx,LOW);
}
}
// TX
#include <VirtualWire.h>
// Variables globales
char cad[100];
int i=0;
String cadena="";
int ledOcho=2;
int pataTx=6;
int answer=0;
int ledTx=10;
void setup()
{
vw_set_ptt_inverted(true);
vw_set_tx_pin(pataTx);
Serial.begin(9600); // Abre el puerto serie a 9600 bps
vw_setup(2000); // Abre el puerto RF a 2000 bps
pinMode(ledOcho, OUTPUT);
pinMode(ledTx,OUTPUT);
Serial.print("Finalice con \".\" cada envio de datos.");
}
void loop()
{
// Indica cuantos caracteres hay en el buffer:
if( Serial.available() > 0)
{
cad[i] = Serial.read();
Serial.print(char(cad[i] ));
cadena = cadena + cad[i];
i++;
}
if( cad[i-1] == '.')
{
cad[i] = '\0';
i=0;
if (cadena == "ocho."){
digitalWrite(ledOcho, HIGH);
}
else{
digitalWrite(ledOcho,LOW);
}
cadena = "";
answer=vw_send((byte *)cad, strlen(cad));
digitalWrite(ledTx,answer);
answer=0;
vw_wait_tx();
delay(200);
}
}
The receiver should light ledRX when vw_get_message(buf, &buflen) get true, but never happens.
I tried not setting: vw_set_ptt_inverted(true); , nothing
Mariana