RF Module

RF Module

Home GPS Module Ultrasonic Module RF Module

RF Module

Criteria:

  1. Using two Arduinos, create sketches to transmit a 12-character string containing one number with a leading ‘X’ and padded with ‘Z’. The receiver should display the numbers and indicate whether the number is even or odd.

Required Hardware

Required Libraries


Useful Links

Link to buy sensors Here

Link to programming tutorial Here

Wiring Diagram


Transmitter sketch to send data to the receiver

#include RH_ASK.h
RH_ASK driver;
void setup()
{
Serial.begin(9600);
if (!driver.init())
{
Serial.println("init failed");
}
}
void loop()
{
// int number = random(0, 100);
String message = "X";
// message += String(number, DEC);
int padding = 12 - message.length();
for (int i = 0; i < padding; i++)
{
message += "Z";
}
const char *msg = "X14ZZZZZZZZZ";
// const char *msg = message.c_str();
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(1000);
}

Sketch to receive data from the transmitter

#include RH_ASK.h
#include SPI.h // Not actualy used but needed to compile
RH_ASK driver;
void setup()
{
Serial.begin(9600); // Debugging only
if (!driver.init())
Serial.println("init failed");
}
void loop()
{
uint8_t buf[12];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) // Non-blocking
{
int i;
// Message with a good checksum received, dump it.
Serial.print("Message: ");
Serial.println((char*)buf);
}
}