Wireless Communication in Arduino Using RF Communication

In my previous article I already made a deep drive into how to use a WPF app to communicate with your Arduino. In that article, I also mentioned about the possible ways to make it wireless. This article will guide you mainly through the hardware setups of the Arduino and explain a method that will help the WPF app to communicate with the Arduino wirelessly. As already mentioned, the WPF app won't change a bit. All changes will be reflected to the Arduino's circuit and the code to be burnt into it. The reason that I am writing this article is, you won't definitely like a wired system. What would you prefer?

  1. A wired system?
  2. A wireless system? 

Definitely you won't like to handle some rolls of wires for your application, you will use only what is required. From the developer's point of view, besides concentrating on the controlling app, one must also pay very much attention to the design of the system. In that way you will be able to develop more efficient controllers. Let's begin this article by explaining the various methods available to develop a wireless manually controlled embedded system. Don't freak out. In simple terms, I am referring to the possible methods to convert your wired systems to a wireless systems. Besides explaining the methods, I will also deal with one of the methods to be discussed below in a more detailed fashion.

Methods applied to develop a wireless system

1. Bluetooth pairing: In this technique, we add a Bluetooth device to the Arduino. In the majority of cases we use a HC05 or a HC06 Bluetooth module. These modules (HC05, HC06) are paired with our controlling software using some API. Then we send characters to the Bluetooth device from our controller. The Bluetooth device uses the dedicated Rx and Tx pins of the Arduino to initiate the commands or functions pertaining to the characters received. Figure 1 shows a block diagram of how the communication takes place.

wireless bluetooth link
Figure 1: Block diagram of the system

This article won't cover much of Bluetooth, that's a subject for another article. We will be dealing with the second category here.

2: Using a RF module: A Radio Frequency (RF) module deals with the use of high frequency signals for communication. The frequency that I have used is 2.4GHz. In this module we have two devices. The first device is for the use with our microcontroller or microprocessor (in this case it's the Arduino) named the serial link. The other part is the device that needs to be used with the application. It's a USB link. The USB link will establish the connection between our controlling application and the serial link. Let's see the block diagram as shown in Figure 2. This will clarify things.

wireless link
Figure 2: Block diagram for RF modules.

The preceding figure will hopefully clarify things to a certain level, but not completely because of the fact that once you do this in reality, it will be crystal clear. However, it's much similar to the wired connection with the only difference that the USB wire is basically the USB and the serial link.

What the USB and Serial link Are

USB link: The USB link is basically a hardware module that is connected to the computer via the USB port. This establishes a connection to its counterpart, the Serial link. While shifting to wireless by this RF module, you need not change any code of the controlling application that is required when using Bluetooth. Figure 3 shows a USB 2.4GHz USB link. Please see that the picture is obtained from www.robokits.co.in. I am loyal to this site to buy my components.

Figure 3: USB 2.4 GHz link. The product can be bought from.

You need to configure the device by downloading a configuration software. You can download it from here, in the configuration software, you need to set the device's Baud rate and the frequency. The Baud rate and frequency set here must be same to that of the serial link.

Serial link: The serial link is the one that will be connected to the microcontroller. First let's see the picture. Figure 4 shows the picture of the serial link as shown in www.robokits.co.in.

Figure 4: Serial link 2.4GHz.

As in the picture, the device have 4 pins namely Vcc, Gnd, Rx and Tx. This device operates both on 5V as well as 3.3V. Connections are shown in the form of block diagrams in Figure 5.


Figure 5: Connections for the wireless module.

As shown in the preceding figure (I did a block diagram rather than showing you the actual schematic. The block diagram will be enough for you to understand), the Gnd pin of the device is connected with the Gnd pin of the Arduino, the Vcc pin is connected to the 5V or the 3.3V pin on the Arduino board. The Rx pin is connected to pin to the Tx pin on the Arduino (Pin 1) and the Tx pin is connected to the Rx pin of the Arduino (Pin 0). That's it, the connections are done. The signal received from the USB link is transferred to the Arduino by the Tx pin of the serial link and the Rx pin to the Arduino. Similarly, when information needs to be sent to the controller application, the Tx pin of the Arduino sends the signal to the serial link and the serial link sends it to the USB link and ultimately we see the signal on our controller application.

Once you complete this setup, your hardware part is complete. However some problem arises when using a RF communication channel, like signals aren't received. In that case the best troubleshooting method is as follows.

  1. Switch off the main power of the Arduino.
  2. Disconnect the USB link by pressing the disconnect button.
  3. Remove the USB link and insert it again.
  4. Reconnect the USB link using the connect button.
  5. Turn on the power of the Arduino. 

You can apply any technique you feel like, but trust me, this is the best way as I have experienced these many times while displaying my project and this method works like a charm. The problem mainly occurs when you have any actuators attached to the Arduino, like a DC motor mainly because of back EMF. In case you need another power source rather than the one for the Arduino then turning off the main power source will be the first thing you need to do and at the end turn on the main power.

Coding for the Arduino

Until now I have showed you how the device works, mainly the hardware part. This section will be dedicated on the code. For serial communication, Arduino has some dedicated libraries. In this type of project, where you need to use wireless serial communication, the code may differ from device to device. Arduino UNO and Arduino Leonardo are the most widely used devices. Let's see the code for Arduino UNO first. All the codes are written in the Arduino IDE by the Arduino processor language.

  1. void setup()   
  2. {  
  3.   pinMode(13, OUTPUT);  
  4.   Serial.begin(9600);  
  5. }  
  6.   
  7. void loop()   
  8. {  
  9.   if(Serial.available()>0)  
  10.   {  
  11.     char c = Serial.read();  
  12.     if (c == '1')  
  13.     {     
  14.       digitalWrite(13,HIGH);  
  15.     }  
  16.     else if (c == '0')  
  17.     {  
  18.       digitalWrite(13,LOW);  
  19.     }    
  20.   }  
  21. }  
Well, you don't find much of a difference, right? Actually there is no difference in the case for the Arduino UNO. The function is the same in both cases. That is, they are the same whether using the USB wired communication or the communication involving the Serial pins that is 0 and 1. The changes appear for the Arduino Leonardo. In this case the change is simply replacing Serial with Serial1.

In the case of Arduino Leonardo, when using the USB wired communication, you need to use Serial, but in the case of using the Rx and Tx pins for wireless connection, you need to use Serial1. That's the difference between the two. The following is the code:

  1. void setup()   
  2. {  
  3.   pinMode(13, OUTPUT);  
  4.   Serial1.begin(9600);  
  5. }  
  6.   
  7. void loop()   
  8. {  
  9.   if(Serial1.available()>0)  
  10.   {  
  11.     char c = Serial1.read();  
  12.     if (c == '1')  
  13.     {     
  14.       digitalWrite(13,HIGH);  
  15.     }  
  16.     else if (c == '0')  
  17.     {  
  18.       digitalWrite(13,LOW);  
  19.     }    
  20.   }  
  21. }  
As a summary, this article covered the technique of using wireless communication. RF communication was discussed in detail. You can use these techniques for developing your own advanced IoT system using wireless communication. IoT is really the game changer. With various devices like that of Intel Galileo and Arduino and by the use of apps that are used to control these devices wirelessly, my guess is that the future is now. If you want to see the video of a working example, please visit this YouTube video where I used this concept to develop my very first UGV. The wire that is seen in the video is not for controlling but for providing power to the UGV.

Up Next
    Ebook Download
    View all
    Learn
    View all