Tech Gyan Set
Published © MIT

Smart Room-Wise Electricity Waste Detection System

Smart system that detects power waste in empty rooms and turns data into savings. ⚡

BeginnerFull instructions provided8 hours15
Smart Room-Wise Electricity Waste Detection System

Things used in this project

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

1️⃣ Libraries + Pin Configuration

C/C++
// ===== Libraries =====
#include <WiFi.h>

// ===== Pin Configuration =====
#define PIR_PIN 27
#define CURRENT_SENSOR_PIN 34
#define BUZZER_PIN 23
#define RELAY_PIN 26

// ===== Variables =====
bool roomOccupied = false;
bool loadOn = false;
bool wasteDetected = false;

unsigned long emptyStartTime = 0;
unsigned long wasteThreshold = 300000; // 5 minutes (in ms)

float currentValue = 0;
float currentThreshold = 0.2;  // Adjust according to calibration

2️⃣ Setup Function

C/C++
void setup() {
  Serial.begin(115200);

  pinMode(PIR_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(RELAY_PIN, OUTPUT);

  digitalWrite(BUZZER_PIN, LOW);
  digitalWrite(RELAY_PIN, HIGH); // Appliance ON initially

  Serial.println("⚡ Smart Electricity Waste Detector Started");
}

3️⃣ Read Motion Sensor (Room Occupancy)

C/C++
void checkMotion() {
  int motionState = digitalRead(PIR_PIN);

  if (motionState == HIGH) {
    roomOccupied = true;
    emptyStartTime = 0; // Reset timer
  } else {
    roomOccupied = false;
  }

  Serial.print("Room Occupied: ");
  Serial.println(roomOccupied ? "YES" : "NO");
}

4️⃣ Read Current Sensor (Load Detection)

C/C++
void checkLoad() {
  int sensorValue = analogRead(CURRENT_SENSOR_PIN);

  // Convert to voltage
  float voltage = sensorValue * (3.3 / 4095.0);

  // Basic current estimation (needs calibration)
  currentValue = (voltage - 2.5) / 0.066;

  if (currentValue > currentThreshold) {
    loadOn = true;
  } else {
    loadOn = false;
  }

  Serial.print("Load ON: ");
  Serial.println(loadOn ? "YES" : "NO");
}

5️⃣ Waste Detection Logic (Main Smart Logic)

C/C++
void detectWaste() {

  if (!roomOccupied && loadOn) {

    if (emptyStartTime == 0) {
      emptyStartTime = millis();
    }

    if (millis() - emptyStartTime > wasteThreshold) {
      wasteDetected = true;
      Serial.println("🚨 ELECTRICITY WASTE DETECTED!");
    }

  } else {
    wasteDetected = false;
    emptyStartTime = 0;
  }
}

6️⃣ Alert System (Buzzer + Optional Auto OFF)

C/C++
void handleAlert() {

  if (wasteDetected) {
    digitalWrite(BUZZER_PIN, HIGH);

    // Optional: Auto turn off appliance
    digitalWrite(RELAY_PIN, LOW);

  } else {
    digitalWrite(BUZZER_PIN, LOW);
  }
}

7️⃣ Monthly Wastage Counter Logic (Basic Example)

C/C++
unsigned long wasteMinutes = 0;

void calculateWastageReport() {

  static unsigned long lastMinuteCheck = 0;

  if (wasteDetected) {

    if (millis() - lastMinuteCheck > 60000) {
      wasteMinutes++;
      lastMinuteCheck = millis();
    }

  }

  Serial.print("Total Waste Minutes: ");
  Serial.println(wasteMinutes);
}

8️⃣ Main Loop

C/C++
void loop() {

  checkMotion();
  checkLoad();
  detectWaste();
  handleAlert();
  calculateWastageReport();

  delay(1000);
}

Credits

Tech Gyan Set
10 projects • 2 followers
Thanks to Tech Gyan Set .

Comments