- A computer runnig MPLAB X, with XC8 compiler installed.
- PIC 16F688
- PIC 16F877A
- 2x16 LCD
- 433MHz RF modules (transmitter and receiver)
- Jumper wires
- Other parts according to parts list below
In this article, I'll show you one way to make a wireless thermometer using two PIC microcontrollers. One microcontroller, the PIC16F688, will measure voltage from an LM34, convert it to an ADC value, and transmit some data. The receiver will receive the data, and display a message on an LCD.
Sending data with the 433MHz transmitter is easy: in my case, I connect the PIC TX pin to the 433MHz data pin, then the transmitter sends whatever comes out the UART pin.
But receiving the data is the far more difficult part. The receiver will receive everything in its range. To sort out the data we want, we need some sort of protocol or error correction. In previous articles, I have used an Arduino with the VirtualWire library, and I have used a "synchronizing" string in another. In this article, I'm using another technique (this site inspired me). Now, I'm adding parity check to the transmitted data. The parity is being checked at the receiver end. While doing research for this article, I found a site with a VirtualWire library for PIC's. One drawback I found, however, was that this library filled almost all my PICs memory.
We need 2 block diagrams, one for each circuit.
- A way to program the microcontroller -> ICSP
- A sensor to measure temperature -> LM34
- A microcontroller to process the data -> PIC16F688
- A way to transmit the data -> 433MHz RF TX module
- A way to program the PIC16F877A
- A way to receive the RF signal -> 433MHz RF RX module
- A way to process the received data -> PIC16f877A
- A way to display a message -> 2x16 LCD
In the pictures below, you will see a MAX232 IC. This is added for debugging.
Unused pins are not tied to GND or to a testpad. None of the schematics are for production, they are for breadboard only.
When the program runs, it reads the voltage from the LM34. This voltage is converted into an ADC value. This value is then calculated to temperatures in both Fahrenheit and Celsius. According to a few if-sentences, a value is transferred to the uart_write-function. This function checks if the value is valid, and transfers it to the uarttransmit- function. This function adds parity to the data, and sends it out to the TXREG.
This type of transmitters send all the time when power is applied, which results in interference with other wireless appliances working in the same frequency range. Garage door openers and remote controlled ceiling fans might not respond correctly when the transmitter is on. To deal with that, I turn the transmitter on when it is transmitting and off when it is not transmitting.
The receiver picks up all kinds of signals and noise. The software has some debugging code and a MAX232 to see what's happening in a terminal window. When a signal is picked up, the value is checked for Framing Error bit. If the value has a framing error, the received data is set to NULL. Then the value is checked for the Overrun Error bit. If the Overrun Error bit check fails, the RCSTAbits.CREN is reset. If the received value passes those two tests, the received data is not garbage and parity is calculated. If the calculated parity is equal to the received parity, the value is valid and actions according to some if-sentences are taken.
When the received data is checked and OK, the PIC displays a message on the LCD-display. To make the LCD work with the microcontroller, I used the library files that are installed with the XC8 compiler. All the source files are added to one lcd_lib.c file. The LCD library files are included in the ZIP file below.
During development, I added a MAX232 IC to my breadboards. This was connected to my computer. That way it was easy for me to actually see what was sent out the EUSART-port on both the PICs.
In this article I have shown you how to make a wireless thermometer with 2 PIC microcontrollers, an LM34 and an LCD. The temperature is measured with one PIC, and an ADC value is calculated. According to the calculations, the data is formatted and sent out the EUSART port. The receiver checks for errors and when all is ok, a message is displayed on the LCD.
Pictures and Video
Give this project a try for yourself! Get the BOM.