Power grids are one of the most sophisticated machines humans have ever built and our life is highly dependent on it. Like fire, electricity also needs to be controlled and power grids are built for that. In simple words, Power grids are responsible for distributing electricity over a large area using a network of power lines and equipment like transformers.
We have several ways of generating electricity. However, we can broadly classify the methods of electricity generation into 3 types: Nuclear power plants, Renewable energy sources, and Non-renewable energy sources. All the power generated by these sources is connected to the power grid which distributes the energy as per our requirements.
We know that energy generation using fossil fuels is the most hazardous to our environment and renewables are most environment friendly. However, we can not stop using fossil fuels altogether because renewables can not fulfill our needs for now. So we need to optimize the power grid so that it can only use fossil fuels whenever necessary.
Sounds simple isn't it? Now, Have a look at the graph below showing the typical usage of electricity in 24 hours of time. (Source: A typical all-India daily load curve., Download Scientific Diagram)
You can see that the power demand varies a lot and we need to take care of that otherwise there will be consequences.
Theory and Working
To solve this issue we will create an IoT-based smart power grid that will help us to optimize our power grids and make them smart so that they can easily use all types of energy generation solutions (renewable and non-renewable) and automatically reduce the use of fossil fuels as possible by taking autonomous decision based on the power requirements. It will only turn on fossil fuel-based power plants if the renewables and nuclear combined are not sufficient enough. Additionally, it will share all the data on an IoT dashboard where it is stored as well as monitored continuously.
Project Demonstration
- For the demonstration of the project, I am considering a power grid connected to a nuclear power plant, some renewable energy source (Say offshore wind farm), and a fossil fuel-based source (say coal-based) for handling varying consumer power requirements.
- I am designing a system that can continuously monitor the power output of the grid and based on the requirements it can switch on/off the energy sources.
- At a time, based on the required consumer power, any of the energy sources or any combination of them is switched on.
- In my system “turned off” means stand by as these power stations are complex to operate and can’t be turned on/off with a flick of a switch at a moment's notice.
Components Required
- ESP8266/ESP32 board
- INA219 Module
- LEDs
- 570-ohm Resistors for LEDs
- Jumper wires
- Breadboard
- Thingspeak Cloud Account
- Power supply adaptor (10 Watts)
I got the ESP8266/ESP32 board and INA219 Module from Digikey and all the other components are available in the local market.
Circuit Diagram
The working of the circuit is quite simple and straightforward. I am using a Node MCU board as the brains of the system. INA 219 module is there for continuously reading the output power. LEDs are there for the variable load. As we turn on/off the LEDs the power changes. The SCL and SDA pins of the INA 219 Module is connected to the D1 and D2 pin of Node MCU and its VCC and GND pins are connected to the 3.3V and GND of Node MCU to power our module. The INA 219 module is connected in series with our LEDs where vin+ is connected to the positive side of the DC adaptor and vin- pin is connected to the LED. The negative side of the DC adaptor is connected to the GND pin of node MCU.
Final Circuit on Breadboard
Make the circuit on the breadboard as shown below.
Thingspeak Cloud Setup
Create an account/sign in to a ThingSpeak Account.
Create a new channel. Give it the name “IoT-based smart power grid” and select 3 fields by clicking the box next to the field. Give names to the fields as Voltage, current, and power respectively.
Keep all the values as default and click save channel.
Node MCU Code
Upload the code provided to your Node MCU development board. If you wish, with slight modifications in the code, you can also use an ESP32 board or an Arduino along with an ESP8266 board for wifi.
Copy and Paste the API key of your channel and wifi credentials in the code. You can get the API key by navigating to the API keys tab as shown below.
Working
I am using a node MCU board as the brains of the system. It is processing all the data as well as sending the data to the ThingSpeak cloud. For monitoring the output power, I am using an INA219 DC current sensor. For load, I am using LEDs which are in a pair of 4 representing the load on our power grid as 25%, 50%, 75%, and 100% respectively.
For different loads, we are getting specific power consumption as shown below:
At 100% load
At 75% load
At 50% load
At 25% load
Add and Configure ThingSpeak Widgets
As per the output values of the sensor, I am using conditions in the ThingSpeak cloud’s lamp widget.
Navigate to our IoT-based smart power grid channel and click on add widgets.
Select the “Lamp” widget and name it “Renewables”. Similarly, add two more Lamp widgets and name them “Non-Renewables” and “Nuclear” Respectively.
If you want, you can also add gauges for better visualization along with the graphs.
Now we need to configure the widgets. It requires a value based on which it turns on or turns off (if condition). These values can be obtained by observing the data that we got after running the system for quite a while. You can check the values using the exported data from the ThingSpeak platform (.csv file) or check the serial monitor output of Arduino IDE.
You can get the CSV file by clicking the “Export recent data” on our ThingSpeak channel
Serial monitor output of Arduino IDE
Note that the values are completely dependent on the type of load you are using. I am using LEDs and my values for Renewables, Non-Reneables, and Nuclear are 20 mW, 100 mW, and 70 mW respectively.
Testing the Project
Now after putting the values as per your setup, the project is ready. The ThingSpeak cloud lamps will turn on/off depending on the load. You can check the working by individually turning on/off the LEDs.
For a 25% load
For 50 to 75% load
For 100% load
Advantages of Using This System
- Better management of available resources.
- Better supply and demand management.
- Reduced greenhouse gas emissions and better for the environment without impacting end-user requirements.
- Increase in overall efficiency of power transmission.
- Easy fault detection and troubleshooting.
- IoT data can be used to develop AI models for more refinement in the system.
- Easy to use and implement in existing power grid infrastructure.
- Avoid excess generation using fossil fuels.
- Automatic decisions reduce human errors.
- Safeguards are in place if some catastrophe happens.
- Remote operation is possible.
And many more….
Enclosures
- Node MCU Program
- Project Images
- Project Demonstration and explanation video (2 separate videos)
- IoT data from ThingSpeak and Arduino serial monitor output.
- Circuit Diagrams
- Digikey details
#include <Wire.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219;
#include <ESP8266WiFi.h>
String apiKey = ""; // Enter your API key from ThingSpeak
const char *ssid = ""; // replace with your wifi ssid and wpa2 key
const char *pass = "";
const char* server = "api.thingspeak.com";
#define renewables D5
#define nonReneables D6
#define nuclear D7
WiFiClient client;
void setup()
{
Serial.begin(115200);
delay(10);
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
while (!Serial) {
// will pause Zero, Leonardo, etc until serial console opens
delay(1);
pinMode(renewables, OUTPUT);
pinMode(nonReneables, OUTPUT);
pinMode(nuclear, OUTPUT);
}
Serial.println("Hello!");
if (! ina219.begin()) {
Serial.println("Failed to find INA219 chip");
while (1) { delay(10); }
}
Serial.println("Measuring voltage and current with INA219 ...");
}
void loop()
{
float shuntvoltage = 0;
float busvoltage = 0;
float current_mA = 0;
float loadvoltage = 0;
float power_mW = 0;
shuntvoltage = ina219.getShuntVoltage_mV();
busvoltage = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
power_mW = ina219.getPower_mW();
loadvoltage = busvoltage + (shuntvoltage / 1000);
Serial.print("Bus Voltage: "); Serial.print(busvoltage); Serial.println(" V");
Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage); Serial.println(" mV");
Serial.print("Load Voltage: "); Serial.print(loadvoltage); Serial.println(" V");
Serial.print("Current: "); Serial.print(current_mA); Serial.println(" mA");
Serial.print("Power: "); Serial.print(power_mW); Serial.println(" mW");
Serial.println("");
delay(2000);
if (client.connect(server,80)) // "184.106.153.149" or api.thingspeak.com
{
String postStr = apiKey;
postStr +="&field1=";
postStr += String(loadvoltage);
postStr +="&field2=";
postStr += String(current_mA);
postStr +="&field3=";
postStr += String(power_mW);
postStr += "\r\n\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.println("%. Send to Thingspeak.");
}
client.stop();
Serial.println("Waiting...");
// thingspeak needs minimum 15 sec delay between updates
delay(1000);
if (power_mW<10)
{
digitalWrite(renewables, HIGH);
digitalWrite(nonReneables, LOW);
digitalWrite(nuclear, LOW);
}
else if (power_mW<30)
{
digitalWrite(renewables, HIGH);
digitalWrite(nonReneables, LOW);
digitalWrite(nuclear, HIGH);
}
else
{
digitalWrite(renewables, HIGH);
digitalWrite(nonReneables, HIGH);
digitalWrite(nuclear, HIGH);
}
}