Welcome to the 3rd part of RF Communication tutorial. In the last two parts
I have introduced the basics of RF Communication.

Part III will be covering mostly the practical part, i.e. we will build a complete
& working data transfer system. Here you will get circuit and program to
implement the solution. The application is very simple in this case, just to
transfer a byte of data from Tx station to the Rx station. Once you implement
it and get it working you will have enough information and experience to make
other RF based projects.

I request all users to follows the instruction exactly as given (unless they
are smart enough to know what they are doing). The most important thing in this
article is timing of the MCU, so

  • Use the exact frequency crystals as used in the designs.
  • Write High Fuse = C9 (HEX Value) and Low Fuse FF
    (HEX Value) to enable external crystal.


We will have two units. One is Tx (Transmitter) and Other is Rx (Receiver).
Both units are based around ATmega16 MCU(you can use ATmega32 also) on external
16MHz crystal. On the Tx unit PORTC will act as input. While in Rx unit it will
act as output. The value at PORTC of TX unit is constantly sent over the air
to the RX unit where it is latched on its PORTC. That means whatever value you
put in the PORTC of Tx station is available on PORTC of Rx station (8bits or
1 byte). We will connect 8 micro
on the PORTC of Tx station and 8 leds
on the PORTC of Rx station. For testing you can press keys on the Tx side and
corresponding LED on the Rx side will glow. Simple!

You can then use the same techniques of sending/receiving data in any other
application, like SWARM robotics.

RF Module Interface with AVR ATmega

RF Module Tx + AVR ATmega16


AVR Atmega interface with RF Module

RF Module Rx + AVR ATmega16

The above two schematic gives detailed connection of AVR ATmega16
(or ATmega32)
MCU with RF Modules.

ASK RF Modules

RF Modules


Note About the Schematic

  1. Power PINs of MCU are not shown but must be connected properly.
  2. BC548(NPN) transistor and two 4.7K resistor forms a very simple NOT
    . This is because in RS232
    the "idle" state is HIGH to make idle state LOW
    we have use the inverter.
  3. You can use a low
    cost ready made avr development board
    for quick and easy experimentation.(like
    ). It has inbuilt power supply, crystal, reset circuit and ISP port(and
    much more) Only you have to connect the transistor and RF modules that’s it!
    You can easily program the MCU by using USB
    AVR Programmer
AVR ATmega16 RF module circuit

RF Communication Test


The software is written in C language and compiled using the open source compiler
avr-gcc. For project management AVR Studio was used. I have used my fully buffered,
interrupt driven USART library for usart related job. The library comes in two

  • USART.c
  • USART.h

These files must be copied to the current project folder and added to AVR Studio
Project. How to add a file to avr studio project is given here.

Some important functions of USART library are as follows


Initializes the USART of AVR MCU. The parameter is the UBRR value. What is
UBRR? Its not the topic of this article! I assume that you know about the
Basics of RS232 communication and have knowledge of USART. Don’t worry much
if you don’t know that. Just leave this article and read the following articles


This function sends a byte of data over the Tx channel.


Returns the number of byte of data currently waiting in the fifo queue.


Reads and returns a byte of data from the buffer.

Complete Listing of Tx.c

#include <avr/io.h>
#include <util/delay.h>

#include "usart.h"

void main()
   //Initialize the USART with Baud rate = 2400bps

   //Enable Internal Pullups on PORTC


   Keep transmitting the Value of Local PORTC
   to the Remote Station.

   On Remote RX station the Value of PORTC
   sent on AIR will be latched on its local PORTC

   uint8_t data;

      Now send a Packet
      Packet Format is AA<data><data inverse>Z

      total Packet size if 5 bytes.

      //Stabilize the Tx Module By Sending JUNK data
      UWriteData('J');  //J for junk

      //Send 'A'

      //Send Another 'A'

      //Send the data;

      //Send inverse of data for error detection purpose


      //End the packet by writing 'Z'

      //Wait for some time

Complete Listing of Rx.c

#include <avr/io.h>

#include "usart.h"

void main()

   uint8_t i; //Clasical loop varriable

   uint8_t packet[5],data=0;

   DDRC|=0xFF; //All Output

   //Initialize the USART with Baud rate = 2400bps

   Get data from the remote Tx Station
   The data is the value of PORTC on Remote Tx Board
   So we will copy it to the PORTC of this board.


      //Wait for a packet
      if(UReadData()!='A') continue;
      if(UReadData()!='A') continue;


      //Get the packet


      //Is it ok?
      if(packet[2]!=((uint8_t)~packet[3])) continue;

      if(packet[4]!='Z') continue;

      //The packet is ok


      //Now we have data put it to PORTC




Comming soon !



Avinash Gupta

My Facebook Profile

ASK RF Modules

RF Modules