<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Wongani Tembo on Medium]]></title>
        <description><![CDATA[Stories by Wongani Tembo on Medium]]></description>
        <link>https://medium.com/@wonganitembo02?source=rss-9444a4149e24------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*adz7OdAzVUq1WOw3</url>
            <title>Stories by Wongani Tembo on Medium</title>
            <link>https://medium.com/@wonganitembo02?source=rss-9444a4149e24------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 01:53:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@wonganitembo02/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Tokenless Prepaid Meters And Anomaly Detection — The Future of Prepaid Electricity]]></title>
            <link>https://medium.com/@wonganitembo02/tokenless-prepaid-meters-and-anomaly-detection-the-future-of-prepaid-electricity-abd6b625749d?source=rss-9444a4149e24------2</link>
            <guid isPermaLink="false">https://medium.com/p/abd6b625749d</guid>
            <dc:creator><![CDATA[Wongani Tembo]]></dc:creator>
            <pubDate>Fri, 01 Aug 2025 14:24:00 GMT</pubDate>
            <atom:updated>2025-08-06T18:37:06.122Z</atom:updated>
            <content:encoded><![CDATA[<h3>Tokenless Prepaid Meters And Anomaly Detection — The Future of Prepaid Electricity</h3><p><strong>“We will make electricity so cheap that only the rich will burn candles.”</strong><br> — <em>Thomas Edison</em></p><h3><strong>Background</strong></h3><p>According to the Malawi Integrated Electrification Plan report of 2022, the Electricity Supply Corporation of Malawi (ESCOM) and other off-grid providers supply electricity to approximately 750,000 households, with about 550,000 served by the national grid and 200,000 off-grid. Additionally, 3,992 public facilities are connected to grid electricity, while 346 are off-grid. This translates to roughly 3.4 million people having access to electricity out of 4,435,000 households, representing a total population of 16.6 million as of 2022. Among ESCOM’s grid-served customers, electricity is accessed either through prepaid or postpaid billing systems. Prepaid billing — where customers pay in advance before using electricity — has become the preferred option for many due to its flexibility and the control it offers over energy consumption and budgeting. According to a 2023 Nyasa Times report, ESCOM has installed over 537,000 prepaid meters, reflecting the significant growth in the adoption of prepaid electricity billing.</p><h3><strong>The Problem</strong></h3><p>The current prepaid electricity meter system used by ESCOM presents significant challenges to consumers, particularly in terms of usability, accessibility, and safety. Consumers are unable to monitor their real-time electricity consumption or receive alerts for unusual usage patterns, which contributes to issues such as overloading and increases the risk of electricity-induced fires. Additionally, the system relies on token-based recharging, which requires manual entry of a 20-digit code while the meter is powered using batteries — an impractical requirement when batteries are unavailable. Consumers also lack remote access to their consumption data or balance, leading to unexpected power outages and significant inconvenience, especially during odd hours. These limitations highlight the urgent need for a smarter, more seamless, and user-friendly prepaid metering solution.</p><h3><strong>The Proposed Solution</strong></h3><p>To address the limitations in the current prepaid metering system, we propose the development of a robust Internet of Things (IoT)-based smart metering solution that focuses on real-time electricity monitoring, seamless unit purchasing, and enhanced user safety. Our approach aims to create a more consumer-friendly experience that reduces inconvenience and empowers users with the tools they need to manage their electricity consumption more effectively.</p><p>We are building a system that continuously monitors electricity usage in real time, giving users clear visibility into their consumption patterns. This will not only help households make informed decisions on how to use electricity more efficiently, but will also enable them to detect and respond to unusual or excessive usage. By integrating anomaly detection algorithms, we can automatically identify sudden spikes or prolonged high usage and promptly notify users through SMS, web, or mobile app alerts. This early warning system enhances safety by reducing the risk of overloads and electrical fires.</p><p>To simplify the recharge process, we are implementing a tokenless, smart purchase system. Instead of manually entering 20-digit tokens using batteries, customers will be able to buy electricity units through a secure mobile or web application. Once a transaction is completed, the system will automatically update the user’s meter balance and reconnect them to power instantly. In situations where the user’s phone is unavailable, electricity can still be purchased through any device with internet access, as long as the meter number is known.</p><p>Furthermore, we are embedding a safety mechanism within the system that can trigger alerts or take predefined actions when abnormal usage is detected. This feature empowers users to act quickly or even allows the system to self-regulate based on safety thresholds.</p><h3><strong>The Concept</strong></h3><h3><strong>1. Tokenless Prepaid Meter</strong></h3><p>This project involved the development of a smart electricity meter designed to replicate the functionality of pole-mounted prepaid meters commonly used by utility providers. The primary objective of the meter was to measure electricity consumption, manage prepaid credit balances, and communicate with a central utility database for remote updates and control.</p><h4>System Components</h4><p>The system was composed of the following key components:</p><ul><li><strong>ESP32 Development Board</strong> — served as the main microcontroller, responsible for processing data and managing communication.</li><li><strong>SCT-013–000 Non-Invasive AC Current Sensor</strong> — measured the amount of current drawn by the connected load.</li><li><strong>ZMPT101B AC Voltage Sensor Module</strong> — monitored the voltage level of the supply.</li><li><strong>Relay Module (1-Channel or 4-Channel)</strong> — acted as an automated switch to control the power supply to the household.</li><li><strong>Step-Down Transformer</strong> — reduced the high-voltage AC input to a safer, lower voltage suitable for electronic components.</li><li><strong>Bridge Rectifier and Capacitive Filter</strong> — converted the AC signal to DC and smoothed it for consistent voltage output.</li><li><strong>Voltage Regulator (e.g., LM7805)</strong> — maintained a stable 5V DC supply required for the ESP32 and associated components.</li><li><strong>EEPROM (Electrically Erasable Programmable Read-Only Memory)</strong> — stored the current prepaid balance locally.</li><li><strong>Weatherproof Enclosure, Connectors, and Insulated Cables</strong> — ensured safe and reliable outdoor operation.</li></ul><h4>System Connections</h4><p>The system was powered by an AC mains supply, which was first stepped down using a transformer. This reduced voltage was then rectified and filtered to produce DC, and finally regulated to 5V to power the ESP32 and sensors.</p><p>The <strong>current transformer (CT sensor)</strong> measured the electric current passing through the household wiring and provided a signal proportional to the usage. Simultaneously, the <strong>voltage sensor (VT)</strong> read the supply voltage. Both sets of data were captured by the ESP32, which used them to calculate power consumption.</p><h4>System Operation</h4><p>The ESP32 microcontroller continuously read data from the current and voltage sensors to monitor real-time energy consumption. It used this information to deduct usage from the remaining electricity balance, which was stored locally on the EEPROM.</p><p>The system was designed to periodically synchronize with the utility provider’s central database. During a recharge, the updated balance was sent from the utility and stored in the EEPROM to minimize constant database queries and avoid latency. This also allowed the system to operate effectively in areas with unstable connectivity.</p><p>When the electricity balance reached zero, the ESP32 triggered the <strong>relay module</strong> to disconnect the power supply, cutting off electricity to the household. Upon receiving confirmation of a top-up, the ESP32 updated the balance and automatically restored power by reactivating the relay.Anomaly Detection</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O-8y0ma_jv2-wURedHvNgQ.png" /></figure><h3><strong>2. Anomaly Detection Device</strong></h3><h4>Materials Used</h4><p>To build the anomaly detection device, we used a selection of sensing and control components that worked together to provide real-time electricity monitoring and anomaly detection. The materials included:</p><ul><li>Raspberry Pi 4</li><li>SCT-013–000 or similar current transformer (CT) sensor</li><li>ZMPT101B or similar voltage transformer (VT) sensor</li><li>1-Channel or 4-Channel Relay Module</li><li>Step-down transformer</li><li>Bridge rectifier</li><li>Capacitive filter</li><li>Voltage regulator (e.g., LM7805)</li><li>Wi-Fi Module (e.g., ESP8266)</li><li>Connectors and terminals</li><li>Insulated cables</li></ul><p>These components formed the core of the monitoring and control system, ensuring stability, accuracy, and communication.</p><h4>System Connections and Architecture</h4><p>At the heart of the system was the Raspberry Pi 4, which acted as the central processing unit for data acquisition, anomaly detection, and communication. The AC power from the household supply (after the meter) was stepped down using a transformer. This voltage was then rectified, filtered, and regulated to deliver a consistent 5V DC output to power the Raspberry Pi.</p><p>A CT sensor was connected to monitor current flow, and a VT sensor was used to measure voltage. These sensors provided real-time input, which the Raspberry Pi processed. Relay modules were installed to control electrical loads based on consumption patterns or anomaly detection logic. The Raspberry Pi was connected to a server via Wi-Fi to facilitate communication with a web or mobile interface.</p><h4>Device Operation</h4><p>Once the system was powered, the sensors began collecting current and voltage readings. The Raspberry Pi continuously processed this data to calculate power consumption and detect any anomalies in the usage pattern.</p><p>If a spike or unusual usage trend was detected, the system took automatic action by triggering relays to isolate high-load appliances or alert the user. The alerts and control interface were accessible via connected mobile or web platforms, keeping users informed in real time.</p><h4>Using LSTM for Intelligence</h4><p>To ensure intelligent and adaptive monitoring, we implemented a Long Short-Term Memory (LSTM) model for analyzing and predicting electricity usage. LSTM networks were well-suited for time-series data, such as household power consumption, and helped identify changes in consumption behavior over time.</p><p>The model was trained on historical energy data to recognize normal usage patterns. Any significant deviation from these patterns was flagged as an anomaly, prompting an alert or control action. This predictive functionality gave users early warnings, enabling them to take corrective steps and improve energy efficiency.</p><h3><strong>The Challenge</strong></h3><p>During the development of the smart prepaid electricity meter system, several challenges were encountered — both on the hardware and computational sides.</p><p>One of the key computational challenges was related to the limited processing power and memory available on the microcontroller platforms used. Due to these resource constraints, we were unable to train our machine learning models on large datasets. This limitation forced us to work with smaller subsets of data, which may have impacted the overall accuracy and generalizability of the model.</p><p>On the hardware side, the most significant challenge was acquiring accurate and reliable readings from the current and voltage sensors. The ESP32 development board, which served as the main controller for the system, was found to be incompatible with some of the analog output characteristics of the SCT-013 current sensor and the ZMPT101B voltage sensor. This incompatibility resulted in unstable or incorrect sensor readings when connected directly to the ESP32.</p><p>To overcome this issue, we introduced an Arduino Uno into the system architecture, as it handled analog signal inputs more reliably. The Arduino Uno was tasked with collecting the analog voltage and current data from the sensors, and the processed readings were then transmitted to the ESP32 via serial communication (UART). While this solution added complexity to the system, it significantly improved the accuracy and stability of the measurements, which were critical for reliable energy usage monitoring.</p><h3>The Prototype</h3><p><strong>Anomaly Detection</strong></p><p>In our implementation, we trained the LSTM model using sequences of power consumption data collected every 30 minutes over a 24-hour period. Each input sequence, referred to as a “window,” consisted of 48 consecutive data points representing energy use across an entire day. The model used this window to predict the next immediate power consumption value. With each new data point, the window slid forward by one interval, allowing the model to continuously learn and update its understanding of usage patterns. This sequence-based approach allowed the LSTM to capture both short- and long-term trends, making it highly effective at forecasting what “normal” power consumption should look like at any given time.</p><p>Once trained, the LSTM model predicted the next value of active power, which we then compared against the actual power readings captured by the anomaly detection device. The difference between the predicted and measured values formed the basis of our anomaly detection system. If the values closely matched, it was considered normal usage. If there was a sudden spike that occurred briefly, it was classified as a <strong>Normal Spike</strong>, which often represents harmless short-term fluctuations like appliance startups or momentary surges. However, if these spikes occurred repeatedly over a longer duration, we categorized the pattern as a <strong>Prolonged Anomaly</strong>. This type of anomaly often suggests persistent abnormal usage or a potential electrical fault.</p><p>In response to a prolonged anomaly, the system took automated action by temporarily disconnecting the affected appliance or load for five seconds and then reconnecting it. This safety response not only helped prevent excessive energy consumption but also reduced the risk of damage to appliances and mitigated potential fire hazards caused by overloading. By integrating the LSTM model into our anomaly detection device, we were able to move beyond simple threshold-based alerts and offer a more intelligent, real-time solution that adapts to the user’s electricity usage and improves household safety and energy efficiency.</p><p><strong>System Interface</strong></p><p>In addition to the physical smart meter prototype, we also developed a comprehensive web-based application to facilitate remote monitoring, management, and user interaction with the prepaid electricity system. The system was designed to enhance user accessibility, provide real-time updates, and improve the overall efficiency of electricity usage management.</p><p>The application consisted of several key modules:</p><ul><li><strong>Electricity Recharge Module</strong>: This feature allowed users to purchase electricity by entering a valid meter number and the desired number of units. Upon successful payment, the system automatically updated the user’s electricity balance and sent an SMS notification confirming the transaction along with the number of units purchased. If a user’s meter had been disconnected due to a zero balance, the system would automatically reconnect the supply once the purchase was made.</li><li><strong>Real-Time Balance Updates</strong>: Users could view their current electricity balance at any time through the platform. The system ensured real-time synchronization with the meter, providing up-to-date information on consumption and remaining units.</li><li><strong>Anomaly Detection Module</strong>: This page displayed insights on how different electrical switches or appliances were consuming electricity. It was directly linked to an anomaly detection device and provided visual indicators when abnormal usage patterns were identified. Users also received SMS alerts whenever such anomalies were detected.</li><li><strong>SMS Notification System</strong>: The platform integrated SMS functionality to enhance communication with users. Notifications were sent for successful transactions, low electricity balance (below 10 units), and detected anomalies, ensuring users remained informed without needing to log into the system constantly.</li><li><strong>User Management Module</strong>: This administrative section handled user registration, meter number assignment, customer detail updates, and account deletion. It was designed to provide flexibility in managing customer information and maintaining a clean, accurate database.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DL4JNxjwnxdeyEIf7Czzog.png" /><figcaption>System Dashboard</figcaption></figure><p><strong>Tokenless prepaid Meter</strong></p><p>The prepaid meter module was designed to monitor electricity usage in real time and deduct consumed energy from a user’s balance. This module integrated four main components: a <strong>current transformer</strong>, a <strong>relay module</strong>, an <strong>Arduino Uno</strong>, and an <strong>ESP32</strong> microcontroller.</p><p>In this setup, the <strong>Arduino Uno</strong> was responsible for measuring the current flowing through the system using the <strong>SCT-013 current transformer</strong>. The analog signal generated by the sensor was processed by the Arduino to determine the real-time current draw. The <strong>relay module</strong>, which controlled the connection or disconnection of power to the user, was also managed by the Arduino. This allowed the system to physically cut off power supply when the balance reached zero and reconnect it once units were purchased.</p><p>The <strong>ESP32</strong>, acting as the central processor, was responsible for all computational tasks. It received current data from the Arduino via serial communication and used it — along with a known voltage value — to calculate the instantaneous power consumption. Power was then integrated over time to compute total energy usage using the formula:</p><p><strong><em>Energy (kWh) = (Power (Watts) × Time (Hours)) / 1000</em></strong></p><p>This calculated energy value was used to decrement the user’s available electricity balance. The updated balance was maintained locally and also synchronized with the central server through a <strong>WebSocket connection</strong>, enabling real-time updates between the hardware meter and the web-based platform. This ensured users could see their current balance instantly and be notified when it ran low or reached zero.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DrVrsFJwreBuMDJpWtHYJw.png" /><figcaption>Meter Readings with embedded Anomaly device</figcaption></figure><p>This modular approach allowed for efficient division of tasks — offloading signal measurement to the Arduino while utilizing the processing power and connectivity features of the ESP32 to handle calculations, communication, and balance management.</p><h3>The Observations</h3><p>Project Videos Link: <a href="https://drive.google.com/drive/folders/1ehf-lFiQZmgtR7wBeUib6L6Iw1MtXQWK?usp=sharing">https://drive.google.com/drive/folders/1ehf-lFiQZmgtR7wBeUib6L6Iw1MtXQWK?usp=sharing</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7XzSgVAQlEgtXixxE_p7Eg.png" /><figcaption>Anomaly detection prediction</figcaption></figure><figure><img alt="Overall system" src="https://cdn-images-1.medium.com/max/1024/1*GxElb-_csP4Y2jAYkOkLLQ.png" /><figcaption>Overall System</figcaption></figure><h3><strong>What’s Next?</strong></h3><p>Project Supervsor: Mr Francis Masi</p><p>Project By: Wongani Tembo, Fahad Twaha and Kingsley Tembo</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=abd6b625749d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>