element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Particle
  • Products
  • Dev Tools
  • Single-Board Computers
  • Particle
  • More
  • Cancel
Particle
Forum Detecting Unstable Electrical Grid with TinyML
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Particle to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 0 replies
  • Subscribers 21 subscribers
  • Views 1025 views
  • Users 0 members are here
  • particle
  • electrical grid
  • machine learning
  • Neuton
  • electrical
Related

Detecting Unstable Electrical Grid with TinyML

AlexMiller
AlexMiller over 3 years ago

Hi everyone!


I conducted an experiment to find out how ML can be useful in the energy sector. In my area, voltage surges are a common thing (and annoying), so I made a model to predict if the electrical grid is stable or not. Although I wasn’t able to check the model performance in real conditions for lack of special equipment, it worked well on the test dataset.


image

Things used in this project:

Hardware components

Particle Argon×1

Software apps and online services

Neuton Tiny ML
Particle Build Web IDE

Introduction

Electricity is the heart of modern social and economic development. More and more countries strive to transfer to sustainable energy systems, which is quite a challenging process, as it causes increasingly unstable power generation and grid overloads. The unstable electrical grid can endanger people's lives and the safety of their property. This means that power systems should undergo timely monitoring and optimization, which AI and machine learning can easily handle.

In fact, artificial intelligence has become an essential tool in the power industry. It provides unique self-learning solutions for energy consumption analysis and grid monitoring under dynamically changing circumstances. In this project, we’ll explore how to leverage a machine learning model for efficient monitoring of the electrical grid as shown on the video.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image


Renewable Energy Sources & Smart Economy

The ascent of renewable energy sources provide the global community with a much demanded alternative to traditional, finite, and climate-unfriendly fossil fuels. However, their adoption poses a set of new paradigms, the two of which deserve particular attention:

  • Prior to the rise of renewable energy sources, the traditional ecosystem involved few production entities (sources) supplying energy to consumers over unidirectional flows. With the advent of renewable options, end-users (households and enterprises) now not only consume energy but have the ability to produce and supply it. Also, for a reliable ecosystem, people need to ensure that energy grids are smarter and equipped with accurate detection of threats and faults.

    image


  • Despite the increased flexibility of renewable sources, the management of supply and demand in a more complex generation/distribution/consumption environment and the related economic implications (e.g. the decision to buy energy at a given price or not) have become even more challenging.

Need for Grid Stability

In a smart grid, consumer demand information is collected, and centrally evaluated against current supply conditions. The resulting proposed price information is sent back to customers for them to make decisions about further usage. As the whole process is time-dependent, dynamic estimation of grid stability becomes not only a concern but a major requirement.


image

Put simply, the objective is to understand and plan for both energy production and/or consumption disturbances and fluctuations introduced by system participants in a dynamic way, taking into consideration not only technical aspects but also how participants respond to changes in the associated economic aspects (energy costs).

The Challenges of Applying AI to Smart Electric Grids

  • Insufficient data accumulation: there aren’t enough data samples that meet the requirements of diverse AI technology applications, and sample collection can be a time-consuming process.
  • Reliability: although AI technology applied to power systems demonstrates high levels of problem identification, it doesn’t always meet the requirements of practical application.
  • Infrastructure: applying AI is based on abundant data samples, advanced computing power, and distributed communication collaboration. However, the supporting capacity and level of relevant infrastructure resources such as quick production AI algorithms, and distributed collaboration platforms need improvement.
  • Lack of power industry-specific algorithms: compared to perception, prediction, and security maintenance, algorithm adaptability of AI in power systems is still weak.

Solution

In this project, we will explore how we can predict electric grid stability with a free platform, Neuton Tiny ML platform, and an integrated IoT Platform-as-a-Service, Particle IoT that helps to deploy software applications to connected devices, from edge to cloud and back.

Also, we will explore the communication infrastructure for such electric grid operations. With the combined knowledge of AI and IoT, we will try to solve some parts of the above-mentioned challenges.


image

Dataset

The original dataset contains 10, 000 observations. It also contains 12 primary predictive features and two dependent variables.

Predictive features:

  • 'tau1' to 'tau4': the reaction time of each network participant, a real value within the range 0.5 to 10 ('tau1' corresponds to the supplier node, 'tau2' to 'tau4' to the consumer nodes);
  • 'p1' to 'p4': nominal power produced (positive) or consumed (negative) by each network participant, a real value within the range -2.0 to -0.5 for consumers ('p2' to 'p4'). As the total power consumed equals the total power generated, p1 (supplier node) = - (p2 + p3 + p4);
  • 'g1' to 'g4': price elasticity coefficient for each network participant, a real value within the range 0.05 to 1.00 ('g1' corresponds to the supplier node, 'g2' to 'g4' to the consumer nodes; 'g' stands for 'gamma');

Dependent variables:

  • 'stab': the maximum real part of the characteristic differentia equation root (if positive, the system is linearly unstable; if negative, linearly stable);
  • 'stabf': a categorical (binary) label ('stable' or 'unstable').

As there is a direct relationship between 'stab' and 'stabf', 'stab' will be dropped and 'stabf' will remain as the sole dependent variable. Here is the link to the dataset:https://archive.ics.uci.edu/ml/datasets/Electrical+Grid+Stability+Simulated+Data+

Procedure

Step 1: Importing the dataset and choosing the target variable

On the Neuton platform, we will upload the dataset for our use case and select 'stabf' as the target variable.

image

In the training parameters, set the Input data type FLOAT32 and Normalization type "Unique scale for each feature". Then proceed to model training.

image

Step 2: Training and Exploratory Data Analysis

Once the training has started, we see the model data analysis which helps us to understand the close relationship between the original dependent and independent variables.

image

Correlation:

It is important to verify the correlation between each numerical feature and the dependent variable, as well as the correlation among numerical features leading to potential undesired collinearity. The heatmap below provides an overview of the correlation between the dependent variable ('stabf' or 'target') and the top 10 numerical features with the highest binary correlation to the target.


image

After the training is over, we can see the model metrics: the model accuracy is 0.921435!

image

We can also see the classification performance using the generated confusion matrix.

image

Download the model for further deployment on our IoT device.

image


Step 3: Hardware setup and model embedding

We have selected the Particle Argon board for this project (although you can use any Particle board without the need to reprogram each board). The Particle Argon is a powerful Wi-Fi development kit that you can use on Wi-Fi networks.

Equipped with the Nordic nRF52840 and Espressif ESP32 processors, the Argon has built-in battery charging circuitry which makes it easier to connect a Li-Po battery and 20 mixed-signal GPIOs to interface with sensors, actuators, and other electronics.

image

Particle IoT boards are secure and fully equipped to allow Smart Grid Infrastructure to deliver data and updates on grid failures at a faster and cheaper rate.

Setting up Particle IDEand Workbench:

Add your downloaded Neuton model inside the Particle Workbench project folder. Your folder structure will look like this (checksum, parser, protocol, application and StatFunctions) These files are required to make predictions on data received over serial communication using the CSV uploader tool.

image

Here is the most important function:

static float* on_dataset_sample(float* inputs)
{
 if (neuton_model_set_inputs(inputs) == 0)
  {
 uint16_t index;
 float* outputs;

 uint64_t start = micros();
 if (neuton_model_run_inference(&index, &outputs) == 0)
    {
 uint64_t stop = micros();
 
 uint64_t inference_time = stop - start;
 if (inference_time > max_time)
        max_time = inference_time;
 if (inference_time < min_time)
        min_time = inference_time;

 static uint64_t nInferences = 0;
 if (nInferences++ == 0)
      {
        avg_time = inference_time;
      }

else
      {
        avg_time = (avg_time * nInferences + inference_time) / (nInferences + 1);
      }

      RGB.control(true);

      RGB.color(255, 255, 255);   // white
 
 switch (index)
      {
 case 0:      
        Particle.publish("Prediction: Stable Grid", String(index));
        RGB.color(0, 255, 0);
 break;
 
 case 1:
        Particle.publish("Prediction: Unstable Grid", String(index));
        RGB.color(255, 0, 0);
 break;
 
 default:
 break;
      }

 return outputs;
    }
  }

 return NULL;
}



Compile the application in the cloud or locally. Once compiled, you are ready to flash it to your device. Make sure you have selected the correct Particle OS for your device.


image

CSV data upload utility:

We are going to test our predictions by sending the test data features from our test dataset CSV file over a USB serial port.

  • Install dependencies,

    # For Ubuntu
    $ sudo apt install libuv1-dev gengetopt
    # For macOS
    $ brew install libuv gengetopt



  • Clone this repo,
    $ git clone https://github.com/Neuton-tinyML/dataset-uploader.git
    $ cd dataset-uploader



  • Run “make” to build the binaries,
    $ make



Once it's done, you can send the CSV file over USB.

$./uploader -s /dev/ttyACM0 -b 230400 -d /home/vil/Desktop/electric_grid_test.csv


image

The prediction is printed on the Particle IoT cloud.

image

Monitoring the stability of the electrical grid helps to reveal "unreliable" energy sources and avoid serious damage. The best strategy for such AI+IoT projects is not only making predictions but also collecting and reporting data in order to improve models for future devices like Particle and make OTA updates easier.

  • Sign in to reply
  • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube