Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Data receiver sketch
// data receiver sketch
#include <VirtualWire.h>
// use onboard LED for status
const int ledPin = 13;
int Sensor1Data;
// holds data from receiver
char Sensor1CharMsg[4];
void setup() {
pinMode(ledPin, OUTPUT);
vw_setup(2000); // data speed in bps
vw_set_rx_pin(11); // receiver data pin to digital 11
void loop() {
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen))
int i;
// LED on to indicate message coming in
digitalWrite(13, true);
for (i = 0; i < buflen; i++)
// fill array with data from receiver
Sensor1CharMsg[i] = char(buf[i]);
// null terminate the char array, indicates the end of the data
Sensor1CharMsg[buflen] = '\0';
// convert data in array to a usable integer
Sensor1Data = atoi(Sensor1CharMsg);
// send data to serial monitor
Serial.print("tx analog pin 1 reads: ");
// message reception finished, turn off onboard LED
digitalWrite(13, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.