top of page
Writer's pictureSanskruti Ashtikar

Home Automation System Using PIC Microcontroller

Updated: Dec 1

Home automation systems have become increasingly popular due to their ability to enhance convenience, security, and energy efficiency in modern homes. A home automation system using a PIC microcontroller can control various household appliances such as lights, fans, and security systems through a centralized system. This article will guide you through the design and implementation of a home automation system using a PIC microcontroller.


Introduction


Home automation involves the automatic control of electronic devices in your home. These devices are connected to the Internet, allowing them to be controlled remotely. With the advent of microcontrollers, designing a cost-effective and efficient home automation system has become feasible. The PIC microcontroller is a popular choice due to its versatility and ease of use.





Components Required


  1. PIC Microcontroller (e.g., PIC16F877A)

  2. Relays

  3. Relay Driver IC (ULN2003)

  4. Sensors (e.g., temperature, motion)

  5. LCD Display

  6. Push Buttons

  7. Transistors

  8. Resistors

  9. Capacitors

  10. Crystal Oscillator

  11. Connecting Wires

  12. Breadboard or PCB

  13. Power Supply


Circuit Design


  1. Microcontroller:

  2. The PIC16F877A microcontroller will act as the central control unit. It will process inputs from various sensors and control outputs such as relays and displays.

  3. Relays:

  4. Relays will be used to control high voltage appliances like lights and fans. The relay driver IC (ULN2003) will interface between the microcontroller and the relays.

  5. Sensors:

  6. Various sensors like temperature sensors (e.g., LM35) and motion sensors (e.g., PIR sensor) will provide input to the microcontroller.

  7. LCD Display:

  8. An LCD display will show the status of the system and sensor readings.

  9. Push Buttons:

  10. Push buttons will be used for manual control of appliances.

  11. Connections:

  12. Connect the sensors to the analog input pins of the PIC microcontroller.

  13. Connect the relay driver IC to the digital output pins of the PIC microcontroller.

  14. Connect the LCD display to the microcontroller using appropriate pins.

  15. Ensure proper grounding and power connections.


Software Design


  1. Programming Environment:

  2. Use MPLAB IDE and XC8 Compiler for programming the PIC microcontroller.

  3. Code Implementation:



#include <xc.h>
#include <stdio.h>
#include "lcd.h"  // Include LCD header file
#define _XTAL_FREQ 20000000  // Define crystal oscillator frequency
// Configuration bits
#pragma config FOSC = HS
#pragma config WDTE = OFF
#pragma config PWRTE = OFF
#pragma config BOREN = ON
#pragma config LVP = OFF
#pragma config CPD = OFF
#pragma config WRT = OFF
#pragma config CP = OFF
// Define sensor input pins
#define TEMP_SENSOR AN0
#define MOTION_SENSOR RB0
// Define relay output pins
#define LIGHT_RELAY RD0
#define FAN_RELAY RD1
void initialize() {
    // Set sensor pins as input
    TRISA = 0x01;  // RA0 as input (temperature sensor)
    TRISB = 0x01;  // RB0 as input (motion sensor)
    
    // Set relay pins as output
    TRISD = 0x00;  // RD0 and RD1 as output
    
    // Initialize LCD
    lcd_init();
    lcd_clear();
    lcd_set_cursor(1, 1);
    lcd_write_string("Home Automation");
    
    // ADC configuration
    ADCON0 = 0x41;  // Enable ADC, select channel 0 (AN0)
    ADCON1 = 0x80;  // Right justified result, VDD as reference voltage
}


unsigned int read_adc() {
    // Start ADC conversion
    __delay_us(25);  // Acquisition time
    GO_nDONE = 1;  // Start conversion
    while (GO_nDONE);  // Wait for conversion to complete
    return ((ADRESH << 8) + ADRESL);  // Return result
}
void main() {
    initialize();
    unsigned int temp_value;
    char buffer[16];
    
    while (1) {
        // Read temperature sensor
        temp_value = read_adc();
        float temperature = (temp_value * 5.0 / 1024.0) * 100.0;  // Convert ADC value to temperature
        
        // Display temperature on LCD
        sprintf(buffer, "Temp: %.2f C", temperature);
        lcd_set_cursor(2, 1);
        lcd_write_string(buffer);
        
        // Control fan based on temperature
        if (temperature > 30.0) {
            FAN_RELAY = 1;  // Turn on fan
        } else {
            FAN_RELAY = 0;  // Turn off fan
        }
        
        // Check motion sensor
        if (MOTION_SENSOR) {
            LIGHT_RELAY = 1;  // Turn on light
        } else {
            LIGHT_RELAY = 0;  // Turn off light
        }
        
        __delay_ms(1000);  // Delay 1 second
    }
}

Working


  1. Initialization:

  2. The microcontroller is initialized by setting the sensor pins as inputs and the relay pins as outputs. The LCD is also initialized to display system status.

  3. Temperature Control:

  4. The temperature sensor (LM35) provides analog input to the microcontroller, which is then converted to a digital value using the ADC module.

  5. The temperature value is displayed on the LCD.

  6. If the temperature exceeds a certain threshold (e.g., 30°C), the microcontroller activates the relay to turn on the fan.

  7. Motion Detection:

  8. The motion sensor provides digital input to the microcontroller.

  9. If motion is detected, the microcontroller activates the relay to turn on the light.

  10. The light is turned off when no motion is detected.

  11. Manual Control:

  12. Push buttons can be used to manually control the appliances. The microcontroller reads the state of the buttons and controls the relays accordingly.





Advantages


  1. Convenience:

  2. Automates routine tasks such as controlling lights and fans, enhancing user convenience.

  3. Energy Efficiency:

  4. Reduces energy consumption by turning off appliances when not needed.

  5. Security:

  6. Enhances home security by detecting motion and controlling lights.

  7. Scalability:

  8. The system can be easily expanded to control more appliances and integrate additional sensors.


Conclusion


A home automation system using a PIC microcontroller offers a cost-effective and efficient solution for automating household appliances. By leveraging sensors and relays, the system can control various devices based on real-time inputs, enhancing convenience, energy efficiency, and security. This article provides a comprehensive overview of the design and implementation of a home automation system using a PIC microcontroller. With proper planning and execution, such systems can be deployed to create smart homes that are more efficient and secure.


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 



0 views0 comments

Related Posts

See All

Comments


bottom of page