Loading... Please wait...

433 Mhz Communication Between Arduinos

433 Mhz Communication Between Arduinos

This example shows how to use a 433Mhz Transmitter/Receiver as supplied in the oddWires Pro kit and above to talk between two Arduinos. There is another exmaple on using the transmitter to control n AC Mains switch here.

Hardware Required

  • Arduino Board x 2
  • 433Mhz Transmitter/Receiver pair
  • Male-Female jumper wires

Circuit

To build the circuit connect transmitter Vcc to +5V, GND to GND and DATA to Arduino pin 10. On the second Arduino connect Vcc to +5V, GND to GND and DATA to pin 2.

wiring-transmitter.png

wiring-receiver2.png

 

Transmitter Code

// oddWires: this is a simple exmaple that shows the 433Mhz module working. It sends a simple message to the receiver

#include

void setup()
{
  // Initialise the IO and ISR
  vw_set_ptt_inverted(true);               // Required for RF Link module
  vw_set_tx_pin(10);                       // pin 10 is used as the transmit data out to the TX Link module,

                                           // change this to suit your needs.
}

void loop()
{
  rfSend("this is a test");
  delay(5000);
}


void rfSend(String message)
{
  char output[100];

  message.toCharArray(output, 99);

  vw_setup(2000);
  vw_send((uint8_t *)output, strlen(output));
  vw_wait_tx();                          // Wait for message to finish
  vw_setup(40);
}

 

Receiver Code

// oddWires: this is a simple example that shows the 433Mhz module working. It receives simple message from the transmitter

#include

#define rxPin 2


const int ledPin =  13;      // the number of the LED pin
int ledState = LOW;          // ledState used to set the LED
long onMillis = 0;           // will store last time LED was updated


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

  // Initialise the IO and ISR
  vw_set_ptt_inverted(true);          // Required for RX Link Module
  vw_setup(2000);                     // Bits per sec
  vw_set_rx_pin(rxPin);               // We will be receiving on pin 2 ie the RX pin from the module connects to this pin.
  vw_rx_start();                      // Start the receiver
}

void loop()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

  if (vw_get_message(buf, &buflen))   // check to see if anything has been received
  {
    int i;
    // Message with a good checksum received.

    for (i = 0; i < buflen; i++)
    {
      Serial.print((char)buf[i]);     // print the received data stored in buffer to the serial monitor
    }
    Serial.println(" ");
    digitalWrite(ledPin, HIGH);
    onMillis = millis();
  }

  if (millis() - onMillis > 100 && onMillis > 0)
  {
    onMillis = 0;
    digitalWrite(ledPin, LOW);
  }
}

 

 

What's News

newsletter

Copyright 2019 oddWires. All Rights Reserved.
 Sitemap | oddWires