Building a Smart Pellet Stove Monitor with HC-SR04, ESP8266 and Tasmota

Building a Tasmota-powered pellet stove level sensor using an HC-SR04 ultrasonic sensor, NodeMCU ESP8266, and 3D printed magnetic enclosures.
May 31, 2026 — 6 mins read — Electronics

Building a Smart Pellet Stove Monitor with HC-SR04, ESP8266 and Tasmota

I've been trying to build a commercial pellet stove level sensor for a while now, and every attempt has taught me something. This time I think I've finally got it right. I'm using an HC-SR04 ultrasonic distance sensor connected to a NodeMCU ESP8266, running the Tasmota firmware, and housing everything in a 3D printed enclosure with magnetic mounting. The goal is to measure how much pellets are left in the stove's tank and eventually connect that to my own platform to get low-level warnings.





What Went Wrong Before

The first version of this build used the exact same hardware: an ESP8266 connected to the HC-SR04 sensor. I was running Home Assistant with ESPHome to read the distance and display it as a chart showing how much fuel was left. It worked well for me personally, but the problem became obvious the moment I tried to turn it into a commercial product. Not many people in my area know about Home Assistant, and even fewer want to set up a home automation server just to monitor their stove.

So I went back to the drawing board and tried a second approach using a time-of-flight laser distance sensor paired with Arduino Cloud. I even made a dedicated video about that version. But it had a critical flaw: as soon as dust settled on the sensor, the readings went completely unreliable. Since this thing is meant to live inside a dusty pellet tank, that was a dealbreaker.


Why Tasmota This Time

For the third version I decided to go back to the ultrasonic sensor, which avoids the dust sensitivity problem, and replace the software layer entirely. I'm now running Tasmota, an open-source firmware for ESP devices that supports both the ESP32 and the ESP8266. What makes it so appealing is the range of communication options it gives you out of the box. You can use MQTT, a built-in web UI, HTTP, or serial, which means I can connect it to almost any platform without locking myself or a customer into a specific ecosystem.

Tasmota already has built-in support for the HC-SR04 ranging sensor, so all I need to do is enable it in the firmware and configure the right pins. The documentation covers everything clearly and kept the setup pretty straightforward.

I'm also building this to connect to a platform I've been developing called Ding, which gathers data from remote sensors and generates predictions. The plan is to send the distance readings to Ding so it can give me warnings when the pellet level gets low.


Building the Firmware

Because I'm using a custom version of Tasmota, I'm not grabbing a prebuilt binary. Instead I'm using PlatformIO inside VS Code to compile my own build targeted at the HC-SR04 sensor. Inside the firmware configuration, the only things I need to change are enabling the sensor driver and setting the correct pin assignments. In my case that's D5 for the echo signal and D6 for the trigger.

Once the build is ready, I flash it to the NodeMCU using the ESP flasher tool. You select the COM port the board is connected to, point it at the compiled firmware file, and hit flash. After a few seconds it's done and you can open a serial monitor to confirm the device is booting correctly. If everything went right, the Tasmota web UI should appear and start showing live distance readings from the sensor.


The Circuit and Wiring

The HC-SR04 runs at 5 volts, which is fine because the NodeMCU supplies that on its Vin pin. But the echo pin outputs 5V logic, and the NodeMCU's GPIO pins expect 3.3V. Feeding 5V directly into a 3.3V GPIO pin would likely damage it over time, so I'm using a simple voltage divider to bring the echo signal down. A 1k ohm resistor and a 2.2k ohm resistor in series between 5V and ground create a midpoint that outputs roughly 3.3V, and that midpoint connects to D5 on the NodeMCU. The trigger pin is 3.3V tolerant so D6 connects straight to it without any extra components.


The 3D Printed Enclosures

Getting the hardware into a proper housing was the other big challenge. I designed two separate enclosures and 3D printed them both.

NodeMCU Enclosure

The NodeMCU enclosure is a snap-fit box sized specifically for the NodeMCU module. It has two recesses at the bottom for 10mm ring magnets, which I fix in place with a drop of super glue. These magnets let the controller sit on the outside of the metal pellet tank and hold firmly without any fasteners. The lid clips closed and the case has cutouts shaped for both USB-C and the older micro-USB connector to accommodate different board revisions.

Sensor Enclosure

The sensor enclosure required a bit more preparation. The HC-SR04 comes with header pins soldered on, but the enclosure doesn't leave room for a connector sticking out. So the first step is removing those pins. I added a bit of extra leaded solder to them to make them easier to melt, then pulled them all off cleanly.

The enclosure has a slot for a flat phone cable, about 4mm wide and 2mm thick. I thread the cable through the slot and solder the four wires directly to the pads on the sensor board. The darkest wire goes to ground, the yellow one to VCC, and the remaining two carry the echo and trigger signals. Once the wires are in, the cover clips on and has two small pins that press the sensor board forward against the front face, keeping it firmly seated. I add a blob of hot glue to the cable exit point as a strain relief so nothing can pull the connections loose. A single 10mm magnet goes on the back of the enclosure with super glue, so the sensor can stick directly to the inside of the metal pellet tank lid.


Testing It Out

With both enclosures assembled and connected, I powered everything up and checked the Tasmota web UI. The distance reading was live and updating at a regular interval. Testing it by placing my hand in front of the sensor brought the reading down to around 4 cm. Moving my hand away let it measure all the way to the camera across the room, showing about 30 cm. Pointing it straight up at the ceiling gave a reading of around a metre, which matched the actual room height.

The next step is to take the raw distance value and map it to a percentage based on the total depth of the pellet tank. Once I know the full range from the sensor down to the bottom of the tank, a simple conversion turns any distance reading into a "how much fuel is left" percentage.


Conclusion

This third version feels like it's finally going in the right direction. The ultrasonic sensor sidesteps the dust sensitivity problem from the second version, and switching to Tasmota opens the door to anyone regardless of the platform they use. The 3D printed enclosures keep everything tidy and the magnetic mounting makes installation straightforward on any metal surface.

I still have to see if this turns into a real product, but the hardware and firmware foundation is solid. If you want to follow along with the next steps, make sure to subscribe to the Taste The Code YouTube channel so you don't miss what comes next.



Tools and Materials


Other Resources

You might also enjoy this

How to make a perfect fit prototype PCB for electrical boxes in Altium

We as makers know that finding the perfect enclosure for our projects can be challenging. Many opt for 3D printing or custom manufacturing,...