Skip to content

Instantly share code, notes, and snippets.

@johnaboxall
Last active August 29, 2019 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnaboxall/88bdbfed51b2730475c2ba70d30828c0 to your computer and use it in GitHub Desktop.
Save johnaboxall/88bdbfed51b2730475c2ba70d30828c0 to your computer and use it in GitHub Desktop.
VirtualWire receiver test sketch
// receiver.ino
//
// https://pmdway.com/blogs/product-guides-for-arduino/tutorial-using-long-range-315mhz-rf-wireless-transceivers-with-arduino
//
// Simple example of how to use VirtualWire to receive messages
// Implements a simplex (one-way) receiver with an Rx-B1 module
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2008 Mike McCauley
// $Id: receiver.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
#include <VirtualWire.h>
const int led_pin = 2;
const int transmit_pin = 12;
const int receive_pin = 11;
const int transmit_en_pin = 3;
void setup()
{
delay(1000);
Serial.begin(9600);
Serial.println("setup");
// Initialise the IO and ISR
vw_set_tx_pin(transmit_pin);
vw_set_rx_pin(receive_pin);
vw_set_ptt_pin(transmit_en_pin);
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
pinMode(led_pin, OUTPUT);
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
digitalWrite(led_pin, HIGH); // Flash a light to show received good message
// Message with a good checksum received, dump it.
Serial.print("Got: ");
for (i = 0; i < buflen; i++)
{
Serial.print(buf[i], HEX);
Serial.print(' ');
}
Serial.println();
digitalWrite(led_pin, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment