Top Banner
Embedded Lab An online teaching laboratory for Microcontrollers and Embedded Systems To search, type and hit en Home Products Theory PIC Experiments PIC Projects Tips & Tricks dsPIC chipKIT Netduino Contact Wireless data transmission between two PIC microcontrollers using low-cost RF modules R-B Sep 9th, 2011 Like 123 people like this. Be the first of your friends. A lot of times we need to keep track of data from a device or a sensor located in a remote location from the point where it is processed. In other situations we desire wireless solutions for ease. Using long cables, infrared (IR) or other means are often tedious and not loss-less. Imagine collecting pH level data from a chemically lethal or toxic treatment plant where human presence is highly health hazardous. Running long cables from the pH sensor to the control or monitor station will surely introduce noisy signals and signal-to-noise ratio will thus drastically decrease. The result is erroneous data acquisition and thereby false decisions may be generated. If infrared signals or other optical means including lasers are used, they will need good obstacle-free line of sight or expensive and delicate optical fibers. Thus the solution stays in the radio frequency (RF) domain. This article talks about interfacing low cost RF modules (KST-TX01 and KST- RX806 ) for transmitting data between two remotely located PIC microcontrollers. Ads by Google Wireless Sensors Embedded System Wireless Module Wireless RS232 PIC Development Board www.mikroe.com EasyPIC v7 - Best seller PIC board for 250 PIC MCUs, rich with modules
11
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: RF

Embedded LabAn online teaching laboratory for Microcontrollers and Embedded Systems

To search, type and hit enter

HomeProductsTheoryPIC ExperimentsPIC ProjectsTips & TricksdsPICchipKITNetduinoContact

Wireless data transmission between two PICmicrocontrollers using low-cost RF modules

R-BSep 9th, 2011

Like 123 people like this. Be the first of yourfriends.

A lot of times we need to keeptrack of data from a device or asensor located in a remotelocation from the point where it isprocessed. In other situations wedesire wireless solutions for

ease. Using long cables, infrared (IR) or other means are often tedious and not loss-less. Imagine collecting pH level data from achemically lethal or toxic treatment plant where human presence is highly health hazardous. Running long cables from the pHsensor to the control or monitor station will surely introduce noisy signals and signal-to-noise ratio will thus drastically decrease.The result is erroneous data acquisition and thereby false decisions may be generated. If infrared signals or other optical meansincluding lasers are used, they will need good obstacle-free line of sight or expensive and delicate optical fibers. Thus the solutionstays in the radio frequency (RF) domain. This article talks about interfacing low cost RF modules (KST-TX01 and KST-RX806) for transmitting data between two remotely located PIC microcontrollers.

Ads by Google Wireless Sensors Embedded System Wireless Module Wireless RS232

PIC Development Boardwww.mikroe.com

EasyPIC v7 - Best seller PIC board for 250 PIC MCUs, rich with modules

Page 2: RF

Data broadcast using RF modules

In this demo, we will see how to achieve an easy data transaction between two PIC16F877A microcontrollers using inexpensiveRF modules. The theory is pretty simple and straight. It uses KST-TX01 and KST-RX806 RF modules which is a 433 MHzserial data transmitter/receiver pair. One PIC16F877A is programmed to transmit its ADC data (RA0/AN0 channel) seriallyusing its built-in USART hardware at 1200 baud with no parity and 8-bit data stream. The PIC’s USART transmitter (TX) pinfeeds the data into the data pin of the KST-TX01 which transmits it using 433 MHz ASK RF signal. On the receiving end theKST-RX806 module receives the data and its output is connected to the another PIC’s USART input pin. The second PIC isprogrammed to read its USART receiver (RX) pin. On both ends, two LCD displays are also connected which show thetransmitted and received bytes. Since RS232 communications typically allow 8-bit data, the 8-bit A/D conversion is used here forsimplicity, instead of the more common 10-bit ADC.

Transmitting unit

Page 3: RF

Receiving unit

Wireless data transmission between two PIC micros

Software

The demo codes given for the receiver and the transmitter PICs are written using CCS PCWHD compiler. The firmwares areeasy to understand and needs no explanation. In CCS PCWHD, the LCD pins are defined in the lcd.c file. By default, it uses thePORTD pins (as shown in the circuit diagram above) as connections to the LCD. If you are using a different port, you need toedit the lcd.c file accordingly.

Receiving side code

#include <16F877A.h>#device *= 16#fuses HS, NOWDT, NOPROTECT, NOLVP, PUT#fuses NOBROWNOUT, CPD, NODEBUG, NOWRT#use delay(clock=10MHz)#use rs232(baud=1200, rcv=PIN_C7, bits=8, parity=N)

Page 4: RF

#include <lcd.c>

void main(){ byte c; lcd_init(); lcd_putc("\f"); while(true) { c=getc(); printf(lcd_putc,"\fRx Data = %u",c); delay_ms(100); }}

Transmitting side code

#include <16F877A.h>#device *= 16#device adc=8#fuses HS, NOWDT, NOPROTECT, NOLVP, PUT#fuses NOBROWNOUT, CPD, NODEBUG, NOWRT#use delay(clock=10MHz)#use rs232(baud=1200, xmit=PIN_C6, bits=8, parity=N)

#include <lcd.c>

void main(){ byte s=0; lcd_init(); lcd_putc("\f"); setup_adc_ports(adc_clock_internal); setup_adc(AN0); set_adc_channel(0); while(true) { read_adc(adc_start_only); while(!adc_done()); s = read_adc(adc_read_only); lcd_gotoxy(1,1); printf(lcd_putc, "\fTx Data = %u" s); putc(s); delay_ms(100); }}

Summary

Thus we saw that KST-TX01 and KST-RX806 RF modules are very easy to use for RF transmission and reception of data asthey can be directly interfaced to the UART port of microcontrollers. However, there are few things that I noted whileexperimenting with them. One is, when the ADC value (8-bit in this demo) is around 250 or higher the receiver starts gettinggarbage data. It seems like when the data contains too many 1s, it is not recognized by the receiver which literally “believes” thatthe data is static. One solution could be dividing the ADC byte into two nibbles and send them separately. It will slow down thenet data transmission rate but the received data will be less likely to be erroneous. It also adds an extra overhead of reconstructingthe bytes from the nibbles. Similarly, if you want to use 10-bit (or more) resolution for A/D conversion, the ADC result can alsobe broken into two 5-bit fragments (MSB 5-bit and LSB 5-bit) before transmission. Adding three extra 0s on the MSB end ofeach fragment completes the transmission byte. By doing so, the numerical value of each data byte will be less than 32.

Another important fact to note is the range of the modules. Many manufactures claim ranges of up to 10m or so. In reality thismay not be what they claim because of the antenna length and the quality of the modules themselves. A wire of 12 inches or so isadequate for a reasonably good wireless communication.

Lastly, I found the two RF modules perform best at 1200 baud. While data transmission at 2400 baud is also possible, it will notbe error free. Baud rates more than that are not useful at all. Several improvements can be done to add more features but I havekept it for those who are willing to explore it more and use it in various purposes.

Page 5: RF

The lesson from this demo can be expanded to a wide range of applications. Here are some common applications:

Remote appliance controllers,Wireless headsets,Remote data acquisition systems,Surveillance and security systems,Robotics,Hands free devices,Digital radios,X-bee and Bluetooth,Navigation systems,Toys and so on.

Many thanks to Shawon Shahryiar for contributing this article toEmbedded Lab. He works as an Engineer in the Research andDevelopment Cell at ELECTRO Group in Dhaka, Bangladesh.You can contact him at:

Random Posts

In-Circuit Debugging of PIC microcontrollersAn In-Circuit Debugger (ICD) is a very powerful and effective tool for real-time debugging of a microcontroller-based sy...

Using Fixed Voltage Reference (FVR) for A/D conversion in enhanced mid-range PIC microcontrollersThe reference voltage plays a very important role in any A/D conversion. It determines both the range and the resolution...

MikroElektronika’s “Ready for PIC” board talks to “Processing”"Ready for PIC" is one of MikroElektronika's compact prototyping boards for 28 and 40 pin PIC microcontrollers. The boar...

Filed under: PIC Tutorials, Tips and Tricks

RSS feed for comments on this postTrackBack URI

18 Responses to this post

1. shivendra kumar sahu on September 10th, 2011 3:33 pm

2

LC RF Filter Design Guidewww.anatechelectronics.com

RF Lumped Element (LC) Filters, acomprehensive white paper, Read!

1202 55 21 4594

Page 6: RF

where is lcd.c file ?

2. R-B on September 10th, 2011 5:15 pm

sahu,

Read this for more info on lcd.c file

http://seng.ulster.ac.uk/eme/sidk/resources/Eejits%20guide%20to%20using%20a%20LCD%20alphanumeric%20display.pdf

3. Electronics-Lab.com Blog » Blog Archive » Wireless data transmission between two microcontrollers using KST-TX01and KST-RX806 rf modules on September 10th, 2011 5:24 pm

[...] data transmission between two microcontrollers using KST-TX01 and KST-RX806 rf modules – [Link] Tags: KST-RX806, KST-TX01, Microcontroller, modules, PIC, RF Filed in Mcu | 1 views No [...]

4. hamid djouahra on September 13th, 2011 10:43 am

thanks RB for your posts about microcontrollers,if you are able to give me a little help and advice about active powermetering using mikroC and PIC18F452;

5. ali raheem on September 13th, 2011 6:52 pm

If streams of constant data is a problem why not try manchester encoding? Each bit (x) is is transmitted twice in effect asx^0 and x^1. Also it’s self clocking

6. R-B on September 13th, 2011 8:26 pm

hamid,I am extremely busy right now to help on this. But you can search online for resources:

http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2138&param=en025183http://atmel.com/dyn/resources/prod_documents/doc2566.pdfhttp://ww1.microchip.com/downloads/en/AppNotes/01291b.pdf

You can implement the concept with whatever microcontroller you want.

7. Wireless data transmission between two PIC microcontrollers using low-cost RF modules | Look4tech.com on October24th, 2011 12:23 pm

[...] more at http://embedded-lab.com/blog/?p=3557 This entry was posted in MCU – Wireless communication and taggedmicrocontroller, PIC, wireless. [...]

8. Roberto Garcia on October 31st, 2011 12:54 pm

Do you have the hex files for this programs so I can program my pics on Mplab?

9. R-B on October 31st, 2011 3:17 pm

Sorry, I don’t. But you can compile the source program provided.

10. Amna91 on November 20th, 2011 9:57 am

can u tell me what other transeciver i can use because the pair u r using is not available in the market….. plz reply [email protected]

11. Amna91 on December 6th, 2011 4:09 pm

the source code given above gives me error can u plz mail me the source code which is error free…[email protected]

12. R-B on December 7th, 2011 9:08 pm

Amna91,

Page 7: RF

I would suggest you to contact Shawon regarding this. His email address is provided at the end of the article.

13. problem with Servo and Stepper motor on December 31st, 2011 9:49 am

[...] to be just 433MHz RF TX & RX pairs. Example of interfacing KSTs to a PIC Microcontrollers: Wireless datatransmission between two PIC microcontrollers using low-cost RF modules BigDog Reply With Quote + Post NewThread + Reply to Thread [...]

14. Razu Ahmmed on December 31st, 2011 2:27 pm

I have tried to make communication between two uc by KST TX01 & KST RX806 according to your connection but withatmega8.I did not find any output.Instead of KST TX01 & KST RX806 when i connect two uc by a wire then myprogram works but when i place KST TX01 & KST RX806 i did not find any output.where could be the problem. mycode in mikroC is followingTX:char uart_rd;

void main(){

UART1_Init(960); // Initialize UART module at 9600 bpsDelay_ms(1000); // Wait for UART module to stabilizewhile (1){UART1_Write_Text(“a”);Delay_ms(1000);}}AND RX:char uart_rd;

void main(){

DDRB=0xFF;PORTB=0×00;UART1_Init(960); // Initialize UART module at 9600 bpsDelay_ms(1000); // Wait for UART module to stabilizewhile (1) { // Endless loopif (UART1_Data_Ready()) { // If data is received,uart_rd = UART1_Read(); // read the received data,if(uart_rd==’a'){PORTB0_bit=~PORTB0_bit;}}elsePORTB4_bit=~PORTB4_bit;}}

15. Majayz on January 20th, 2012 2:35 am

Hi Engineer

im doing a similar project although the difference is that i want the two picocontrollers (PIC16F877A) to be able to sendand receive data from the other.can you help with mikro C code for the realisation of the transmission.

16. hamid djouahra on March 1st, 2012 8:18 am

Page 8: RF

hi RB

thanks for your posts

i am working in an electricity active energy metering system, but i did not find how to make the same meter based PIC takethe energy consumed into account even if the phase and the neutral are inverted for a single phase case.

17. Ahmad Abdullah on March 24th, 2012 5:27 pm

Hello , this transmitter and reciever works with ASK modulation ,does the transmitter that works with modulation AM , can be used the same way ?

18. anithaanandharaj on July 27th, 2012 10:48 am

v want to interface 4-wire resistive touch screen with pic16f887 & how i can do it.i need coding for that.i also need acoding to transmit the data through zigbee

Leave a comment

Name (required)

Email Address (required)

Website

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <deldatetime=""> <em> <i> <q cite=""> <strike> <strong>

Post your comment

........................................................................

Page 9: RF

Subscribe through email

Sign Up

2 Follow Follow @EmbeddedLab@EmbeddedLab

Featured Project

Introducing Easy Pulse: A DIY photoplethysmographic sensor for measuring heart rate

When I first built the Heart rate measurement through fingertip project, the infrared LED and photodiode used for fingerphotoplethysmography were actually from salvaged parts, and therefore, I could not provide specifications for them in the article.

Experimenting with PIC

These tutorials are aimed to provide you an introductory level theory and practice of embedded system design through

Ads by Google

Pic Microcontroller Kit

Point to Point Wireless

Wireless Communications

Page 10: RF

the application of PIC microcontrollers.

Browse our PIC Tutorials

Most Popular Posts

Heart rate measurement from fingertipProgrammable digital timer switch using a PIC MicrocontrollerPIC-based Digital Voltmeter (DVM)A very simple IR remote control switch for an electrical applianceLab 15: Scrolling text message on an LED dot-matrix display

chipKIT Tutorials

Browse our chipKIT Tutorials

Categories

555 Timer (7)Analog (1)Arduino (10)AVR Projects (27)AVR Tutorials (5)chipKIT (11)dsPIC (1)Embedded Lab Projects (36)Embedded Labs (25)Embedded Lessons (33)MCU develeopment tools (4)Microcontroller Programmers (6)MSP430 Launchpad (1)Netduino (2)PIC Projects (64)PIC Tutorials (42)PIC18F (10)Power Supply (6)Processing (2)Product Review (12)Products (10)Robotics (4)Tech News (47)Tips and Tricks (39)Uncategorized (1)

Page 11: RF

Links

EEWebElectronics-LabLED Display PanelsLED Lighting PanelsLED Panel Light Manufacturer

Visitors

flag counter

© 2012 Embedded Lab. All Rights Reserved. | Theme Provided by Best Wordpress Themes