This system uses a Pzem-004t sensor, which is a non-invasive AC power monitor, to measure various electrical parameters like voltage, current, power, and energy consumption. The Bharath Pi then processes this data and can be used to:
- Display real-time power consumption: You can set up a display or web interface to monitor the current power draw, voltage, and other parameters.
- Log historical data: Store the collected data over time to analyze trends and identify areas for energy savings.
- Integrate with other systems: Connect the system to smart home platforms or automation systems for further control and analysis.
Steps to get started:
- Gather your components: Make sure you have all the necessary hardware and software tools.
- Connect the hardware: Follow the instructions for your specific Pzem-004t and Bharath Pi to connect them properly and safely.
- Write the code: You'll need to program the Bharath Pi to read data from the Pzem-004t, process it, and display or store it as desired. There are many libraries and resources available online for this purpose.
- Test and refine: Run your system and verify that it's working correctly. Adjust your code and settings as needed.
- Expand and customize: Depending on your goals, you can add features like data visualization, remote access, or integration with other systems.
PIN CONNECTION
- Connect the V+ pin of the PZEM-004T to a 5V power supply pin on the Bharath pi board.
- Connect the V- pin of the PZEM-004T to the GND (Ground) pin on the Bharath pi board.
- Connect the RX pin of the PZEM-004T to a digital pin on the Bharath pi board (e.g., Pin 16).
- Connect the TX pin of the PZEM-004T to another digital pin on the Bharath pi board (e.g., Pin 17).
Hardware Setup:
- The PZEM-004T sensor is connected to the microcontroller (e.g., Arduino, ESP8266, or ESP32) using jumper wires. The current coil is clamped around the wire carrying the AC current to be measured.
- The microcontroller is also connected to a Wi-Fi module (if not built-in) to enable internet connectivity.
Preferences Initialization:
- At the beginning of the program, the Preferences library is initialized with a unique namespace, which will be used to store the configuration settings.
Calibration (optional):
- Depending on the specific PZEM sensor and current coil used, calibration might be necessary to ensure accurate readings. Calibration factors or correction values can be stored in the Preferences.
Reading and Storing Data:
- The microcontroller reads electrical parameters (e.g., voltage, current, power) from the PZEM sensor at regular intervals.
- The obtained data is then stored in the Preferences using appropriate keys (e.g., "voltage", "current", "power").
- Above diagram shows the complete wiring illustration, don’t forget to give the detector mains input and also to sense the current, one of the lines for cargo should go through the ct detector.
Note: Before making any connections, ensure the circuit is disconnected from the main power source to avoid accidents.
Code Snippet#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Preferences.h>
#include <PZEM004Tv30.h>
// LCD settings
int lcdColumns = 16;
int lcdRows = 2;
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
// PZEM settings
PZEM004Tv30 pzem(Serial2, 16, 17); // RX, TX
// Preferences settings
Preferences preferences;
unsigned long lastUpdateTime = 0;
float totalPowerConsumed = 0.0;
float totalCurrentConsumed = 0.0;
float currentConsumedToday = 0.0;
float powerConsumedToday = 0.0;
void setup() {
// Initialize the LCD
Serial.begin(115200);
Serial.begin(115200);
lcd.begin();
lcd.setCursor(0, 0);
Serial.println("power monitoring");
delay(500);
lcd.print("Power Monitoring");
lcd.setCursor(0, 1);
lcd.print("by refillbot.com");
Serial.println("by refillbot.com");
delay(500);
delay(2000);
lcd.clear();
lcd.begin();
lcd.backlight();
preferences.begin("power_prefs", false);
totalPowerConsumed = preferences.getFloat("totalPowerConsumed", 0.0);
totalCurrentConsumed = preferences.getFloat("totalCurrentConsumed", 0.0);
// Print initial values on LCD
lcd.setCursor(0, 0);
lcd.print("Power: -- W");
lcd.setCursor(0, 1);
lcd.print("Current: -- A");
delay(2000);
}
void loop() {
unsigned long currentTime = millis();
if (currentTime - lastUpdateTime >= 1000) {
lastUpdateTime = currentTime;
// Read the voltage, current, power, and frequency from the PZEM
float voltage = pzem.voltage();
float current = pzem.current();
float power = pzem.power();
float frequency = pzem.frequency();
// Calculate energy consumed in 1 second
float energyConsumed = power / 3600.0;
// Calculate energy consumed in one day (24 hours)
float energyConsumedOneDay = energyConsumed * 24.0;
// Calculate power consumed in one day
powerConsumedToday += energyConsumed;
// Calculate current consumed in one day
currentConsumedToday += current;
// Update total cumulative values
totalPowerConsumed += energyConsumed;
totalCurrentConsumed += current;
// Save the cumulative values to Preferences library
preferences.putFloat("totalPowerConsumed", totalPowerConsumed);
preferences.putFloat("totalCurrentConsumed", totalCurrentConsumed);
lcd.setCursor(0, 0);
lcd.print("Power: ");
lcd.print(power);
lcd.print(" W");
lcd.setCursor(0, 1);
lcd.print("Current: ");
lcd.print(current);
lcd.print(" A");
Serial.print("Power: ");
Serial.print(power);
Serial.println(" W");
Serial.print("Current: ");
Serial.print(current);
Serial.println(" A");
delay(4000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Frequency: ");
lcd.print(frequency);
lcd.print(" Hz");
lcd.setCursor(0, 1);
lcd.print("Energy: ");
lcd.print(energyConsumed, 3);
lcd.print(" Wh");
delay(4000);
Serial.print("Frequency: ");
Serial.print(frequency);
Serial.println(" Hz");
Serial.print("Energy: ");
Serial.print(energyConsumed, 3);
Serial.println(" Wh");
delay(4000);
lcd.begin();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Power C: ");
lcd.print(powerConsumedToday, 3);
lcd.print(" Wh");
lcd.setCursor(0, 1);
lcd.print("Voltage C: ");
lcd.print(totalPowerConsumed, 3);
lcd.print(" Wh");
delay(4000);
Serial.print("Power Consumption Today: ");
Serial.print(powerConsumedToday, 3);
Serial.println(" Wh");
Serial.print("Voltage Consumption Total: ");
Serial.print(totalPowerConsumed, 3);
Serial.println(" Wh");
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Current_c: ");
lcd.print(currentConsumedToday, 3);
lcd.print(" A");
lcd.setCursor(0, 1);
lcd.print("Current_T: ");
lcd.print(totalCurrentConsumed, 3);
lcd.print(" A");
delay(4000);
Serial.print("Curren _C _T: ");
Serial.print(currentConsumedToday, 3);
Serial.println(" A");
Serial.print("Current Total: ");
Serial.print(totalCurrentConsumed, 3);
Serial.println(" A");
delay(1000);
}
Comments
Please log in or sign up to comment.