<?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 Dineth Hettiarachchi on Medium]]></title>
        <description><![CDATA[Stories by Dineth Hettiarachchi on Medium]]></description>
        <link>https://medium.com/@deaneeth?source=rss-d6dee9ab2033------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Bhub7ElBMLQxlCxpNoAvfg.png</url>
            <title>Stories by Dineth Hettiarachchi on Medium</title>
            <link>https://medium.com/@deaneeth?source=rss-d6dee9ab2033------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 14:12:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@deaneeth/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[Building a Full-Stack ESP32 IoT Project for Smart Beehive Monitoring]]></title>
            <link>https://deaneeth.medium.com/building-a-full-stack-esp32-iot-project-for-smart-beehive-monitoring-5a6f421b7be7?source=rss-d6dee9ab2033------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a6f421b7be7</guid>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[agricultural-technology]]></category>
            <category><![CDATA[esp32]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[iot]]></category>
            <dc:creator><![CDATA[Dineth Hettiarachchi]]></dc:creator>
            <pubDate>Sun, 05 Jul 2026 12:01:10 GMT</pubDate>
            <atom:updated>2026-07-05T12:01:10.716Z</atom:updated>
            <content:encoded><![CDATA[<p>How I connected embedded C++, solar-powered sensors, Firebase Realtime Database, and a React TypeScript dashboard into one live smart farming system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JOgqLfGQzthTKAgjoFExUg.png" /><figcaption>Hero image showing the beehive hardware prototype beside a clean dashboard screen with live sensor cards, GPS map, and activity charts.</figcaption></figure><p>My dad’s apiary is not exactly a quiet place to test electronics.</p><p>There is heat, dust, insects, sunlight, humidity, and the constant low noise of a living hive doing what a hive does. It is also the kind of place where a “<em>simple IoT project</em>” stops being simple very quickly. A sensor reading that looks perfect on a desk can become useless outside. A wire that behaves nicely during testing can loosen. A dashboard that looks clean with mock data suddenly feels fragile when the data is coming from real hardware.</p><p>That was the reason I wanted to build this project properly.</p><p>The goal was simple in one sentence: build a complete live telemetry system from PCB to browser, where an <strong>ESP32</strong> collects beehive data, sends it to Firebase <strong>Realtime Database</strong>, and a real-time monitoring dashboard turns that sensor data into something a beekeeper can actually understand.</p><p>I split the project into two public repositories, but I do not think of them as two separate projects:</p><ul><li><strong>Hardware / edge layer:</strong> <a href="https://github.com/deaneeth/smart-beehive-monitor">https://github.com/deaneeth/smart-beehive-monitor</a></li><li><strong>Dashboard / cloud layer:</strong> <a href="https://github.com/deaneeth/Smart-Beehive-Dashboard">https://github.com/deaneeth/Smart-Beehive-Dashboard</a></li></ul><p>Together, they form one full-stack IoT system: sensors in the hive, embedded C++ firmware on the ESP32, Firebase as the live data backbone, and a React TypeScript dashboard for visualization.</p><h3>The Problem: What “Smart Beehive” Actually Means</h3><p>When people hear <em>“smart beehive,”</em> it can sound like a fun sensor demo. Put a temperature sensor inside a box, send the number somewhere, make a chart, call it smart farming.</p><blockquote>That is not enough.</blockquote><p>A beehive is a biological system, not a static machine. If the temperature changes, it may say something about colony stress. If humidity rises, it may affect hive conditions. If weight changes over time, it can hint at honey production, feeding patterns, or loss. If bee traffic drops suddenly, that can be a signal worth investigating. If motion is detected near the hive at night, the beekeeper may want to know.</p><p>So for this ESP32 IoT project, I wanted to monitor several signals at once:</p><ul><li>Temperature, humidity, pressure, and air quality using the <strong>BME680</strong></li><li>Bee entrance and exit activity using <strong>TCRT5000 IR</strong> sensor arrays</li><li>Hive weight using an <strong>HX711 load cell</strong> setup with a 100kg load cell</li><li>Predator or movement detection using an <strong>HC-SR501 PIR motion sensor</strong></li><li>GPS location using a <strong>NEO-6M module</strong> for anti-theft and tracking</li><li>Solar and battery power status for outdoor reliability</li></ul><p>This is also where I noticed that most tutorials fell short for what I wanted.</p><p>A tutorial might show how to connect one BME sensor to an ESP32. Another might show Firebase writes. Another might show a chart in React. But the hard part is not one sensor, one API call, or one graph.</p><p>The hard part is making the whole thing behave like a living IoT monitoring system.</p><h3>The Architecture: From Hive to Dashboard</h3><p>Here is the architecture in plain English.</p><pre>Beehive <br>   ↓ <br>Sensors: BME680, TCRT5000, HX711 + load cell, PIR, GPS, battery/solar signals <br>   ↓ <br>ESP32 running embedded C++ firmware with PlatformIO <br>   ↓ <br>WiFi connection <br>   ↓ <br>Firebase Realtime Database <br>   ↓ <br>Next.js + React + TypeScript dashboard <br>   ↓ <br>Gauges, charts, alerts, GPS map, and historical trends</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9INXu5rDc3HoMB-ZPE8m7w.png" /><figcaption>Architecture diagram showing ESP32 sensor layer, WiFi transport, Firebase Realtime Database, and Next.js dashboard.</figcaption></figure><p>The edge layer is responsible for collecting data from the physical world. The <strong>ESP32</strong> reads the sensors, prepares structured telemetry, and syncs it to Firebase.</p><p>The transport layer is <strong>WiFi</strong>. I chose WiFi because this version was designed around accessible hardware and a Firebase-first architecture. A GSM or LoRa version would be useful for remote farms, but for this build, WiFi kept the system easier to develop, debug, and connect to a real-time dashboard.</p><p>The cloud layer is <strong>Firebase Realtime Database</strong>. Instead of building my own backend first, I wanted a live data backbone that could support real-time sync without writing a custom WebSocket server.</p><p>The frontend is the IoT web dashboard. It consumes the Firebase data and turns it into visual feedback: gauge charts, time-series charts, activity summaries, alert states, GPS location, and power status.</p><p>That distinction matters. This is not a simulation where the frontend is the main project and the hardware is imaginary. The dashboard exists because the hardware produces data. The hardware exists because the dashboard needs meaningful real-world inputs.</p><p>That is the part I care about as an AI/ML and software engineer: end-to-end systems thinking.</p><h3>Building the Edge: ESP32 Project, Sensors, and Embedded Systems Decisions</h3><p>For the hardware layer, I used an ESP32-based firmware project written in embedded C++ with PlatformIO.</p><p>The <strong>ESP32</strong> made sense because it gives a good balance of cost, WiFi, available GPIO, community support, and low-power possibilities. A Raspberry Pi would have been easier for some high-level scripting tasks, but it would also be heavier, more power-hungry, and honestly unnecessary for this type of sensor data collection.</p><p>For a solar-powered IoT device, the microcontroller choice matters.</p><p><strong>The project uses:</strong></p><ul><li>ESP32-WROOM-32U development board</li><li>BME680 environmental sensor</li><li>TCRT5000 IR sensor arrays</li><li>HX711 amplifier with 100kg load cell</li><li>HC-SR501 PIR motion detector</li><li>NEO-6M GPS module</li><li>Dual 18650 3.7V batteries</li><li>5W solar panel</li><li>TP4056 charging module</li><li>MT3608 boost converter</li></ul><p>Each sensor has a reason.</p><p>The <strong>BME680</strong> gives environmental monitoring. Temperature and humidity are obvious for beekeeping, but gas resistance also gives an air-quality-related signal that can be useful as part of broader environmental monitoring.</p><p>The <strong>TCRT5000</strong> sensors are for bee movement. Counting bees perfectly is harder than it sounds because bees do not politely walk through sensors one at a time like test objects in a lab. But entrance activity is still useful as an approximate activity signal, especially when tracked over time.</p><p>The <strong>HX711</strong> and load cell setup is for hive weight. Weight trends are important because honey production and hive health are not just instant values. They are patterns.</p><p>The <strong>PIR</strong> sensor adds a simple predator alert or motion detection layer. The GPS module gives location awareness for anti-theft or field tracking.</p><p>This is what I mean by practical sensor fusion. Not a fancy deep learning model. Not pretending this is computer vision. Just multiple imperfect signals combined into a more useful picture of the hive.</p><h3>Why Firebase on constrained hardware?</h3><p>Writing to Firebase directly from the ESP32 was a tradeoff.</p><p><strong>The good part:</strong> fewer backend moving pieces. The ESP32 can push current values and history records into Firebase, and the dashboard can subscribe to updates.</p><p><strong>The harder part: </strong>embedded Firebase libraries change, and constrained hardware is not as forgiving as a laptop. One of the practical issues I had to handle was library migration. The project documentation now makes it clear that it uses mobizt/FirebaseClient, the newer async library, and not the older deprecated Firebase ESP Client library.</p><p>That kind of detail is not glamorous, but it matters. A project can look broken because of one incompatible library version.</p><pre>; platformio.ini idea <br>lib_deps = <br>  mobizt/FirebaseClient <br>  mobizt/FirebaseJson</pre><p>For embedded systems, documentation is not decoration. It is part of the build.</p><h3>Designing the Backbone: Firebase Realtime Database</h3><p>I used Firebase Realtime Database because the dashboard needed live updates.</p><p>A REST polling approach would work, but it would add unnecessary delay and repeated requests. For a real-time dashboard, I wanted the frontend to react when the data changes, not ask every few seconds, “Anything new yet?”</p><p>The database structure is organized around the major system domains:</p><pre>smart-beehive/ <br>├─ environment/ <br>│ ├─ current/ <br>│ └─ history/ <br>├─ beeActivity/ <br>├─ weight/ <br>├─ location/ <br>├─ system/ <br>│ ├─ power/ <br>│ └─ status/ <br>└─ alerts/</pre><p>That structure seems simple, but it forced me to think carefully about data shape.</p><p>The dashboard does not want random sensor dumps. It wants predictable paths:</p><ul><li>environment/current for latest temperature, humidity, pressure, and gas resistance</li><li>beeActivity/current and daily history for movement patterns</li><li>weight/current and weight/history for load cell readings</li><li>location/current for GPS coordinates</li><li>system/power/current for voltage, percentage, and charging state</li><li>alerts/current for motion, low battery, and sensor error states</li></ul><p>The biggest design rule I followed was this: current state and historical state should not fight each other.</p><p>A dashboard card needs the latest value quickly. A chart needs history. Those are related, but not the same access pattern. Keeping both paths makes the frontend easier to reason about.</p><p>For security rules, the project documentation keeps it practical: public dashboards may allow reads, but writes should be restricted. That is a basic but important production-style decision. The device should write telemetry. The dashboard should mostly read. Not every client should be able to overwrite the hive.</p><h3>Building the Dashboard: React, TypeScript, Tailwind, and the IoT Web Dashboard</h3><p>For the frontend, I built a React TypeScript dashboard using Next.js, Firebase Realtime Database, Recharts, React Gauge Charts, Leaflet, and Tailwind CSS.</p><p>I specifically did not use Python or Streamlit for this layer.</p><p>Streamlit is excellent for quick data apps and ML demos, but this project needed to feel like an IoT web dashboard that could sit in a portfolio and be extended like a real web application. I wanted routing, reusable components, typed data interfaces, responsive UI, and frontend architecture.</p><p><strong>The dashboard includes:</strong></p><ul><li>Live metric cards for environmental values</li><li>Gauge charts for quick status reading</li><li>Historical trend charts using Recharts</li><li>Bee activity visualization</li><li>Hive weight tracking</li><li>GPS map view using Leaflet</li><li>Predator alert display</li><li>Solar and battery power monitoring</li><li>Responsive UI styling with Tailwind CSS</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*piO-SonM0S2XhOON" /><figcaption>Dashboard screenshot with live temperature, humidity, weight, battery, and bee activity cards.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Xq6QJqjyeFWTZpnz" /><figcaption>Historical charts showing bee activity and hive weight trends.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PHdfCADmnDQRGMXF" /><figcaption>Leaflet map screenshot showing hive GPS location.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fyPgUJeYbbZ1yfnl" /><figcaption>Status of the full system including the IoT sensors, WiFi, Battery and UpTime as well.</figcaption></figure><p>TypeScript helped a lot here because IoT data can get messy. A value might be missing. A timestamp might not match the format expected by a chart. A Firebase path might return null during first load.</p><p>Typing the expected data shape makes those problems more visible.</p><p>A simplified version of the dashboard setup looks like this:</p><pre>git clone https://github.com/deaneeth/Smart-Beehive-Dashboard <br>cd Smart-Beehive-Dashboard npm install <br>cp .env.example .env.local <br>npm run dev</pre><p>And the hardware side starts like this:</p><pre>git clone https://github.com/deaneeth/smart-beehive-monitor <br>cd smart-beehive-monitor <br>platformio run <br>platformio run --target upload</pre><p>The dashboard repository does not currently publish a production deployment URL, so I am not going to pretend there is one.</p><p>Right now, the important part is that the frontend proves the cloud layer is usable, readable, and connected to the hardware design.</p><h3>The Hard Parts: What I Actually Struggled With</h3><p>This was not a clean “I connected sensors and everything worked” project.</p><p><strong>The first hard part</strong> was dependency drift. In normal web development, a dependency issue is annoying. In embedded development, it can feel like the board is gas-lighting you. The Firebase library migration was one of those moments. The fix was not just changing a line of code. It required documenting which library version the project expects and making the setup reproducible.</p><p><strong>The second hard par</strong>t was outdoor power management. A solar-powered IoT project sounds elegant, but batteries, charging modules, voltage boosting, and real sunlight conditions are not theoretical. The hardware design uses dual 18650 batteries, a 5W solar panel, TP4056 charging, and MT3608 boost conversion, but real field deployment still needs careful testing over time.</p><p><strong>The third hard part</strong> was calibration. A 100kg load cell is only useful if the readings are calibrated. Bee counting with IR sensors is also approximate because real bees move unpredictably. This is where engineering humility helps. The goal is not to claim perfect measurement. The goal is to build a system that can be calibrated, improved, and validated.</p><p><strong>The fourth hard part</strong> was frontend-backend data mismatch. Embedded firmware thinks in sensor readings. Frontend dashboards think in UI state. Firebase sits in the middle. If the data paths are inconsistent, the dashboard becomes fragile. That is why the database structure became a core part of the architecture, not an afterthought.</p><p>In other words, the hardest part was not any single technology. It was making all the parts agree with each other.</p><h3>What I Built: Stats and Outcomes</h3><p>The project is public and split into two repositories.</p><h4>Hardware / Edge Repository</h4><p><strong>Repository</strong>: <a href="https://github.com/deaneeth/smart-beehive-monitor">https://github.com/deaneeth/smart-beehive-monitor</a></p><p>At the time of writing:</p><ul><li><strong>Stars:</strong> 16</li><li><strong>Commits</strong>: 31</li><li><strong>License:</strong> MIT</li><li><strong>Main language:</strong> C++</li><li><strong>Stack:</strong> ESP32, PlatformIO, embedded C++, Firebase Realtime Database</li><li><strong>Documentation:</strong> wiring guide, bill of materials, Firebase setup, dashboard setup, and system setup</li></ul><p>This repository contains the firmware and hardware-side documentation for the ESP32 IoT project.</p><h4>Dashboard / Cloud Repository</h4><p><strong>Repository:</strong> <a href="https://github.com/deaneeth/Smart-Beehive-Dashboard">https://github.com/deaneeth/Smart-Beehive-Dashboard</a></p><p>At the time of writing:</p><ul><li><strong>Stars:</strong> 4</li><li><strong>Commits:</strong> 13</li><li><strong>License:</strong> MIT</li><li><strong>Languages:</strong> TypeScript, CSS, JavaScript</li><li><strong>Stack:</strong> React, Next.js, TypeScript, Firebase Realtime Database, Recharts, React Gauge Charts, Leaflet, Tailwind CSS</li></ul><p>This companion dashboard proves the project is not only an IoT hardware project. It is a full-stack IoT system with a real web interface.</p><h3>What works today</h3><p>The architecture, firmware structure, Firebase schema, setup documentation, and dashboard implementation are in place. The project demonstrates embedded systems work, real-time data sync, cloud-backed telemetry, and frontend visualization.</p><h3>What still needs field testing</h3><p>I still want to test the system longer in outdoor hive conditions. The main areas that need real field validation are sensor calibration, long-term solar charging behavior, enclosure durability, IR bee counting accuracy, and reliability over multiple days of continuous operation.</p><p>That is the honest state of the project. It is functional as an engineering build and strong as a production-style prototype, but field reliability is something that has to be earned outside, not claimed in a README.</p><h3>Key Takeaways</h3><ol><li><strong>Design the data model before the dashboard becomes complicated.</strong><br>In an IoT monitoring system, the database structure is part of the product. Separate current state from historical data early, because dashboards, alerts, and charts do not all read data the same way.</li><li><strong>Choose hardware based on deployment constraints, not hype.</strong><br>I used ESP32 instead of Raspberry Pi because this system needed low-power sensor collection, WiFi, and outdoor solar-powered IoT behavior. The best board is not the most powerful one. It is the one that fits the environment.</li><li><strong>Build the complete loop, even if each part starts simple.</strong><br>A sensor reading alone is not a system. A dashboard with mock data is not a system either. The value comes from closing the loop: physical sensor data, embedded firmware, cloud sync, real-time visualization, and feedback that a user can act on.</li></ol><h3>What’s Next</h3><p>I do not want to turn this into a fake startup road-map. The realistic next steps are more practical.</p><p><strong>First,</strong> I want to improve field testing. That means running the hardware outside for longer periods and logging how the battery, solar charging, WiFi connection, and sensors behave in real conditions.</p><p><strong>Second,</strong> I want to improve calibration workflows. The HX711 load cell calibration should be easier to repeat. The TCRT5000 bee counter logic can also be improved with better filtering and threshold tuning.</p><p><strong>Third,</strong> I want to make the dashboard more useful for trend analysis. As an AI/ML engineer, this is where the project becomes interesting as a machine learning adjacent IoT project. Before adding models, I need clean historical data. Later, that data could support anomaly detection, predictive maintenance IoT patterns, or simple alerts for unusual activity.</p><p><strong>Fourth,</strong> I want to improve deployment documentation so another IoT builder or beekeeper can reproduce the system without guessing.</p><blockquote><strong>No fake AI claims. No imaginary computer vision. Just better data, better reliability, and better engineering.</strong></blockquote><h3>Closing</h3><p>This project reminded me why I like building complete systems.</p><p>Tutorial clones are useful for learning, but they usually end right before the engineering gets interesting. Real projects have mismatched libraries, unstable readings, imperfect sensors, awkward data shapes, power constraints, and UI decisions that reveal whether the backend was designed properly.</p><p>That is the work I enjoy.</p><blockquote><strong>I am Dineth Hettiarachchi,</strong> an AI/ML and software engineer building end-to-end intelligent systems. This smart farming project was my way of connecting embedded systems, sensor data, Firebase, and a React TypeScript dashboard into one practical agricultural technology build.</blockquote><p>Feedback is welcome from embedded engineers, React developers, beekeepers, smart farming builders, and anyone who has fought with sensors long enough to know that “it worked on my desk” is not the same as “it works outside.”</p><p><strong>The repositories are open for contributions:</strong></p><ul><li><a href="https://github.com/deaneeth/smart-beehive-monitor">https://github.com/deaneeth/smart-beehive-monitor</a></li><li><a href="https://github.com/deaneeth/Smart-Beehive-Dashboard">https://github.com/deaneeth/Smart-Beehive-Dashboard</a></li></ul><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a6f421b7be7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Built a TPU You Can Watch Run-Every Signal Is Real]]></title>
            <link>https://deaneeth.medium.com/i-built-a-tpu-you-can-watch-run-every-signal-is-real-3bf2e83b2805?source=rss-d6dee9ab2033------2</link>
            <guid isPermaLink="false">https://medium.com/p/3bf2e83b2805</guid>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[webassembly]]></category>
            <category><![CDATA[computer-architecture]]></category>
            <category><![CDATA[system-verilog]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Dineth Hettiarachchi]]></dc:creator>
            <pubDate>Mon, 08 Jun 2026 11:06:15 GMT</pubDate>
            <atom:updated>2026-07-06T15:32:47.682Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>How compiling actual SystemVerilog to WebAssembly taught me more about hardware than any ML paper ever did</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AqpdHo_tDL6AWMJJz2QQ9A.png" /></figure><p>I had been using TPUs for almost a year before I realized I had absolutely no idea what was happening inside one.</p><p>I knew the math. I could write the `nn.Linear` call. I understood that matrix multiplication maps cleanly to hardware. But <strong>why</strong> it maps cleanly, what’s actually happening in the silicon when those multiplications fire was a complete mystery to me.</p><p>The standard explanation is a diagram with arrows. Weights go in here, activations go in there, results come out the bottom. Clean. Tidy. Completely useless for actually understanding anything.</p><p>So I decided to build one. A real one. And make it run in the browser so I could watch it cycle by cycle.</p><p>That became <a href="https://github.com/deaneeth/tiny-tpu"><strong>TinyTPU</strong></a><strong>.</strong></p><h3>What I Actually Wanted to Understand</h3><p>TPUs use something called a <strong>systolic array</strong> to execute matrix multiply. It’s the architecture behind why TPUs are efficient at exactly the workloads that matter for deep learning.</p><p>The word “systolic” means heartbeat. Data pulses through a grid of processing elements in lockstep with the clock, like a heartbeat. Each cell does one tiny job (multiply one number by another, add to a running total) and passes data to its neighbors. No cell talks to memory mid-computation. That’s the whole trick.</p><blockquote><strong>The name sounds complicated. The actual behavior, when you can watch it execute one clock at a time, is surprisingly elegant.</strong></blockquote><p>Weight-stationary dataflow, the variant TPUs use, works like this: you load matrix B into the grid as stationary weights. Each processing element holds one value permanently during the computation. Then matrix A streams in from the left edge, row by row, with a specific diagonal delay called the skew. Results accumulate downward through the grid and exit from the bottom.</p><p>Every explanatory article I found drew this as a static diagram. I needed to see it move.</p><figure><img alt="From RTL to Live Hardware in the Browser" src="https://cdn-images-1.medium.com/max/1024/1*5gEG4VKgJP0TdXqG16saDA.png" /><figcaption>From RTL to Live Hardware in the Browser</figcaption></figure><h3>The Constraint That Made It Honest</h3><p>When I built TinyGPU, the core decision was: model the concepts, not the hardware. The simulator was written in Python, the parallelism was simulated, the visualization was generated after the fact. That was fine for the learning goal.</p><p>TinyTPU had a different constraint from the start: <strong>nothing on screen is allowed to be faked.</strong></p><p>Not “mostly real.” Not “a JavaScript approximation of what the hardware would do.” The browser had to run the actual hardware model. Every number in the visualization had to be a live signal read directly from compiled RTL.</p><blockquote><strong>That one constraint turned a weekend project into two months of work. It also made the result actually interesting.</strong></blockquote><p><strong>The architecture I landed on:</strong> write real synthesizable SystemVerilog, verify it with a numpy golden model, compile it to a cycle-accurate C++ simulation via Verilator, compile that to WebAssembly via Emscripten, and have the React frontend read hardware state every clock cycle through an `embind` API.</p><p><strong>The pipeline is</strong> <em>`.sv` → Verilator → C++ → Emscripten → `.wasm` → React island → SVG.</em></p><h3>The Part Nobody Warned Me About: The Skew</h3><p>Here’s the thing about weight-stationary dataflow that took me an embarrassingly long time to understand from diagrams alone.</p><p>Matrix A doesn’t just stream in from the left. It streams in <strong>diagonally</strong>. Row 0 enters at cycle 0. Row 1 enters at cycle 1. Row 2 at cycle 2. And so on. This deliberate stagger called the <strong>row skew </strong>ensures that the right activation meets the right weight at the right processing element at the right clock cycle.</p><p>Without the skew, every activation would arrive at column 0 at the same time and the wrong values would multiply together. The diagonal stagger is what makes the spatial layout of the grid correspond to the temporal sequencing of the computation.</p><blockquote><strong>In a waveform viewer, the skew looks like a moving diagonal of signal activity sweeping across the array. That’s the visual signature of a working systolic array.</strong></blockquote><p>When I finally got the RTL correct and looked at the simulation waveform in gtkwave, seeing that diagonal pattern appear for the first time was genuinely satisfying. It meant the hardware was thinking the way it was supposed to think.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplayer.vimeo.com%2Fvideo%2F1206157317%3Fapp_id%3D122963&amp;dntp=1&amp;display_name=Vimeo&amp;url=https%3A%2F%2Fvimeo.com%2F1206157317%3Fshare%3Dcopy%26fl%3Dsv%26fe%3Dci&amp;image=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F2174928599-603e78c6bed2951cb342c6ffa11b5b1c64ef9914b972f3843be95492bb23668b-d_1280%3Fregion%3Dus&amp;type=text%2Fhtml&amp;schema=vimeo" width="1280" height="720" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f6a5eedb158692057c605b500da32f1/href">https://medium.com/media/0f6a5eedb158692057c605b500da32f1/href</a></iframe><h3>Three Decisions That Actually Mattered</h3><h4>Decision 1: Golden model before hardware</h4><p>Before I wrote a single line of SystemVerilog, I wrote `sim/golden.py` a dead-simple numpy implementation of matrix multiply that serves as the ground truth.</p><p>Every change to the RTL gets validated against this oracle before it’s considered correct. If the hardware output bit-matches numpy for 20 random matrix pairs, the RTL is correct. If it doesn’t, it doesn’t matter how good the visualization looks, it’s a beautiful lie.</p><pre>def matmul_golden(A, B):<br> return np.array(A, dtype=np.int64) @ np.array(B, dtype=np.int64)</pre><p>That’s it. The simplest possible oracle. The hardware is “correct” when it matches this.</p><p>This ordering matters more than it sounds. I’ve seen hardware education projects where the author writes the visualizer first, then writes hardware that produces values that “look right.” That’s not how you learn hardware. That’s how you fool yourself.</p><h4>Decision 2: The debug output bus</h4><p><strong>Verilator </strong>can expose internal signals two ways: via a debug output bus that you explicitly wire at the top level, or via a `public_flat` flag that exposes everything.</p><p>I chose the explicit bus. Every PE’s weight, activation, and partial sum is wired to a top-level output bundle that the C++ harness reads. No reaching into internal hierarchies. No relying on compiler flags that might behave differently across Verilator versions.</p><pre>```systemverilog<br>// top-level debug outputs - explicit, stable, honest<br>output logic signed [ACC_W-1:0] dbg_psum [N][N],<br>output logic signed [DATA_W-1:0] dbg_weight [N][N],<br>output logic signed [DATA_W-1:0] dbg_act_out [N][N]<br>```</pre><p>It’s more wiring. But when the visualization shows a value, you can trace exactly which RTL register it came from.</p><h4>Decision 3: Never touching the WASM during SSR</h4><p>The frontend is built in Astro, which server-side renders pages at build time. WASM can’t load during SSR there’s no `window`, no browser APIs, nothing.</p><p>The fix is using `client:only=”react”` on every island that touches the simulator, and dynamically importing the WASM module inside `useEffect`. Not at the module level. Not at component top. Inside `useEffect`, after hydration, guarded by a `typeof window !== ‘undefined’` check.</p><p>I got this wrong twice before getting it right. Both times the production build was a blank white page with a cryptic error about `window is not defined`. Both times the fix was the same: move the import deeper, later, more client-side.</p><h3>What Went Wrong (Several Things)</h3><p>The skew timing took the most debugging. I had the controller FSM correct and the PE wiring correct but the results were shifted one column to the right. The activation for row 0 was meeting the weight for row 1. Off by one in the per-row delay logic, which meant the diagonal stagger was starting one cycle too late.</p><p>The waveform caught it immediately once I knew what to look for: the moving diagonal was displaced by one column from where it should have been. The fix was two characters in the controller. The debugging was four hours.</p><p>The WASM bridge had its own set of problems. `verilated.cpp` not found because `VERILATOR_ROOT` was unset. The ` -Mdir` path not matching the `-I` include path. CORS blocking `.wasm` files served over `file://` (always use `python3 -m http.server` for local testing, never open directly). Each of these produced a completely different error message that didn’t point at the actual cause.</p><p>The one I didn’t expect: the whole Astro SSR/WASM problem was invisible in development and only appeared in production builds. `pnpm dev` uses a dev server that doesn’t pre-render. `pnpm build` does. You can develop locally for hours without hitting this issue and then have a broken production deploy. The fix is to run `pnpm build &amp;&amp; pnpm preview` before calling anything done.</p><h3>What It Looks Like When It Works</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2s1RpRUfm51lpTsfvml7bQ.gif" /></figure><p>The visualizer has three modes.</p><p><strong>L1 -One Cell:</strong> Isolate a single processing element. Watch the MAC equation update live: `psum_out = psum_in + weight × act_in`. See the weight load, see the activation arrive, see the partial sum update. One multiply-accumulate, made visible.</p><p><strong>L2-The Array:</strong> The full 4×4 grid. This is the one worth watching. You see the weight loading phase (all PEs loading their stationary weights simultaneously), then the streaming phase where activations enter from the left in diagonal waves, then the drain phase as results exit from the bottom. The FSM state badge in the corner <em>`IDLE → LOAD_WEIGHTS → STREAM → DRAIN → DONE`</em> tracks where the hardware is in its execution.</p><p><strong>L3 -Tiling: </strong>Enter matrices larger than 4×4 and the orchestration layer splits them into 4×4 tiles, calls the real hardware repeatedly for each tile, and accumulates the results. An 8×8 matmul becomes eight passes through real RTL. The tiling itself is TypeScript that’s honest too, and documented clearly.</p><blockquote><strong>The moment that made the whole thing worth it: watching the diagonal pattern sweep across the PE grid in L2 for the first time with real data. That’s the skew. That’s the thing the static diagrams were trying to describe.</strong></blockquote><h3>What This Actually Taught Me</h3><p>I can explain weight-stationary dataflow now. Not just recite the definition actually explain why you’d choose it, what tradeoff it makes (memory bandwidth for weight re-use), why it maps cleanly to matrix multiply in neural networks, and what happens at the boundaries.</p><p>I understand why tiling exists. The 4×4 array can hold 16 weights. A real `nn.Linear(1024, 1024)` has over a million weights. The hardware has to process the problem in tiles, accumulating partial results across passes. Every time a deep learning framework maps a layer to hardware, this is happening. Every time.</p><p>I also now have a reflex I didn’t have before: when something “works” in hardware simulation but produces wrong outputs, the first thing I check is timing. Not logic. Timing. The systolic array bug the off-by-one in the diagonal skew was the RTL doing exactly what I told it to do. I just told it the wrong thing by one cycle.</p><p>Building the wrong thing correctly teaches you more about the right thing than reading about the right thing ever does.</p><h3>The Honest Assessment</h3><p>4 stars on GitHub at launch. That’s the number. It’s not what I hoped for.</p><p>Distribution is a separate skill from building, and I’m still learning it. The project is real verified hardware, honest signals, nothing faked. Getting people to care about that takes more than just building it correctly.</p><p>But the learning happened regardless of the star count. That’s the thing about building educational tools: the person who learns the most is always the builder.</p><p>The repo is on <a href="https://github.com/deaneeth/tiny-tpu"><strong>GitHub</strong></a>.</p><p>The live demo is at <a href="https://tiny-tpu.vercel.app/"><strong>tiny-tpu.vercel.app</strong></a>.</p><p>If you want to understand what’s inside the chips running your models, this is one way to start.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3bf2e83b2805" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Built a Tiny GPU Simulator to See What Happens When Threads Execute in Parallel]]></title>
            <link>https://deaneeth.medium.com/i-built-a-tiny-gpu-simulator-to-see-what-happens-when-threads-execute-in-parallel-c2f204ab3bc3?source=rss-d6dee9ab2033------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2f204ab3bc3</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[cuda]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[gpu]]></category>
            <dc:creator><![CDATA[Dineth Hettiarachchi]]></dc:creator>
            <pubDate>Sat, 24 Jan 2026 22:49:59 GMT</pubDate>
            <atom:updated>2026-01-24T22:49:59.724Z</atom:updated>
            <content:encoded><![CDATA[<p>How building a visual simulator taught me more about parallel computing than months of reading CUDA documentation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K6Mnf761WKvP78M9AJnAQw.png" /></figure><p>I was three hours into debugging a <strong>CUDA kernel</strong> when I realized I had no idea what was actually happening.</p><p><strong>The code compiled. It ran.</strong> It even produced output-just not the <em>right</em> output. Somewhere inside that GPU, thousands of threads were executing my instructions in parallel, but I was blind to it all. No print statements. No step-through debugger. Just a black box that either worked or didn’t.</p><p>That’s when I started sketching what eventually became <a href="https://github.com/deaneeth/tinygpu"><strong>TinyGPU</strong></a><strong>.</strong></p><h3>The Problem with Learning GPU Programming</h3><p>GPUs are incredible machines. They can execute thousands of operations simultaneously, making them essential for everything from graphics rendering to machine learning. <strong>But there’s a catch:</strong> they’re nearly impossible to understand by just reading documentation.</p><p>The mental model is weird. Unlike CPUs where you think about one instruction executing at a time, GPUs run the <em>same</em> instruction across hundreds of threads simultaneously. They have this thing called “SIMT” <strong>(Single Instruction, Multiple Threads)</strong> that sounds simple until you try to reason about what happens when threads diverge, or when they need to synchronize, or when they access shared memory.</p><blockquote><strong><em>Most learning resources give you one of two extremes:</em></strong><em> oversimplified analogies that don’t transfer to real code, or industrial-grade tools like </em><strong><em>Nsight</em></strong><em> that assume you already understand everything.</em></blockquote><p>I needed something in between. <strong>Something I could <em>see</em>.</strong></p><figure><img alt="TinyGPU: Your Visual Guide to Parallel Computing" src="https://cdn-images-1.medium.com/max/1024/1*IvUbQ_Au-cYmuJas_YMc5g.png" /><figcaption>TinyGPU: Your Visual Guide to Parallel Computing</figcaption></figure><h3>The Insight That Changed Everything</h3><p>The breakthrough came when I stopped thinking about building a <strong>“realistic”</strong> GPU simulator.</p><p>Real GPUs are fantastically complex-warp schedulers, register allocation, cache hierarchies, memory coalescing. Modeling all of that would take years and miss the point entirely.</p><blockquote><strong><em>What if I just modeled the </em>concepts<em>?</em></strong><em> The bare minimum needed to understand how parallel execution actually works?</em></blockquote><p>That constraint <em>”simplicity over realism” </em>shaped every design decision that followed. If a feature didn’t directly illuminate how threads coordinate and execute, it got cut.</p><h3>How TinyGPU Actually Works</h3><p>At its core, <strong>TinyGPU</strong> is a <strong>SIMT execution model</strong> with just enough machinery to be interesting.</p><p>Each thread gets its own program counter and register file. They all execute the same program, but independently-meaning they can be at different instructions at different times. This is critical for understanding thread divergence.</p><p>There’s a shared global memory space where threads can read and write values. There’s also shared memory within thread blocks for faster coordination.</p><p><strong>The instruction set is deliberately minimal: </strong>basic arithmetic (ADD, MUL), memory operations (LD, ST), control flow (JMP, BEQ, BNE), and synchronization (SYNC).</p><blockquote><strong><em>That’s it. No floating point, no fancy intrinsic’s, no texture sampling.</em></strong></blockquote><p><strong>But here’s the key part: </strong>every single cycle of execution is tracked and can be visualized.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ve3epxrWTq4RVy3FbtMmzg.png" /></figure><h3>The Build: Three Decisions That Mattered</h3><h4>Decision 1: Per-Thread Program Counters</h4><p>Early versions tried to keep threads perfectly synchronized. If one thread hit a conditional branch, all threads had to wait. This made the implementation simpler but completely missed the point.</p><p>Real GPUs <strong><em>do</em> handle divergence-threads</strong> within a warp can temporarily execute different paths. So I gave each thread its own PC and let them diverge naturally.</p><blockquote><strong><em>The tradeoff? </em></strong><em>More complexity in the execution loop. But the educational value was undeniable. You could finally </em>see<em> what happens when threads take different branches.</em></blockquote><h4>Decision 2: Making SYNC Actually Synchronize</h4><p><strong>The synchronization barrier instruction </strong>(SYNC)<strong> sounds simple:</strong> all threads must reach this point before any can continue.</p><p>But implementing it correctly was tricky. Threads don’t execute in lockstep. Some might reach the barrier quickly while others are still processing earlier instructions. If you’re not careful, you get deadlocks or threads that zip past the barrier when they shouldn’t.</p><p><strong>The solution was a barrier counter.</strong> When a thread hits SYNC, it increments the counter and enters a waiting state. Only when <em>all</em> threads have incremented does the counter reset and execution resumes. <strong>Simple in concept,</strong> but it took several iterations to get the state management right.</p><h4>Decision 3: Visualization as First-Class Feature</h4><p>Most simulators treat visualization as an afterthought-maybe you can dump register values to a text file <em>if you’re lucky.</em></p><p><strong>I made visualization core to the design. </strong>Every instruction execution is logged with full state snapshots: register values, memory contents, program counters, active threads. This data feeds into a heatmap renderer that shows you exactly what changed each cycle.</p><blockquote><strong><em>The killer feature?</em></strong><em> Export to animated GIF. You can watch an entire parallel sorting algorithm execute step-by-step, seeing threads coordinate through barriers and swap memory values. It turns an abstract algorithm into something you can </em>understand<em> by watching.</em></blockquote><p>A snippet of assembly code for odd-even sort :</p><pre>SET R0, 0        ; phase_counter<br>SET R1, 8        ; num_phases == N <br>SET R3, 0        ; parity <br><br>loop_phase:<br>    ; compute base index = tid * 2<br>    MUL R4, R7, 2      ; R4 = tid * 2<br>    ADD R5, R4, R3     ; R5 = index = tid*2 + parity<br>    ADD R6, R5, 1      ; R6 = index + 1<br>    CSWAP R5, R6       ; compare &amp; swap memory[index], memory[index+1]<br>    SYNC               ; synchronize threads across the phase<br><br>    ADD R3, R3, 1      ; parity = parity + 1<br>    BNE R3, 2, noreset<br>    SET R3, 0<br>noreset:<br>    ADD R0, R0, 1<br>    BNE R0, R1, loop_phase<br><br>done:<br>    JMP done</pre><p>A frame from the execution GIF showing the heatmap visualization of threads, registers, and memory during one cycle of the sort :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*Nqvc7B2iwFLd6NV9IHcmoQ.gif" /><figcaption>Odd Even Sort</figcaption></figure><h3>What Went Wrong (And What I Learned)</h3><p>The first version had threads executing in perfect parallel-all on the same instruction at the same time. It looked clean but was fundamentally wrong.</p><p>Turns out modeling <em>realistic</em> execution is harder than modeling <em>synchronized</em> execution. <strong>The bug that took the longest to find? </strong>A race condition in how threads were checking the synchronization barrier. Some threads would see the barrier as cleared before all threads had actually incremented the counter. The solution required adding explicit barrier state and more careful ordering of checks.</p><p>I also vastly underestimated how hard it would be to pick good example programs. Writing a parallel odd-even sort that’s simple enough to follow but interesting enough to demonstrate real synchronization challenges took a dozen iterations.</p><blockquote><em>Too simple and it doesn’t show the power of parallelism. Too complex and beginners get lost in the algorithm rather than the execution model.</em></blockquote><p><strong>The visualization almost killed the project. </strong>My initial approach stored full state history in memory, which scaled terribly. <strong>Running an 8-thread program for 200 cycles would consume gigabytes of RAM.</strong> I had to switch to a streaming approach where states are rendered to frames immediately and discarded. Not as flexible, but actually usable.</p><h3>Seeing It In Action</h3><p>The <strong>short video</strong> below gives a visual overview of how <strong>TinyGPU</strong> came to be and what problem it is designed to solve.</p><p>Rather than a line-by-line technical walkthrough, the video focuses on the <strong>motivation behind the project,</strong> the <strong>core idea</strong> of making parallel execution visible, and a high-level demonstration of what the simulator produces.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplayer.vimeo.com%2Fvideo%2F1157992805%3Fapp_id%3D122963&amp;dntp=1&amp;display_name=Vimeo&amp;url=http%3A%2F%2Fvimeo.com%2F1157992805&amp;image=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F2111878974-9c3ad46c564c53bc51ac6fbd1e0bc827eae89abea90a4920f0362b884f435c63-d_1280%3Fregion%3Dus&amp;type=text%2Fhtml&amp;schema=vimeo" width="1920" height="1080" frameborder="0" scrolling="no"><a href="https://medium.com/media/b82fa0479f72d9fb6a462b1ed0418041/href">https://medium.com/media/b82fa0479f72d9fb6a462b1ed0418041/href</a></iframe><p>The most illuminating moment is watching the odd-even sort execute. You can <strong>literally see threads synchronizing at barriers,</strong> comparing values in memory, and swapping them when needed. Each phase of the sort is a wave of activity across threads, all coordinating through SYNC instructions.</p><p><a href="https://vimeo.com/1157997386?share=copy&amp;fl=sv&amp;fe=ci#t=0">Verify to continue</a></p><blockquote><strong>Another powerful example</strong> is the parallel reduction-summing an array by having threads repeatedly combine values. You watch the active thread count halve each iteration as threads finish their work and idle, while the remaining threads carry more of the computational load.</blockquote><h3>What Actually Works (And What Doesn’t)</h3><p><strong>TinyGPU successfully demonstrates core GPU concepts:</strong> SIMT execution, thread divergence, shared memory, and barrier synchronization. The visualization makes these abstract ideas concrete. <strong>Students can write a simple kernel and immediately see how threads coordinate.</strong></p><p><strong>The instruction set is expressive enough to implement real algorithms:</strong> sorting, reductions, convolutions, even simple ray tracing if you’re patient.</p><blockquote><strong><em>But it’s definitely a learning tool, not a performance simulator.</em></strong><em> There’s no warp scheduling, no memory coalescing model, no cache hierarchy. Execution is deliberately serial (one instruction at a time) to make visualization meaningful. A real GPU would execute all these threads in massive parallel batches.</em></blockquote><p>Thread count is also <strong>limited-realistically</strong> you can run maybe <strong>32–64 threads</strong> before the visualization becomes unwieldy and memory usage spikes. Real GPUs casually handle thousands.</p><p><strong>The memory model is simplified.</strong> Real GPUs have local memory, constant memory, texture memory-all with different performance characteristics. TinyGPU just has global and shared. Good enough to learn the concepts, insufficient to understand real-world optimization.</p><h3>Three Lessons That Transferred Beyond This Project</h3><h4>Lesson 1: Simplification reveals truth</h4><p>Stripping away complexity didn’t make TinyGPU less useful-it made the core concepts more visible. When teaching or designing, the question isn’t <em>“how much can I include?”</em> <strong>but</strong> <em>“what can I remove without losing the essential insight?”</em></p><h4>Lesson 2: Visualization changes understanding</h4><p>Reading about thread synchronization is abstract. <em>Watching it happen is visceral. </em><strong>The same principle applies everywhere</strong>: if you can make invisible processes visible, understanding becomes automatic rather than intellectual.</p><h4>Lesson 3: Educational tools need constraints</h4><p>The best learning experiences are deliberately constrained. TinyGPU’s minimal instruction set forces you to think about <em>how</em> things work rather than which library function to call. Constraints aren’t limitations-they’re scaffolding.</p><h3>What I’d Build Next</h3><p><strong>The next major feature</strong> is dynamic warp scheduling. Right now threads execute somewhat independently. Real GPUs group threads into <strong>“warps”</strong> that execute together. Modeling this would demonstrate why divergent branches are expensive-the hardware has to execute both paths sequentially when threads disagree.</p><p>I also want to add <strong>memory access pattern visualization.</strong> <strong>Color-code memory operations</strong> by thread to show coalescing (or lack thereof). This would make the performance implications of access patterns immediately obvious.</p><blockquote><strong><em>A more ambitious extension:</em></strong><em> multi-block execution with an actual grid structure. Right now TinyGPU is basically a single block. Scaling to multiple blocks executing independently would demonstrate another level of parallelism.</em></blockquote><p><strong>There’s also a pedagogical challenge: </strong>the current examples are good, but they’re all batch algorithms. Adding interactive examples-maybe a simple particle system or cellular automaton-would show real-time parallel computation rather than just <strong>“run once and visualize.”</strong></p><h3>Why This Actually Mattered</h3><p>Building <strong>TinyGPU </strong>taught me more about GPU programming than months of reading CUDA documentation.</p><p>Not because the simulator is realistic-it’s deliberately not-but because it made the mental model explicit. Every abstraction in <strong>parallel computing (SIMT, barriers, shared memory)</strong> became concrete machinery I could inspect and modify.</p><p><em>The larger lesson is about understanding complex systems. Sometimes you don’t need to study the real thing-you need to build a simplified version that captures the essence. The act of deciding what to include and exclude forces you to understand what actually matters.</em></p><p><strong>GPUs are still black boxes in production. </strong>But now when I write <strong>CUDA kernels</strong>, I can visualize what’s happening inside. I can reason about synchronization and divergence because I’ve seen it play out cycle by cycle.</p><p><strong>That mental model-that’s what </strong><a href="https://github.com/deaneeth/tinygpu"><strong>TinyGPU</strong></a><strong> really builds.</strong></p><p>The code is on <a href="https://github.com/deaneeth/tinygpu"><strong>GitHub</strong></a> if you want to run it yourself.</p><p><strong><em>Fair warning: </em></strong><em>you might end up spending an afternoon watching threads sort arrays in slow motion. It’s oddly mesmerizing.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2f204ab3bc3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Bees to Bytes: My Journey Building a Simple AI to Protect a Beehive]]></title>
            <link>https://deaneeth.medium.com/from-bees-to-bytes-my-journey-building-a-simple-ai-to-protect-a-beehive-cf8f072ab0ca?source=rss-d6dee9ab2033------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf8f072ab0ca</guid>
            <category><![CDATA[project-based-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[beginner]]></category>
            <dc:creator><![CDATA[Dineth Hettiarachchi]]></dc:creator>
            <pubDate>Mon, 15 Sep 2025 21:37:50 GMT</pubDate>
            <atom:updated>2025-09-15T21:37:50.339Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Digital illustration of a futuristic AI-powered beehive." src="https://cdn-images-1.medium.com/max/1024/1*nG6Dfc6PY8x037EgWzDM9Q.png" /></figure><p>I was sitting there, feeling the warm sun on my skin and listening to the buzzing bees in my dad’s apiary. But my mind was a million miles away, stuck on a huge, overwhelming problem: building my first real-world AI project. I had this big idea for a smart beehive monitor, but going from what I’d learned in tutorials to actually building something that worked felt impossible.</p><p>How do you even get started? What tools do you pick? How do you turn a vague idea into something that helps someone? This isn’t a story about a perfect project. It’s about taking one giant problem, chopping it down to a tiny, manageable piece, and learning what real AI work is all about.</p><h4>The Problem: When Big Ideas Hit Reality</h4><p>My first plan was super ambitious. I wanted to build a system that did everything: track hive temperature, check humidity, count bee traffic, and even identify the queen bee. It sounded awesome, but I quickly got stuck in a cycle I call “perfection paralysis.” I had to face a tough truth: <strong>I couldn’t build the entire ocean all at once. I needed to pick just one drop.</strong></p><p>So, I chose one really specific, painful problem for beekeepers: the <em>Varroa mite</em>. These tiny pests are a huge threat, and catching them early is a big deal. A single infestation can wipe out an entire colony in a season. My goal became simple: train a small AI model to look at pictures from inside a beehive and tell me if it sees a Varroa mite. That’s it! One problem, one solution.</p><h4>The Approach: From an Idea to Action</h4><p>With that clear goal, I got strategic. This wasn’t about creating some theoretical masterpiece; it was about getting a working model as fast as possible. I broke the project down into three key steps:</p><ol><li><strong>Get the Data:</strong> I’d put a simple camera inside the beehive to snap a bunch of pictures. I didn’t need perfect data; I just needed enough to prove the idea.</li><li><strong>Train the Model:</strong> Instead of building a complex neural network from scratch, I decided to use an existing cloud service. All that studying for my Microsoft AI-102 exam came in handy here! I used a pre-trained computer vision model on Azure AI. This let me focus on solving the <strong>problem</strong>, not getting lost in the math.</li><li><strong>Build the App:</strong> The final step was to make a simple script that would grab a new picture, send it to the model on Azure, and give me a clear “Mite Detected” or “All Clear” message back.</li></ol><p><strong>Here’s a tip:</strong> In the real world, you don’t have to reinvent the wheel. The goal is to find the simplest way to get from a problem to a solution. That often means using powerful, pre-built tools like Azure, AWS, or GCP!</p><h4>From Studying to Doing: My Simple Model</h4><p>The core of this project was the computer vision model. This is where the magic happens, but it doesn’t have to be complicated. Here’s how I did it:</p><ul><li><strong>Teaching the Model:</strong> I took a small sample of my pictures and manually drew little boxes around all the Varroa mites. This is called “labeling,” and it’s how you teach the model what a “mite” looks like. It’s kind of boring, but it’s where you create real value.</li><li><strong>Training:</strong> I uploaded those labeled pictures to Azure’s Custom Vision service. With just a few clicks, the service automatically trained a model to recognize the mites. The platform handled all the hard stuff — the complicated network architecture, the fast training, and all the optimization.</li></ul><p>The final result was a small, specialized model. It wasn’t the next ChatGPT, but it was <strong>my</strong> model. It was trained on <strong>my</strong> data to solve <strong>my</strong> problem, and that felt way more powerful than any generic tutorial.</p><p>Here’s a look at the process, conceptually:</p><pre># What the script does:<br>1. Grab a picture from the beehive camera.<br>2. Send the picture to the AI model on Azure.<br>3. The model sends back a prediction (e.g., &#39;mite detected&#39;).<br>4. If a mite is found, send a text alert to the beekeeper!</pre><p>This simple flow shows what applied AI is really about: getting from a data source to a decision. The cloud service handles the hard work, which lets you focus on building a truly useful solution.</p><h4>The Takeaways: What I Learned from Not Being Perfect</h4><p>Getting stuck in “perfection paralysis” was my biggest roadblock. Here are my main takeaways from the whole thing:</p><ul><li><strong>Start small, and stay focused.</strong> Don’t try to build the entire ocean. Find one painful problem and solve it with the simplest tool you can.</li><li><strong>Use the tools that are already out there.</strong> You don’t need a Ph.D. in machine learning to build something cool. Platforms like Azure AI, AWS SageMaker, and Google Cloud AI Platform exist for a reason — use them!</li><li><strong>Balance what you study with what you do.</strong> My AI-102 studies gave me the foundation, but actually applying it to a real-world problem made everything click in a way no textbook ever could.</li><li><strong>Enjoy the journey!</strong> The most valuable part of any project isn’t the final product; it’s the process of solving problems, debugging, and learning new things.</li></ul><h4>What’s Next?</h4><p>This little “mite detector” is just the beginning. It’s a proof of concept that I can expand with more features, better models, and real-time alerts. It’s also a great reminder that even the most complex fields can be tackled one small step at a time.</p><p>What’s a big, overwhelming problem you’ve wanted to solve? How could you break it down into a single, manageable piece using a simple AI solution?</p><p>Let me know in the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf8f072ab0ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>