Radio Frequency Transmitter & Receiver Module with Arduino

Starting point how to use wireless radio frequency transmitter & receiver modules.

img_20171210_162144_2PoR0iMdMS

1. Download RadioHead library:

http://www.airspayce.com/mikem/arduino/RadioHead/index.html

http://www.airspayce.com/mikem/arduino/RadioHead/RadioHead-1.81.zip

kuvatommis_2017-12-10_16-29-08_bUwlvJOcgO

Unzip and copy it into Arduino library folder:

kuvatommis_2017-12-10_16-33-33_zPfWXossMX

Now you should to see RadioHead example code:

kuvatommis_2017-12-10_16-40-14_krQKy8QrP0

2. Transmitter module:

img_20171210_165027_VXJzZKVjXv

Antenna lenght depens do you have 315, 330 or 433 MHz module. Best is to use the antenna of 1/4 wavelength (or 1/2, 1/8).

Online calculator: http://www.onlineconversion.com/frequency_wavelength.htm

  • 315MHz wavelenght is 0.95 m, 1/4 = 23.75 cm
  • 330MHz wavelenght is 0.91 m, 1/4 = 22.75 cm
  • 433MHz wavelenght is 0.69 m, 1/4 = 17.25 cm

Youse single core wire. Antennas should be on same orientations. Both of them horizontal or vertical.

3. Receiver module

img_20171211_203148_Hua6QHdUWl

4. Transmitter test circuit

img_20171211_211003_su1fO40zcj

Transmitter Test Code:

#include  
#include   
const char *message = ""; 
int button = 2; 
RH_ASK driver; 
void setup() { 
 Serial.begin(9600); // Debugging only 
 if (!driver.init()){ 
   Serial.println("init of receiver failed"); 
 } 
 pinMode(button,INPUT); 
} 
void loop(){ 
 if (digitalRead(button) == HIGH){ 
   message="a"; 
   driver.send((uint8_t *)message, strlen(message)); // send the message 
   driver.waitPacketSent(); // Wait until the whole message is gone 
   Serial.println(message); 
   Serial.println(strlen(message)); 
   delay(2000); 
   } 
  else{ 
   //Serial.println("Low"); 
     } 
}

5. Receiver test circuit

img_20171211_212156_un9IpoEeQn

Receiver Test Code:

#include <RH_ASK.h> 
#include <SPI.h>  
RH_ASK driver; //pin 12
// RH_ASK driver(2000, 2, 4, 5); // ESP8266: do not use pin 11 
int ledPassive = 5; //standby light 
int ledActive = 7; //green LED's 
void setup() 
{ 
 pinMode(ledPassive,OUTPUT); 
 pinMode(ledActive,OUTPUT); 
 Serial.begin(9600); // Debugging only 
 if (!driver.init()) 
 Serial.println("init of receiver failed"); 
} 
void loop() 
{ 
 digitalWrite(ledPassive,HIGH); 
 noTone(8); 
 digitalWrite(ledActive,LOW); 
 uint8_t buf[RH_ASK_MAX_MESSAGE_LEN]; 
 uint8_t buflen = sizeof(buf); 
 if (driver.recv(buf, &buflen)) { // if message received 
   for(int i=0;i<sizeof(buf);i++){ 
     Serial.print(char(buf[i])); //test display output 
   } 
   if(buf[0]=='a'){ // and if the first letter in message array is X 
     digitalWrite(ledPassive,LOW); 
     for(int i=0;i<10;i++){ // loop alternates between LED and buzzer 
       digitalWrite(ledActive,HIGH); 
       tone(8, 262); //pin 8
       delay(100); 
     } 
   } 
    else if(buf[0]!='a'){ 
     digitalWrite(ledPassive,HIGH); 
     noTone(8); 
    } 
   } 
} 

And the result:

Originally published: https://www.hackster.io/taunoerik/radio-frequency-transmitter-receiver-module-with-arduino-af01e4

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.