top of page
Writer's pictureSanskruti Ashtikar

Smart Home Energy Management System using PIC Microcontroller

Updated: Nov 30

Introduction


Energy management in homes is becoming increasingly important as energy costs rise and environmental concerns grow. A smart home energy management system (SHEMS) helps in monitoring and controlling energy usage, optimizing the power consumption of home appliances, and ultimately reducing energy bills. In this article, we will discuss how to design and implement a smart home energy management system using a PIC microcontroller.





System Overview


The Smart Home Energy Management System (SHEMS) is designed to monitor energy usage, control appliances, and optimize energy consumption based on predefined conditions. The system uses various sensors to collect data on power consumption and environmental conditions, and it controls connected devices based on this data.


Key Features:


  • Real-time energy monitoring

  • Appliance control based on energy usage

  • Automatic load shedding during peak usage

  • User interface for monitoring and control


Components Required


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

  2. Current Sensor (e.g., ACS712)

  3. Voltage Sensor (e.g., ZMPT101B)

  4. Relay Module (for controlling appliances)

  5. LCD Display (16x2)

  6. Push Buttons (for user input)

  7. Wi-Fi Module (e.g., ESP8266) or Bluetooth Module (optional, for remote monitoring)

  8. Power Supply (5V)

  9. Resistors, Capacitors, Diodes

  10. Connecting Wires and Breadboard/PCB


Block Diagram


Core Components:


  1. PIC Microcontroller: The brain of the system, responsible for processing sensor data, controlling relays, and communicating with the user interface.

  2. Current and Voltage Sensors: Measure the power consumption of connected appliances.

  3. Relay Module: Controls the on/off state of home appliances.

  4. LCD Display: Provides real-time feedback to the user about energy usage and system status.

  5. User Interface: Push buttons or remote control via Wi-Fi/Bluetooth for user interaction.


Optional Components:


  • Wi-Fi/Bluetooth Module: For remote monitoring and control using a smartphone or computer.


Circuit Diagram


Connections:


  1. Current Sensor (ACS712): Connect the output of the current sensor to an analog input pin (e.g., AN0) of the PIC microcontroller.

  2. Voltage Sensor (ZMPT101B): Connect the output of the voltage sensor to another analog input pin (e.g., AN1) of the PIC microcontroller.

  3. Relay Module: Connect the control input of the relay to a digital I/O pin of the PIC (e.g., RB0, RB1) to control appliances like lights, fans, or air conditioners.

  4. LCD Display: Interface the LCD to the PIC using the standard 4-bit mode (D4-D7 for data, RS, and EN connected to GPIO pins).

  5. Push Buttons: Connect push buttons to digital input pins of the PIC for user interaction.


Working Principle


1. Sensor Data Acquisition


The current sensor (ACS712) and voltage sensor (ZMPT101B) continuously monitor the current and voltage of connected appliances. The PIC microcontroller reads the analog signals from these sensors and converts them to digital values using its ADC (Analog-to-Digital Converter).


2. Energy Calculation


The microcontroller calculates the power consumption using the formula:

Power=Voltage×Current\text{Power} = \text{Voltage} \times \text{Current}Power=Voltage×Current

By integrating the power over time, the system can calculate the energy consumption in kilowatt-hours (kWh).


3. Appliance Control


Based on the energy consumption data and user-defined thresholds, the system can automatically turn appliances on or off to optimize energy usage. For example, if the total power consumption exceeds a certain limit, the system can turn off non-essential appliances to prevent overloading.


4. User Interface


The system displays real-time energy usage data on the LCD screen. Users can interact with the system using push buttons to set thresholds, turn appliances on/off, or view energy usage statistics.


5. Remote Monitoring (Optional)


If equipped with a Wi-Fi or Bluetooth module, the system can send real-time data to a smartphone app or web interface, allowing users to monitor and control their home energy usage remotely.





PIC Microcontroller Programming


Below is a simplified example code for the smart home energy management system using MPLAB X IDE and the XC8 compiler.


Main Code:


#include <xc.h>
#include <stdio.h>
#define _XTAL_FREQ 20000000  // 20 MHz oscillator frequency
#define RELAY1 RB0  // Relay 1 control pin
#define RELAY2 RB1  // Relay 2 control pin
// 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_adc(unsigned char channel);
float calculate_power(unsigned int voltage, unsigned int current);
void display_energy(float power);
void main() {
    initialize();
    
    while (1) {
        unsigned int voltage = read_adc(1);  // Read voltage from AN1
        unsigned int current = read_adc(0);  // Read current from AN0
        
        float power = calculate_power(voltage, current);
        display_energy(power);
        
        // Example of controlling appliances based on power usage
        if (power > 1000) {  // If power exceeds 1000W
            RELAY1 = 0;  // Turn off non-essential appliance
        } else {
            RELAY1 = 1;  // Keep appliance on
        }
        
        __delay_ms(1000);  // Delay between readings
    }
}


void initialize() {
    TRISB0 = 0;  // Set RB0 as output for relay
    TRISB1 = 0;  // Set RB1 as output for relay
    
    // ADC configuration
    ADCON0 = 0x01;  // ADC on, select AN0 initially
    ADCON1 = 0x80;  // Right justify result, use VDD as reference
    
    // Initialize other peripherals like LCD, UART (if needed)
}
unsigned int read_adc(unsigned char channel) {
    ADCON0 &= 0xC5;  // Clear existing channel selection
    ADCON0 |= (channel << 3);  // Select the required channel
    __delay_us(5);  // Acquisition time
    ADCON0 |= 0x02;  // Start ADC conversion
    while (ADCON0 & 0x02);  // Wait for conversion to complete
    return ((ADRESH << 8) + ADRESL);  // Return ADC result
}
float calculate_power(unsigned int voltage, unsigned int current) {
    // Convert ADC values to actual voltage and current
    float actual_voltage = (voltage * 5.0) / 1024.0 * (230.0 / 5.0);  // Adjust for sensor scaling
    float actual_current = (current * 5.0) / 1024.0 * (30.0 / 5.0);  // Adjust for sensor scaling
    
    return actual_voltage * actual_current;  // Power = Voltage * Current
}
void display_energy(float power) {
    char buffer[16];
    sprintf(buffer, "Power: %.2fW", power);
    // Code to display on LCD
}




Explanation of the Code


  1. Initialization: The initialize() function configures the ADC for reading voltage and current, and sets up the I/O pins for controlling relays.

  2. ADC Reading: The read_adc() function reads the analog signal from the sensors and converts it to a digital value, which is then used to calculate the actual voltage and current.

  3. Power Calculation: The calculate_power() function converts the ADC values into actual voltage and current, then calculates the power consumption using the formula Power=Voltage×Current\text{Power} = \text{Voltage} \times \text{Current}Power=Voltage×Current.

  4. Energy Display: The display_energy() function formats the calculated power value and displays it on the LCD.

  5. Appliance Control: The code includes a basic example of turning off a relay (and hence an appliance) if the power consumption exceeds a certain threshold, demonstrating how the system can manage energy usage in real-time.


Conclusion


The Smart Home Energy Management System using a PIC microcontroller is an effective solution for monitoring and controlling energy usage in residential settings. It helps optimize energy consumption, reduces electricity bills, and contributes to a more sustainable lifestyle. The system can be expanded to include more sensors, support multiple appliances, and even integrate with IoT platforms for advanced features like remote monitoring and control.


Further Enhancements


  1. Remote Monitoring: Integrate Wi-Fi or Bluetooth to enable remote monitoring and control via a smartphone app or web interface.

  2. Data Logging: Add an SD card module to log energy usage data over time for detailed analysis.

  3. Smart Algorithms: Implement smart algorithms to predict energy consumption patterns and automatically adjust appliance usage for optimal energy efficiency.

  4. Integration with Renewable Energy Sources: Incorporate solar panels or other renewable energy sources into the system, allowing for intelligent management of energy produced and consumed.

  5. Voice Control: Integrate with voice assistants like Amazon Alexa or Google Assistant for hands-free control of home appliances.


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 



6 views0 comments

Related Posts

See All

Comments