Introduction
Temperature monitoring is a critical task in various applications, including industrial automation, environmental monitoring, and home automation systems. Wireless temperature sensors offer the advantage of remote monitoring without the need for complex wiring, making them ideal for hard-to-reach or hazardous environments. In this article, we will discuss how to design and implement a wireless temperature sensor using a PIC microcontroller.
System Overview
The system consists of two main components: the transmitter and the receiver. The transmitter reads the temperature data using a temperature sensor (like the LM35) and sends this data wirelessly to the receiver using a wireless communication module (like RF or Bluetooth). The receiver then displays the temperature data on an LCD or sends it to a computer for further processing.
Components Required
PIC Microcontroller (e.g., PIC16F877A)
Temperature Sensor (e.g., LM35)
Wireless Transceiver Modules (e.g., 433MHz RF modules, HC-12, or Bluetooth)
LCD Display (16x2)
Voltage Regulator (e.g., LM7805)
Resistors, Capacitors, Diodes
Power Supply (5V)
Connecting Wires and Breadboard/PCB
Block Diagram
Transmitter Section:
Temperature Sensor (LM35): Converts the ambient temperature into an analog voltage.
PIC Microcontroller: Reads the analog signal from the temperature sensor, converts it to digital data using the ADC, and sends the data to the wireless module.
Wireless Module (e.g., 433MHz RF Transmitter): Transmits the temperature data to the receiver section.
Receiver Section:
Wireless Module (e.g., 433MHz RF Receiver): Receives the transmitted temperature data.
PIC Microcontroller: Processes the received data and sends it to the LCD for display or forwards it to another system for further processing.
LCD Display (16x2): Displays the temperature data received.
Circuit Diagram
Transmitter Circuit:
LM35 Temperature Sensor: Connect the VOUT pin of the LM35 to the analog input pin (e.g., AN0) of the PIC microcontroller.
Wireless Module: Connect the data pin of the wireless module to a digital I/O pin of the PIC (e.g., TX pin).
Power Supply: Provide a regulated 5V power supply to both the PIC microcontroller and the LM35 sensor.
Receiver Circuit:
Wireless Module: Connect the data pin of the wireless module to a digital I/O pin of the PIC microcontroller (e.g., RX pin).
LCD Display: Connect the LCD to the PIC microcontroller using the standard 4-bit interface.
Power Supply: Provide a regulated 5V power supply to both the PIC microcontroller and the wireless module.
Working Principle
Transmitter Section:
Temperature Sensing: The LM35 temperature sensor outputs an analog voltage proportional to the ambient temperature. The PIC microcontroller reads this analog voltage using its ADC (Analog-to-Digital Converter).
Data Conversion: The analog voltage is converted into a digital value that represents the temperature. This value is then formatted and sent to the wireless module for transmission.
Wireless Transmission: The wireless module transmits the temperature data to the receiver module.
Receiver Section:
Data Reception: The wireless module receives the temperature data and sends it to the PIC microcontroller.
Data Processing: The PIC microcontroller processes the received data and converts it back into a readable temperature format.
Display: The processed temperature data is displayed on the LCD for real-time monitoring.
PIC Microcontroller Programming
Below is a simplified example code for both the transmitter and receiver sections, using MPLAB X IDE and the XC8 compiler.
Transmitter Code:
#include <xc.h>
#define _XTAL_FREQ 20000000 // 20 MHz oscillator frequency
#define TEMP_SENSOR_CHANNEL 0 // LM35 connected to AN0
#define TX_PIN RC6 // TX pin for UART transmission
// Configuration bits
#pragma config FOSC = HS // High-speed oscillator
#pragma config WDTE = OFF // Watchdog Timer disabled
#pragma config PWRTE = OFF // Power-up Timer disabled
#pragma config BOREN = ON // Brown-out Reset enabled
#pragma config LVP = OFF // Low-voltage programming disabled
#pragma config CPD = OFF // Data EEPROM protection disabled
#pragma config WRT = OFF // Flash program memory write protection off
#pragma config CP = OFF // Code protection off
// Function prototypes
void initialize();
unsigned int read_temperature();
void send_temperature(unsigned int temperature);
void main() {
initialize();
while (1) {
unsigned int temperature = read_temperature();
send_temperature(temperature);
__delay_ms(1000); // Delay between readings
}
}
void initialize() {
TRISC6 = 0; // TX pin as output
TXSTA = 0x24; // Enable UART transmission
RCSTA = 0x90; // Enable UART and continuous receive mode
SPBRG = 31; // Baud rate 9600
// ADC configuration
ADCON0 = 0x41; // ADC on, select AN0
ADCON1 = 0x80; // Right justify result, use VDD as reference
}
unsigned int read_temperature() {
ADCON0 |= 0x02; // Start ADC conversion
while (ADCON0 & 0x02); // Wait for conversion to complete
return ((ADRESH << 8) + ADRESL); // Return ADC result
}
void send_temperature(unsigned int temperature) {
char buffer[10];
sprintf(buffer, "TEMP:%d\r\n", temperature);
for (int i = 0; buffer[i] != '\0'; i++) {
while (!TXIF); // Wait until TX buffer is empty
TXREG = buffer[i]; // Transmit character
}
}
Receiver Code:
#include <xc.h>
#define _XTAL_FREQ 20000000 // 20 MHz oscillator frequency
#define RX_PIN RC7 // RX pin for UART reception
// Configuration bits
#pragma config FOSC = HS // High-speed oscillator
#pragma config WDTE = OFF // Watchdog Timer disabled
#pragma config PWRTE = OFF // Power-up Timer disabled
#pragma config BOREN = ON // Brown-out Reset enabled
#pragma config LVP = OFF // Low-voltage programming disabled
#pragma config CPD = OFF // Data EEPROM protection disabled
#pragma config WRT = OFF // Flash program memory write protection off
#pragma config CP = OFF // Code protection off
// Function prototypes
void initialize();
void receive_temperature();
void display_on_lcd(unsigned int temperature);
void main() {
initialize();
while (1) {
receive_temperature();
}
}
void initialize() {
TRISC7 = 1; // RX pin as input
TXSTA = 0x20; // Enable UART transmission
RCSTA = 0x90; // Enable UART and continuous receive mode
SPBRG = 31; // Baud rate 9600
// LCD initialization code (if using an LCD display)
}
void receive_temperature() {
char buffer[10];
int i = 0;
while (1) {
while (!RCIF); // Wait for data reception
buffer[i] = RCREG; // Read received character
if (buffer[i] == '\n') {
buffer[i] = '\0'; // Null-terminate the string
break;
}
i++;
}
if (sscanf(buffer, "TEMP:%d", &temperature) == 1) {
display_on_lcd(temperature);
}
}
void display_on_lcd(unsigned int temperature) {
// Display temperature on LCD (implementation depends on LCD library used)
}
Explanation of the Code
Initialization: Both the transmitter and receiver sections start with the initialization of the UART for serial communication and the ADC (in the transmitter) for temperature sensing.
Reading Temperature (Transmitter): The read_temperature() function reads the analog output from the LM35 sensor, converts it to a digital value using the PIC’s ADC, and sends the data wirelessly using the send_temperature() function.
Receiving Temperature (Receiver): The receive_temperature() function reads the incoming data from the wireless module, processes it, and displays the temperature on an LCD.
Displaying Temperature: The temperature data is displayed on an LCD for real-time monitoring.
Conclusion
The wireless temperature sensor system using a PIC microcontroller is a practical solution for monitoring temperature in remote or inaccessible locations. By using wireless communication, the system eliminates the need for complex wiring and allows for easy deployment in various applications, from environmental monitoring to smart home systems.
Further Enhancements
Data Logging: Integrate an SD card module for logging temperature data over time.
Multiple Sensors: Expand the system to support multiple temperature sensors for monitoring in different locations.
Internet Connectivity: Connect the system to the internet using Wi-Fi or GSM for remote monitoring via a web interface or mobile app.
Battery Power: Implement a battery-powered solution with power-saving features for portable or off-grid applications.
Want us to guide you through your project or make the project for you ?
Create Various Projects
Check out our Free Arduino Projects Playlist - Arduino Projects
Check out our Free Raspberry Pi Projects Playlist - Raspberry Pi Projects
Check out our Free TinkerCAD Projects Playlist - TinkerCAD Projects
Check out our Free IoT Projects Playlist - IoT Projects
Check out our Free Home Automation Projects Playlist - Home Automation Projects
Check out our Free NodeMCu Projects Playlist - NodeMCu Projects
Comments