top of page
Writer's pictureSanskruti Ashtikar

Smart Energy Meter Using PIC Microcontroller

Updated: Nov 26

Introduction


Energy meters are essential devices for monitoring electrical power consumption in homes and industries. Traditional energy meters only measure and display power usage, but with advancements in microcontroller technology, we can create a Smart Energy Meter that not only measures power consumption but also provides additional features like data logging, remote monitoring, and real-time alerts. This article guides you through designing and implementing a Smart Energy Meter using a PIC Microcontroller.





Components of the System


  1. PIC Microcontroller:

  2. Model: PIC16F877A or similar

  3. Function: Acts as the central control unit, processing data from sensors and managing display and communication.

  4. Current Sensor:

  5. Model: ACS712 or similar

  6. Function: Measures the current flowing through the circuit.

  7. Voltage Sensor:

  8. Type: Voltage divider circuit or dedicated voltage sensor module

  9. Function: Measures the voltage across the load.

  10. Power Measurement Module:

  11. Model: ADE7757 or similar (optional)

  12. Function: Provides accurate measurement of power and energy, if used.

  13. LCD Display:

  14. Model: 16x2 or 20x4 LCD

  15. Function: Displays real-time voltage, current, power, and energy consumption data.

  16. Communication Module (Optional):

  17. Type: GSM, Wi-Fi, or Bluetooth module

  18. Function: Enables remote monitoring and data transmission.

  19. Relay Module (Optional):

  20. Function: Controls power to the load, enabling features like remote cut-off.

  21. Power Supply:

  22. Type: 5V or 12V DC adapter

  23. Purpose: Powers the microcontroller and other components.

  24. Resistors, Capacitors, and Other Passive Components:

  25. Purpose: For building the voltage divider circuit and other interfacing requirements.


Design Considerations


  1. Accuracy:

  2. Ensure accurate current and voltage measurements by selecting appropriate sensors and calibrating them correctly.

  3. Safety:

  4. Incorporate isolation techniques such as optocouplers to protect the microcontroller and low-voltage components from high-voltage mains.

  5. Data Logging:

  6. If required, include an SD card module or internal memory to store historical power consumption data for later analysis.

  7. User Interface:

  8. Design a clear and intuitive interface using the LCD display. Consider including buttons for menu navigation and configuration.

  9. Remote Monitoring:

  10. If remote monitoring is a goal, choose a suitable communication module (e.g., GSM, Wi-Fi) and design the system to transmit data to a remote server or mobile app.


Building the System


1. Microcontroller and Sensor Integration


  • Current Sensor Connection:

  • Connect the ACS712 current sensor to the microcontroller’s analog input pin. This sensor provides an analog voltage proportional to the current flowing through the load.

  • Voltage Sensor Connection:

  • Use a voltage divider circuit to scale down the mains voltage to a safe level for the microcontroller’s ADC. Ensure that the resistor values are chosen to safely divide the mains voltage.

  • Programming the PIC Microcontroller:

  • Write firmware to read the analog inputs from the current and voltage sensors, calculate the real-time power, and display the results.



#include <xc.h>
#define _XTAL_FREQ 4000000
// Define pin connections
#define CURRENT_SENSOR_PIN PORTA0
#define VOLTAGE_SENSOR_PIN PORTA1
#define LCD_RS PORTBbits.RB0
#define LCD_EN PORTBbits.RB1
#define LCD_DATA PORTD
float current, voltage, power;
void init() {
    TRISA = 0xFF;  // Set PORTA as input for sensors
    TRISB = 0x00;  // Set PORTB as output for LCD control
    TRISD = 0x00;  // Set PORTD as output for LCD data
    ADCON1 = 0x80; // Configure ADC
}
float readADC(unsigned char channel) {
    ADCON0 = (channel << 3); // Select ADC channel
    ADCON0 |= 0x01;          // Start conversion
    while (ADCON0 & 0x02);   // Wait for conversion to complete
    return (ADRESH << 8) + ADRESL; // Return ADC result
}
void calculatePower() {
    current = (readADC(CURRENT_SENSOR_PIN) - 512) * 0.1; // Example calibration
    voltage = readADC(VOLTAGE_SENSOR_PIN) * 0.488; // Example calibration
    power = voltage * current;
}
void displayData() {
    // Example code to display data on the LCD
    // Initialize LCD and send power value to the display
}


void main() {
    init();
    while (1) {
        calculatePower();
        displayData();
        __delay_ms(1000); // Update every second
    }
}

2. LCD Display Integration


  • Connecting the LCD Display:

  • Connect the 16x2 LCD to the microcontroller using the appropriate data and control pins. Initialize the LCD in the code and display the voltage, current, and power values.

  • Programming the Display:

  • Write functions to format and send data to the LCD, such as displaying “Voltage: 230V”, “Current: 5A”, and “Power: 1150W”.



void displayData() {
    lcd_clear();
    lcd_gotoxy(1, 1);
    printf("Volt: %.2fV", voltage);
    lcd_gotoxy(1, 2);
    printf("Curr: %.2fA", current);
    lcd_gotoxy(1, 3);
    printf("Power: %.2fW", power);
}

3. Communication Module Integration (Optional)


  • Connecting the Communication Module:

  • Connect a GSM, Wi-Fi, or Bluetooth module to the microcontroller’s UART pins. This will allow you to send power consumption data to a remote server or mobile app.

  • Programming the Communication:

  • Implement UART communication routines to send the calculated power data. For GSM, you could send SMS alerts; for Wi-Fi, data could be sent to a cloud server.


void sendDataToServer() {
    // Example code to send data via GSM or Wi-Fi module
    // Use AT commands or HTTP requests to transmit data
}




4. Relay Module Integration (Optional)


  • Connecting the Relay Module:

  • Connect a relay module to the microcontroller to control the load based on power consumption thresholds.

  • Programming the Relay Control:

  • Implement logic to turn off the relay (and hence the load) if the power consumption exceeds a certain limit, acting as an automatic cutoff.


void controlRelay() {
    if (power > 2000) { // Example threshold
        RELAY_PIN = 1;  // Turn off the relay
    } else {
        RELAY_PIN = 0;  // Keep the relay on
    }
}

Testing and Optimization


  1. Calibration:

  2. Calibrate the current and voltage sensors by comparing with a standard multimeter. Adjust the conversion factors in the code to ensure accurate readings.

  3. Functional Testing:

  4. Test the system under different loads and verify that the voltage, current, and power readings are accurate. Test the LCD display to ensure the data is clear and correctly formatted.

  5. Communication Testing:

  6. If using a communication module, verify that data is correctly transmitted to the remote server or received on the mobile app.

  7. Safety Testing:

  8. Ensure that all high-voltage parts are properly insulated and that the system operates safely under continuous use.


Conclusion


A Smart Energy Meter using a PIC Microcontroller is a powerful tool for monitoring and managing power consumption in real-time. By integrating current and voltage sensors with a microcontroller, you can accurately measure electrical parameters and display them for easy monitoring. Additionally, with optional communication modules, the system can offer advanced features like remote monitoring and automatic control, making it a versatile solution for both residential and industrial applications.

Careful design, testing, and calibration are essential to ensure the system’s accuracy, reliability, and safety. With proper implementation, this Smart Energy Meter can contribute to energy efficiency and help users keep track of their power usage.




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 



10 views0 comments

Related Posts

See All

Comments


bottom of page