You are on page 1of 12

Wireless data transmission between two PIC microcontrollers using low-c...

http://embedded-lab.com/blog/?p=3557

An online teaching laboratory for Microcontrollers and Embedded Systems

Home Products Theory PIC Experiments PIC Projects Tips & Tricks dsPIC chipKIT Netduino Contact
Low Cost Wireless Wireless Modules Data Transmission Wireless Antenna

R-B Sep 9th, 2011; 37,983 views


Like 165 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 Best Wireless Antenna wireless solutions for RF Receiver ease. Using long cables, infrared (IR) RF Wireless 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

1 of 12

8/30/2013 11:13 PM

Wireless data transmission between two PIC microcontrollers using low-c...

http://embedded-lab.com/blog/?p=3557

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.

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

2 of 12

8/30/2013 11:13 PM

Wireless data transmission between two PIC microcontrollers using low-c...

http://embedded-lab.com/blog/?p=3557

Transmitting unit

Receiving unit

3 of 12

8/30/2013 11:13 PM

Wireless data transmission between two PIC microcontrollers using low-c...

http://embedded-lab.com/blog/?p=3557

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 are easy to understand and needs no explanation. In CCS PCWHD, the LCD pins are defined in the lcd.c file. By default, it uses the PORTD pins (as shown in the circuit diagram above) as connections to the LCD. If you are using a different port, you need to edit 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) #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

4 of 12

8/30/2013 11:13 PM

Wireless data transmission between two PIC microcontrollers using low-c...

http://embedded-lab.com/blog/?p=3557

#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 as they can be directly interfaced to the UART port of microcontrollers. However, there are few things that I noted while experimenting with them. One is, when the ADC value (8-bit in this demo) is around 250 or higher the receiver starts getting garbage data. It seems like when the data contains too many 1s, it is not recognized by the receiver which literally believes that the data is static. One solution could be dividing the ADC byte into two nibbles and send them separately. It will slow down the net data transmission rate but the received data will be less likely to be erroneous. It also adds an extra overhead of reconstructing the bytes from the nibbles. Similarly, if you want to use 10-bit (or more) resolution for A/D conversion, the ADC result can also be broken into two 5-bit fragments (MSB 5-bit and LSB 5-bit) before transmission. Adding three extra 0s on the MSB end of each 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 this may not be what they claim because of the antenna length and the quality of the modules themselves. A wire of 12 inches or so is adequate 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 not be error free. Baud rates more than that are not useful at all. Several improvements can be done to add more features but I have kept it for those who are willing to explore it more and use it in various purposes. 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.

5 of 12

8/30/2013 11:13 PM

Wireless data transmission between two PIC microcontrollers using low-c...

http://embedded-lab.com/blog/?p=3557

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

1586

55

39

10.2K

Like

165

Download Free Software


mobogenie.com/download-software Download Free PC Manager Software. Easy File Transfer. Download Now !

100% Free DataSheet (PDF)


www.AllDataSheet.com Over 20000000 DataSheet. It's Free. Multi Fast Search System.

Microcontroller Projects
ProjectsQA.com Huge Microcontroller Projects list Topics, Guidance & much more

Random Posts
Making a simple clap switch
A clap switch is a fun project for beginners. It switches on and off electrical appliances with a sound of clapping hand...

Introducing the AmiPIC18 LCD shield


Last month I reviewed the Amicus18 development board, which is an Arduino-style platform with a PIC microcontroller. The...

Real-time clock and Temperature display on 168 LED Matrix


Digital clocks and temperature meters are very popular projects. There are tons of such projects available on internet. ...

Filed under: PIC Tutorials, Tips and Tricks

RSS feed for comments on this post TrackBack URI 25 Responses to this post 1. shivendra kumar sahu on September 10th, 2011 3:33 pm 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

6 of 12

8/30/2013 11:13 PM

Wireless data transmission between two PIC microcontrollers using low-c...

http://embedded-lab.com/blog/?p=3557

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-TX01 and 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 power metering 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 as x^0 and x^1. Also its 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=en025183 http://atmel.com/dyn/resources/prod_documents/doc2566.pdf http://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 October 24th, 2011 12:23 pm [...] more at http://embedded-lab.com/blog/?p=3557 This entry was posted in MCU Wireless communication and tagged microcontroller, 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 dont. 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 soon. amna-1991@live.com 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..amna1991@live.com 12. R-B on December 7th, 2011 9:08 pm Amna91,

7 of 12

8/30/2013 11:13 PM

Wireless data transmission between two PIC microcontrollers using low-c...

http://embedded-lab.com/blog/?p=3557

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 data transmission between two PIC microcontrollers using low-cost RF modules BigDog Reply With Quote + Post New Thread + 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 with atmega8.I did not find any output.Instead of KST TX01 & KST RX806 when i connect two uc by a wire then my program works but when i place KST TX01 & KST RX806 i did not find any output.where could be the problem. my code in mikroC is following TX: char uart_rd; void main() { UART1_Init(960); // Initialize UART module at 9600 bps Delay_ms(1000); // Wait for UART module to stabilize while (1) { UART1_Write_Text(a); Delay_ms(1000); } } AND RX: char uart_rd; void main() { DDRB=0xFF; PORTB=000; UART1_Init(960); // Initialize UART module at 9600 bps Delay_ms(1000); // Wait for UART module to stabilize while (1) { // Endless loop if (UART1_Data_Ready()) { // If data is received, uart_rd = UART1_Read(); // read the received data, if(uart_rd==a') { PORTB0_bit=~PORTB0_bit; } } else PORTB4_bit=~PORTB4_bit; } } 15. Majayz on January 20th, 2012 2:35 am Hi Engineer

8 of 12

8/30/2013 11:13 PM

Wireless data transmission between two PIC microcontrollers using low-c...

http://embedded-lab.com/blog/?p=3557

im doing a similar project although the difference is that i want the two picocontrollers (PIC16F877A) to be able to send and 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 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 take the 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 a coding to transmit the data through zigbee 19. Jose Antonio on January 4th, 2013 3:56 am Can this be tested in Proteus? Did you do it? 20. bob on February 1st, 2013 1:52 pm Hello.Thanks a lot for your very great project,Would you please design a project so that two PICs can communicate with RS485 and even send for example a few numbers of 10 digits to each others and on the LCD? Thanks, 21. bimb on March 1st, 2013 5:55 am @ Antonio, i did run it in proteus and it worked, though after compiling and debuggin on ccs c. 22. bimb on March 1st, 2013 5:56 am @ moderator, how can i directly access mr Shawon..theres been no response from that mail add. thanks 23. Arpit on March 14th, 2013 8:31 am Do I need to configure KST-TX01 and KST-RX806 by sending some specific code before using it or I can use it directly.I am asking it because I am working with ATMEGA-16 and I didnt understand some(FUSE) part of your programming. 24. Sky on April 16th, 2013 12:11 pm hello. this is useful project. i wanna measure distance between 2 RF module (between TX and RX), please tell me how to measure distance? i wanna make like this device http://www.amazon.com/Safety-Wristband-Anti-Lost-Protect-outdoor/dp/B007SBR0AM

9 of 12

8/30/2013 11:13 PM

Wireless data transmission between two PIC microcontrollers using low-c...

http://embedded-lab.com/blog/?p=3557

25. Marc on July 25th, 2013 4:14 pm HI Raj! i would like to do a wireless door bell, can you help? thank you! marC:) 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> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Nokia 5233
FROM Rs 4,000

Electric Guitar
FROM Rs 3,500

Subscribe through email

10 of 12

8/30/2013 11:13 PM

Wireless data transmission between two PIC microcontrollers using low-c...

http://embedded-lab.com/blog/?p=3557

Follow @EmbeddedLab

Embedded Lab
Like 4,428 people like Embedded Lab.

Facebook social plugin

Easy Pulse (Version 1.1) Sensor Overview (Part 1)

Easy Pulse, a DIY pulse sensor based on the principle of photoplethysmography, is now also sold by Elecrow, our China-based collaborator, for only $18.50 and ships world-wide through a registered parcel for less than $5. Buy Easy Pulse online for only $18.50.

These tutorials are aimed to provide you an introductory level theory and practice of embedded system design through the application of PIC microcontrollers.

11 of 12

8/30/2013 11:13 PM

Wireless data transmission between two PIC microcontrollers using low-c...

http://embedded-lab.com/blog/?p=3557

Browse our PIC Tutorials

Pic Programming RF Remote Controls Wireless Remote

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

555 Timer (7) Analog (1) Arduino (28) AVR Projects (29) AVR Tutorials (5) chipKIT (11) dsPIC (1) Embedded Lab Projects (56) Embedded Labs (25) Embedded Lessons (39) MCU develeopment tools (7) Microcontroller Programmers (6) MSP430 Launchpad (1) Netduino (8) PIC Projects (72) PIC Tutorials (43) PIC18F (10) Power Supply (6) Processing (3) Product Review (13) Products (28) Raspberry Pie (1) Robotics (4) Tech News (73) Tips and Tricks (50) Uncategorized (1)

EEWEB Electronics-Lab 2013 Embedded Lab. All Rights Reserved. | Theme Provided by Best Wordpress Themes

12 of 12

8/30/2013 11:13 PM

You might also like