315 MHz RF Link Kit and VirtualWire Library

VirtualWire Library

VirtualWire, by Mike McCauley (PDF), helps you use very inexpensive wireless radio modules.

DownloadVirtualWire.zip (version 1.15 – Teensy 3.0 support & minor improvements added)

Very low cost RF modules require specially formatted data, with sync patterns, equal balance of 0 and 1 bits, and error checking. VirtualWire provides all of these features, allowing for best performance from very cheap radio circuits.

Hardware Requirements

VirtualWire requires RF modules. In these photos, a 315 MHz RF Link Kit sold by Seeed Depot ($4.90) was used.


These low cost modules are very simple. The receiver output signal indicates if energy from a transmitter is heard. It can be connected to any pin, but it can not drive pins with a LED attached.

Transmitters usually have only a single data pin, which activate the RF output when high. Some modules 2-way modules, with both a transmitter and receiver also have a transmitter enable pin.

VirtualWire uses Timer1, which means some PWM pins which require Timer1 will not work. Other libraries using Timer1 will be incompatible with VirtualWire. On Teensy 3.0, an IntervalTimer is used, which avoids conflicts with timers used for PWM.


Board Receive
Enable Pin
PWM Pins
Teensy 3.0 Any, except 13 Any Any
Teensy 2.0 Any, except 11 Any Any 4, 14, 15
Teensy 1.0 Any, except 6 Any Any 15, 17, 18
Teensy++ 2.0 Any, except 6 Any Any 25, 26, 27
Teensy++ 1.0 Any, except 6 Any Any 25, 26, 27




Basic Usage

VirtualWire works somewhat differently than most Arduino libraries. Many individual functions are used, and their names are somewhat different. Fortunately, each one is simple.

Configuration Functions


Configure the transmit pin. Default is pin 12. Blah


Configure the receive pin, Default is pin 11. On Teensy 2.0, pin 11 should not be used because most receiver modules can not work correctly with the orange LED on that pin.


Configure the transmit enable pin, or "push to talk". Default is pin 10.


Configure the "push to talk" polarity.


Begin using all settings and initialize the library. This is similar to the "begin" function of other libraries. All pins should be configured before calling this function.

Transmission Functions

vw_send(message, length)

Transmit a message. "message" is an array of the bytes to send, and "length" is the number of bytes stored in the array. This function returns immediately and the message is sent slowly by an interrupt-based background process.


Returns true if the message is being sent, or false if the transmitter is not active. You can use this after sending a message to test when it has finished being transmitted.


Wait for a message to be fully transmitted. Often the simplest approach is to call this after vw_send.

Reception Functions


Activate the receiver process. You must call this function before any reception can occur. An interrupt-based background process is started which monitors the reception of data.


Returns true if message has been received. This is similar to the "available" function of most other libraries.


Wait for a message to be received. This will only return when a message has been received, otherwise it will wait forever.


Wait for a message, but give up after "timeout_ms". Returns true if a message was received, or false if the timeout period elapsed.

vw_get_message(buf, &buflen))

Read the last received message. This should be called only when a message is known to be received with any of the 3 functions above. "buf" is an array where the message is copied. "buflen" should have the array's maximum size upon input, and upon return the number of bytes actually copied is retured. The function itself returns true if the message was verified correct, or false if a message was received but appears to have been corrupted.


Disable the receiver process.

The official VirtualWire documentation (PDF), explains these functions and other usage considerations.

Example Program – Transmit

Example Program – Receive



Realistic Performance Expectations

Many of the cheapest RF modules are sold with very unrealistic claims of data rate and maximum communication distance, and sometimes with very little (or even incorrect) documentation. VirtualWire will help these modules perform as well as they can, but the old saying applies: "you get what you pay for".

For example, the 315 MHz modules shown above were documented with only this image.


The only "documentation" for $4.90 module pair shown above

These modules worked very reliably when sitting only close to each other on a table. When separated by about 20 feet with ordinary office furniture, and a 13 cm wire attached to each (in the middle of the 10 to 15 cm suggested), they were able to communicate, but approximately 20% of messages were corrupted.

Perhaps using better antennas could help, but each board has a loading coil that appears to be designed for relatively short antennas, and no other documentation seems to exist regarding best antennas.

These modules can work well for low performance, non-critical applications. For more demanding applications, more sophisticated (and more expensive) RF modules should be considered.

RF Modules

Please contact Paul at PJRC dot COM if you know of other RF modules to add to this list.


From : http://www.pjrc.com/teensy/td_libs_VirtualWire.html


Post Author: TORTUGA

궁금하신 점은 새로 개편한 홈페이지의 QnA 게시판을 이용해주세요!!!!!!! http://www.hardcopyworld.com/gnuboard5/bbs/board.php?bo_table=qna

댓글 남기기

이메일은 공개되지 않습니다.