Go Down

Topic: wrong code Rx Tx 433Mhz (Read 39 times) previous topic - next topic

bmarius

I want to use the 433Mhz RX-TX Kit for a single Arduino nano and I wrote the following code
I want to have two outputs for the LED one for the broadcast one for the reception.
So when the transmission lights up a led and at the reception to light the second flashing LED
Of course does not work, want help.

#include <VirtualWire.h>
char *msg = "123456789123456789";
int i;
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

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

pinMode(12,OUTPUT);
pinMode(8,OUTPUT);
pinMode(6,OUTPUT);
pinMode(4,OUTPUT);

vw_setup(2000);
vw_set_tx_pin(12);  //emitator in
//vw_setup(2000);
vw_set_rx_pin(8);   //receptor in
vw_rx_start();
//Serial.println("Starting up");
digitalWrite(6,HIGH);  //emisie on
}
void loop()     {
vw_send((uint8_t*)msg, strlen(msg));
vw_wait_tx();
delay(500);
if(vw_get_message(buf,&buflen)) {
  for(i=0;i<buflen; i++) {
  Serial.print((char)buf);
digitalWrite(6,LOW);   //emisie off
digitalWrite(4,HIGH);  //receptie on
delay(50);
digitalWrite(4,LOW);
delay(50);
  }
}
}

hammy

Don't you need two devices ? One the transmitter and one the receiver , each with its own code.

No idea what you are using , but these radio type things usually come with a library and examples to get you started . So more info here might help !

Go Up