Tuesday 24 November 2015

Simple RF Device

You want to have a remote control device but you don't have enough money and you are the creative one? Why don't you create your own remote control device? Here I would like to share about my simple idea to create a simple remote control device. I made a simple remote LED controlller using components that I think are not expensive and easy to find.

Step 1: Gather some needed components


1x a pair of RF Module (xd-fst (transmitter) and xd-rf-5v (receiver))
2x Arduino (I used Arduino UNO as receiver and Mega2560 as transmitter)
1x LED
1x Push Button
1x 10k Resistor
1x ProtoBoard
~x Cable Jumper (I used cable UTP)

Step 2: Wiring 

We will be create two devices for this project, one for receiver device and another for transmitter device.

Receiver:

1x RF Receiver Module (xd-rf-5v)
1x Arduino (I used Arduino UNO)
1x LED
~x Cable Jumper

Transmitter:

1x RF Transmitter Module (xd-fst)
1x Arduino (I used Arduino Mega2560)
1x Push Button
1x 10k Resistor
~x Cable Jumper

And after combine all components, the result will be like:

Step 3: Coding

There will be two types of code we will use, one for receiver and another for transmitter.

Receiver:
 #include <VirtualWire.h>  
 void setup()  
 {  
   Serial.begin(9600);     // Configure the serial connection to the computer  
   vw_set_ptt_inverted(true); // Required by the RF module  
   vw_setup(2000);      // bps connection speed  
   vw_set_rx_pin(3);     // Arduino pin to connect the receiver data pin  
   vw_rx_start();      // Start the receiver  
   pinMode(12, OUTPUT);  // Set LED to pin 13 in UNO  
 }  
 void loop()  
 {  
  uint8_t buf[VW_MAX_MESSAGE_LEN];  
  uint8_t buflen = VW_MAX_MESSAGE_LEN;  
  if (vw_get_message(buf, &buflen))   // We check if we have received data  
  {  
   int i;  
   // Message with proper check    
   for (i = 0; i < buflen; i++)  
   {  
    //Serial.write(buf[i]); // The received data is stored in the buffer  
                // and sent through the serial port to the computer  
    if (buf[i] == 'a'){  
     digitalWrite(12, HIGH);  
     Serial.write(buf[i]); // If you want to see the received message  
    }  
    else{  
     digitalWrite(12, LOW);  
     Serial.write("No message is received");  
    }  
   }  
   Serial.println();  
  }  
 }  

Transmitter:
 #include <VirtualWire.h>  
 int button = 2;  
 void setup()  
 {  
   pinMode(button, INPUT);   // Setting A0 as Input  
   vw_set_ptt_inverted(true); // Required by the RF module  
   vw_setup(2000);      // bps connection speed  
   vw_set_tx_pin(3);     // Arduino pin to connect the receiver data pin  
 }  
 void loop()  
 {  
   if(digitalRead(button) == HIGH){  
    // Message to send:  
    const char *msg = "a";  
    vw_send((uint8_t *)msg, strlen(msg));  
    vw_wait_tx();    // We wait to finish sending the message  
   }  
   else{  
    // Message to send:  
    const char *msg = "b";  
    vw_send((uint8_t *)msg, strlen(msg));  
    vw_wait_tx();     // We wait to finish sending message  
   }  
   delay(10);     // We wait to send the message again          
 }  

I used Arduino virtual wire library, #include <VirtualWire.h>, to call functions that required for wireless communication. You can see the complete guide for this library here.

Step 4: Testing

After all code and wiring are done. Let's try our device.


You can improve this project as you wish with your own creative idea.

No comments:

Post a Comment