top of page
Writer's pictureSanskruti Ashtikar

Automatic Temperature Control System Using PIC Microcontroller

Introduction


Temperature control systems are essential in a variety of applications, from home heating and cooling to industrial processes. An Automatic Temperature Control System using a PIC microcontroller can provide a cost-effective and efficient solution for maintaining desired temperature levels. This article will guide you through the design and implementation of such a system, detailing the components, circuit design, and programming required to achieve automatic temperature regulation.


Components Required


  1. PIC Microcontroller: PIC16F877A or similar.

  2. Temperature Sensor: LM35 or DS18B20.

  3. Relay Module: To control heating/cooling devices like fans, heaters, or air conditioners.

  4. LCD Display: 16x2 or similar for displaying temperature and system status.

  5. Push Buttons: For setting the desired temperature.

  6. Power Supply: 5V DC for the microcontroller and 12V for the relay module (if needed).

  7. Resistors and Capacitors: For signal conditioning and circuit stability.

  8. Connecting Wires and PCB: For assembling the circuit.


System Overview


The Automatic Temperature Control System continuously monitors the ambient temperature using a sensor and compares it with a set point temperature defined by the user. If the measured temperature deviates from the set point, the microcontroller activates heating or cooling devices through a relay module to bring the temperature back to the desired level. The system displays real-time temperature readings and system status on an LCD.


Circuit Diagram


Key Connections:


  1. Temperature Sensor: Connect the sensor's output to an analog input pin of the PIC microcontroller for reading temperature data.

  2. Relay Module: Interface the relay control pins with digital output pins of the microcontroller to switch heating/cooling devices on or off.

  3. LCD Display: Interface with the microcontroller for displaying temperature readings and system status.

  4. Push Buttons: Connect push buttons to digital input pins for setting and adjusting the desired temperature.


Microcontroller Configuration


The PIC microcontroller will manage sensor data, compare the temperature with the set point, and control the relay module based on the temperature readings. It will also handle user inputs for setting the desired temperature and display relevant information on the LCD.


Pin Configuration


  1. Analog Input: For reading data from the temperature sensor.

  2. Digital Outputs: For controlling the relay module.

  3. LCD Pins: For data and control lines to the LCD.

  4. Button Inputs: For adjusting the set point temperature.


Sample Code


Here’s a sample code snippet to illustrate the basic functionality of reading temperature, comparing it with a set point, and controlling a relay:


#include <xc.h>
#include "lcd.h"
#define _XTAL_FREQ 4000000
#define RELAY_PIN PORTBbits.RB0 // Relay connected to RB0
#define TEMP_SENSOR_CHANNEL 0   // Temperature sensor connected to AN0
unsigned int desired_temp = 25; // Default desired temperature
unsigned int current_temp;
unsigned int Read_Temperature(void) {
    unsigned int adc_value = 0;
    
    // Select ADC Channel
    ADCON0bits.CHS = TEMP_SENSOR_CHANNEL;
    
    // Start Conversion
    ADCON0bits.GO_nDONE = 1;
    while(ADCON0bits.GO_nDONE); // Wait for conversion to finish
    
    adc_value = ((ADRESH << 8) + ADRESL); // Combine 10-bit result
    
    // Convert ADC value to temperature (assuming LM35)
    // LM35 gives 10mV per degree C, with 5V reference and 10-bit ADC
    return (adc_value * 5.0 * 100.0) / 1024.0;
}
void main(void) {
    // Initialize modules
    LCD_Init();
    ADC_Init();
    
    // Set relay pin as output
    TRISBbits.TRISB0 = 0;
    
    while(1) {
        // Read current temperature
        current_temp = Read_Temperature();
        
        // Display current temperature on LCD
        LCD_Clear();
        LCD_Set_Cursor(1,1);
        LCD_Write_String("Temp: ");
        LCD_Write_Number(current_temp);
        LCD_Write_String("C");
        
        // Display desired temperature
        LCD_Set_Cursor(2,1);
        LCD_Write_String("Set: ");
        LCD_Write_Number(desired_temp);
        LCD_Write_String("C");
        
        // Control relay based on temperature comparison
        if (current_temp > desired_temp) {
            RELAY_PIN = 1; // Turn on cooling device
        } else {
            RELAY_PIN = 0; // Turn off cooling device
        }
        
        __delay_ms(1000); // Update every second
    }
}

Working of the System


  1. Initialization: On startup, the microcontroller initializes the LCD and ADC modules and sets the relay pin as an output.

  2. Temperature Reading: The microcontroller continuously reads the ambient temperature from the sensor.

  3. Temperature Display: The current and desired temperatures are displayed on the LCD.

  4. Temperature Comparison: The microcontroller compares the current temperature with the set point.

  5. Relay Control: If the temperature exceeds the set point, the microcontroller activates the relay to turn on a cooling device (or deactivate it if the temperature is below the set point).

  6. User Interaction: Users can adjust the desired temperature using the push buttons.


Testing and Calibration


  1. Sensor Calibration: Ensure the temperature sensor provides accurate readings by comparing it with a known accurate thermometer.

  2. Relay Testing: Verify that the relay correctly switches the connected device on and off based on temperature readings.

  3. Temperature Stability: Test the system’s ability to maintain a stable temperature around the set point.


Additional Features


To enhance the functionality of the Automatic Temperature Control System, consider adding:

  1. Heating Control: Add a second relay to control a heating device for situations where the temperature is too low.

  2. Hysteresis Control: Implement a hysteresis function to prevent rapid on/off switching of the relay near the set point.

  3. Data Logging: Integrate a data logging feature to record temperature over time for analysis.

  4. User Interface: Improve the user interface by adding more buttons or a keypad for easier temperature setting.

  5. Remote Monitoring: Add wireless connectivity (Bluetooth, Wi-Fi) for remote monitoring and control of the system.


Conclusion


An Automatic Temperature Control System using a PIC Microcontroller is a versatile project that can be adapted for various applications where temperature regulation is essential. By following this guide, you can design a system that maintains a stable temperature within a desired range, offering opportunities for further customization and enhancement.


References


  • PIC16F877A Datasheet: Microchip

  • LM35 Temperature Sensor Documentation: [Manufacturer's Website]

  • MPLAB X IDE: Microchip



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 


2 views0 comments

Related Posts

See All

תגובות


bottom of page