On the first part of this instructable, I demonstrated how to program a PIC12F1822 using MPLAB IDE and XC8 compiler, to send a simple string wirelessly using cheap TX/RX 433MHz modules.
The receiver module was connected via a USB to UART TTL cable adapter to a PC, and the data received were displayed on RealTerm. The communication was performed at 1200 baud and the maximum range achieved was about 20 meters through walls. My tests showed that for applications where there is no need for high data rate and long range,and for continuous transmission, these modules performed exceptionally well.
The second part of this project demonstrates how to add a PIC16F887 microcontroller and a 16×2 character LCD module on the receiver. Moreover, on the transmitter, a simple protocol is followed with the addition of a few preample bytes. These bytes are necessary for the RX module to adjust its gain prior to getting the actual payload. At the receiver side,the PIC is responsible of getting and validating the data which are displayed on the LCD screen.
Step 1: Transmitter Modifications
On the first part, the transmitter was sending a simple string every few ms using eight data bits, a start, and a stop bit at 1200 bits per second. As the transmission was almost continuous, the receiver had no trouble adjusting it's gain to the received data. On the second part, the firmware is modified so that the transmission is performed every 2.3 seconds. This is achieved using the watchdog timer interrupt (set to 2.3s) to wake up the microcontroller, which is put in sleep mode in between each transmission.
In order for the receiver to have time to fine-tune it's gain, a few preamble bytes with short LO times "(0Xf8)(0Xf8)(0Xf8)(0Xf8)(0Xf8)(0Xfa)" are send before the actual data. Payload is then indicated by a start '&' and a stop '*' byte.
Hence, the simple protocol is described as follows:
Moreover, a 10uF decoupling tantalum capacitor is added between RF module's V+ and GND to get rid of the ripple caused by the dc-dc step up module.
Baud rate remained the same, yet my tests showed that at 2400 baud also, the transmission was efficient.
Step 2: Receiver Modifications: Adding PIC16F887 and HD44780 LCD
The receiver design was based on PIC16F887, but you can use a different PIC with little modifications.
In my project I used this 40 pin μC, as I will need extra pins for future projects based on this design. The output of the RF module is connected to the UART rx pin, whereas a 16x2 character lcd (HD44780) is connected through PORTB pins b2-b7 to display the received data.
As with Part 1, the data received are also displayed on RealTerm. This is achieved using UART tx pin which is connected via a USB to UART TTL cable adapter to a PC.
Looking into the firmware, when a UART interrupt takes place, the program checks whether the byte received is a start byte ('&'). If yes, it starts recording the subsequent bytes, until a stop byte is caught ('*'). As soon as the whole sentence is obtained, and if it conforms to the simple protocol described before, it is then sent to the lcd screen, as well as to the UART tx port.
Prior to receiving the start byte, the receiver has already adjusted its gain using the preceding preamble bytes. These are critical for the smooth operation of the receiver. A simple overrun and framing error check is performed, however this is only a basic UART error handling implementation.
In terms of hardware, a few parts are needed for the receiver:
1 x PIC16F887
1 x HD44780
1 x RF Rx module 433Mhz
1 x 10 μF tantalum capacitor (decoupling)
1 x 10 K trimmer (LCD font brightness)
1 x 220 Ω 1/4 W resistor (LCD backlight)
1 x 1 KΩ 1/4 W
1 x Antenna 433Mhz,3dbi
In practice, the received worked exceptionally well in ranges up to 20 meters though walls.
Step 3: A Few References...
Step 4: Conclusions and Future Work
In rapping things up, I hope this instructable helped you understand how to use RF modules and Pic microcontrollers. You can adjust your firmware to your own needs and include CRC and encryption. If you want to make your design even more sophisticated, you may utilize Microschip's Keeloq technology.
In case your application needs bi-directional data, you would need to have a pair of TX/RX at both microcontrollers, or you can use more sophisticated transceiver modules. However, using this kind of cheap 433MHz modules, only half duplex communication can be accomplished. Further to this, in order to make the communication more reliable your would need to have some form of handshaking between TX and RX.
On the next instructable, I will show you a practical application where an environmental sensor with temperature, barometric pressure and humidity is added on the transmitter. Here, the transmitted data will include crc and will have a basic encryption.
The sensor will be using the i2c port of the PIC12F1822, whereas the implementation of both transmitter and receiver will be exposed through schematics and pcb files.
Thanks for reading me!