433 Mhz example

using two Arduinos to send data over RF

the code:
transmitter:

#include <VirtualWire.h>

const int TX_DIO_Pin = 2;
unsigned   int Data2 = 0;

void setup()
{
  pinMode(13, OUTPUT);
  pinMode(10, OUTPUT);
  Serial.begin(9600);

  vw_set_tx_pin(TX_DIO_Pin);

  vw_set_ptt_inverted(true); 

  vw_setup(2000);  
}

void loop()
{
  unsigned int Data;
  //  unsigned int Data2;

  byte TxBuffer[4];

  Data = 33;
  // Data2 = 55;
  Data2++;
  if (Data2 ==11 ) Data2=0;

  TxBuffer[0] = Data >> 8;
  TxBuffer[1] = Data;
  TxBuffer[2] = Data2 >> 8;
  TxBuffer[3] = Data2;

  digitalWrite(13, HIGH); 
  digitalWrite(10, HIGH); 

  vw_send((byte *)TxBuffer, 4);

  vw_wait_tx(); 
  delay(30);
  Serial.print(" device: ");
  Serial.print(Data);
  Serial.print("    mesg: "); 

  Serial.println(Data2);
  digitalWrite(13, LOW); 
  digitalWrite(10, LOW); 
}

receiver:

#include <VirtualWire.h>

const int RX_DIO_Pin = 2;
unsigned int Data;
unsigned int Data2;

void setup() 
{
  pinMode(13, OUTPUT);
  pinMode(10, OUTPUT);
  Serial.begin(9600);

  vw_set_rx_pin(RX_DIO_Pin);

  vw_setup(2000);

  vw_rx_start(); 
}

void loop() 
{
  uint8_t Buffer_Size =4;
  uint8_t RxBuffer[Buffer_Size];

  delayMicroseconds(1);

  if (vw_get_message(RxBuffer, &Buffer_Size)) 
  {
    digitalWrite(13, HIGH);
    digitalWrite(10, HIGH);

    Data = RxBuffer[0] << 8 | RxBuffer[1];
    Data2 = RxBuffer[2] << 8 | RxBuffer[3];

    Serial.print(" device: ");
    Serial.print(Data);
    Serial.print("    mesg: "); 

    Serial.println(Data2);

    digitalWrite(13, LOW);
    digitalWrite(10, LOW);
  }
}

update moderatore: reformatted the code to be more readable… (CTRL-T in the IDE)

thanks for sharing