Phone : +8801894-801150 Email : projects.zeronebd@gmail.com
support 24/7
project photo

How to Make IOT Power Supply Control by 3 Different Source

Now we are going to learn about a new project. This project is Iot based, we will look over a system where we will collect 3 different types of power in a system.

Introduction:
This project aims to develop an IoT-based smart power supply management system that automatically selects and switches between three different power sourcessolar power, battery backup, and the main grid supply—to ensure uninterrupted power to connected loads. The system uses current and voltage sensors to monitor each source's availability and health. A microcontroller (NodeMCU or ESP32) evaluates sensor data and makes intelligent switching decisions. Through IoT integration, the user can monitor real-time power source status, consumption data, and receive alerts remotely via a Blynk or custom mobile/web application.

Materials:
NodeMCU / ESP32
ZMPT101B Voltage Sensor
ACS712 / ACS758 Current Sensor
Relay Module (3-channel)
Solar Panel
Solar Charge Controller
Battery (12V/24V)
SMPS / AC to DC Adapter
Blynk Board / Wi-Fi Module
Resistors
Diodes
Capacitors
Connecting Wires
Breadboard / PCB
LCD / OLED Display (optional)
Applications:
Home and office energy automation.
Smart grids in remote/rural areas.
IoT-based disaster-resilient power systems.
Renewable energy integration.

CODE:
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// WiFi credentials
char ssid[] = "YourWiFiSSID";
char pass[] = "YourWiFiPassword";
// Blynk authorization token
char auth[] = "YourBlynkAuthToken";
// Pin definitions
#define SOLAR_VOLT_PIN A0
#define BATTERY_VOLT_PIN A1
#define GRID_VOLT_PIN A2
#define RELAY_SOLAR D1
#define RELAY_BATTERY D2
#define RELAY_GRID D3
// Voltage thresholds
const int voltageThreshold = 600; // Example threshold value, adjust accordingly
void setup() {
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode(RELAY_SOLAR, OUTPUT);
  pinMode(RELAY_BATTERY, OUTPUT);
  pinMode(RELAY_GRID, OUTPUT);
  digitalWrite(RELAY_SOLAR, LOW);
  digitalWrite(RELAY_BATTERY, LOW);
  digitalWrite(RELAY_GRID, LOW);
}
void loop() {
  Blynk.run();
  controlPowerSource();
  delay(2000);
}
void controlPowerSource() {
  int solarVoltage = analogRead(SOLAR_VOLT_PIN);
  int batteryVoltage = analogRead(BATTERY_VOLT_PIN);
  int gridVoltage = analogRead(GRID_VOLT_PIN);
  Serial.print("Solar Voltage: ");
  Serial.print(solarVoltage);
  Serial.print(" | Battery Voltage: ");
  Serial.print(batteryVoltage);
  Serial.print(" | Grid Voltage: ");
  Serial.println(gridVoltage);
  if (solarVoltage > voltageThreshold) {
    switchToSource(RELAY_SOLAR);
  } 
  else if (batteryVoltage > voltageThreshold) {
    switchToSource(RELAY_BATTERY);
  } 
  else if (gridVoltage > voltageThreshold) {
    switchToSource(RELAY_GRID);
  } 
  else {
    // No source available
    allRelaysOff();
  }
  // Send voltage data to Blynk
  Blynk.virtualWrite(V0, solarVoltage);
  Blynk.virtualWrite(V1, batteryVoltage);
  Blynk.virtualWrite(V2, gridVoltage);
}
void switchToSource(int relayPin) {
  digitalWrite(RELAY_SOLAR, LOW);
  digitalWrite(RELAY_BATTERY, LOW);
  digitalWrite(RELAY_GRID, LOW);
  digitalWrite(relayPin, HIGH);
  Serial.print("Switched to relay pin: ");
  Serial.println(relayPin);
}
void allRelaysOff() {
  digitalWrite(RELAY_SOLAR, LOW);
  digitalWrite(RELAY_BATTERY, LOW);
  digitalWrite(RELAY_GRID, LOW);
  Serial.println("All relays off. No power source available.");
}