UPDATE, December 2023: I’m late to the party, but have just discovered the Espressif ESP-32 family of microcontrollers. These microcontrollers are cheap, low-power, run on 3.3V, have onboard wifi and GPIO pins, precisely the architecture needed to efficiently build a remote propane sensor. A full RPi is huge overkill for this application. I’m going to be re-implementing the remote propane sensor in 2024 using the ESP32 board, publishing to MQTT so that Home Assistant can read the sensor values, present it remotely, and keep track of it in a log over time. The basic principle is the same, however — a Hall Effect sensor reads magnetic value and delivers voltage readings to a central source.
SEE THIS BLOG POST FOR AN UPDATED, BETTER VERSION.
One great use-case for the Internet of Things is to remotely monitor gauges and levels. In addition to spot-checks, wiring them up also allows you to auto-log values over time, so you can get a nice graph of usage, economize where you can, and project future usage.
If your property is served by liquid propane gas (LPG), there might be occasions where you want to be able to check the tank’s propane level from your phone. Ideally, you might even want it to notify you when the tank is, say, at 25% or lower, so you can schedule a refill. And wouldn’t it be useful to see which seasons, use-cases or appliances tend to consume the most propane?
There are commercial vendors for remote propane monitoring, but they’re usually tied to some kind of subscription service, some of them come bundled with a mandatory cellphone plan, and often tied to the fuel vendor themselves. I wasn’t interested in paying, say, $5 per month just to be able to check a value.
This made a perfect use-case for a simple microcontroller project.
WARNING: Fiddling with electricity, even very low 1-3V such as what we’re talking about here, around combustible material is a very bad idea. Only do this if you know what you are doing. Be sure all your connections are fully sealed and weatherproofed. Maker assumes all risk.
Ready to accept that risk? OK, here’s how I built it:
First, Some Background: How do Propane Gauges work?
At first, I thought that these gauges somehow have a physical pass-through into the tank, but they’re much more clever than that. They make use of magnets to keep the integrity of the tank fully sealed.
There’s a very good video here from DPS Telecom (a vendor of remote monitoring solutions for businesses and homes) which explains how such fuel gauges work:
So to proceed, you’ll need a gauge for your tank which is “Remote Ready.” This has been standardized in America, and you’ll want what’s called an “R3D compatible” gauge. They can be had for about $9-15.
This simply means that the gauge both reads and conveys a magnetic value. As the needle moves, a magnet also moves, which can be read by a Hall Effect Sensor placed just over the needle (under the black plastic.) Luckily, this standardization means that these gauges will almost certainly work on your existing tank, simply by removing two screws, removing the existing gauge, and screwing the new one in. Or, if your existing gauge says it’s “remote ready,” as many do, you’re already set.
But in looking for a pre-made “reader” cable, not only are they hard to find and rarely sold separately, I was shocked to see several vendors asking $150+ for them! You don’t need a commercial reader cable — you can make your own, with a Hall Effect sensor chip which you can find for about $1.
Building Our Remote Gauge
OK, now that we know how these gauges work, how can we get the Raspberry Pi to “read” it? We need to translate that magnetic signal into some kind of voltage. Once that’s done, since RPi doesn’t have a native analog to digital converter built in (as the Arduino does), you’ll also need some kind of Analog to Digital Converter (ADC) chip, so that RPi can make use of the signal in digital form. I chose the MCP 3008 for this project, which you can find on Amazon for about $9.
- Raspberry Pi (I used an RPi4)
- Analog to Digital Converter MCP 3008 Chip
- 49E Hall Effect Sensor Chip
- Half-size breadboard
- 1 10KOhm resistor
- An RD3 Compatible Propane Gauge
- Wires for connecting breadboard
- 3-wire outdoor shielded cable
- Small magnet for testing and setting values in the gauge during prototyping
- Glue/epoxy to set the Hall Effect sensor in place
- Outdoor Enclosure plus cable glands
The key piece of circuitry is the Hall Sensor. I chose the 49E, which are super cheap and accurate enough for the purpose:Hall-sensor-49e
Here’s a demonstration of what I’ve built:
Experienced makers will no doubt notice that the Raspberry Pi 4, a full-fledged Linux computer, is extreme overkill for this application. But I’ll be using that same Pi to handle several other home automation tasks; this is just one of them.
Among the things to notice is that this MCP3008 chip can convert up to 8 analog voltage inputs. This project uses one of the 8. I’ll likely be using this same setup to remotely monitor things like humidity, temperature, soil moisture, etc. over time.
- Get Raspberry Pi configured with Raspbian
- Configure it for headless development via SSH. I used Visual Studio Code and its ssh remote development feature.
- Install prerequisites: CircuitPython and MCP3008 library
- Install pip and flask.
- Get sample code from Github. I’ve put simple Flask code (python) here: stevemurch/whidbey-raspberry-pi (github.com)
- Make circuit: Use the MCP3008 to take an analog input and convert it into a digital signal. See wiring diagram above. [Addendum from diagram: I put a 10k Ohm “pull down” resistor connecting the analog input data pin (MCP3008 channel 0) with ground. This is optional, but it tended to steady the values a bit more.]
- Solder Hall Effect Sensor 49E chip to 3 wires. Check the 49E datasheet and connect a wire for VCC, Ground and Voltage Out.
- Crucial step: Position the Hall Effect Sensor Chip exactly in the small channel, with the smaller side of the trapezoid facing DOWN (i.e., toward the gauge). With my 49E chip, this means the wires, from top to bottom, are VCC, GROUND and SIGNAL.
- Using the Raspberry Pi, take measurements at key values. This will vary considerably based upon how long your wires are, and where precisely you have the Hall Effect Sensor placed. My own values are shown in Table 1 below.
- Install the apache2 server and pretty NextJS/React app to show the gauge.
- Make sure the simple flask application (which is the API that the NextJS front-end calls) starts at RPi boot time. I’ve used gunicorn for this. I’ve set a value in the /etc/rc.local file for it to run at startup.
I’m putting some finishing touches on this code and will provide a link to the GitHub repository shortly. There are three main parts:
gauges.py: A library to spot-read a voltage and spit back out the gauge value
server.py: the flask API
frontend: a simple NextJS app which reads the API and presents a nice looking gauge to the user
- The trickiest part is actually affixing the Hall Sensor to the gauge. Good results are extremely sensitive to precisely where this chip is mounted, and there’s no easy way to lock it in place. I chose a hot glue gun method, but I might revise that to some kind of epoxy.
- The 49E Hall Sensor has a very narrow sensitivity range — highest values it ever reported were around 2.08v and lowest value around 1.3v. But that’s enough fidelity to translate it into a percent-full between 100 and 0. Here, it’s good to remember not to let the perfect be the enemy of the good. I don’t actually need single-digit precision; in this use-case, accuracy to within about 5% is more than adequate.
- I’m still determining whether or not the RPi is going to live outside. My preference is that it not live outside, and that only the 3-wire strand goes out to the gauge from the RPi. If it does have to live outside, it will be powered by Power Over Ethernet (POE) to keep cables to a minimum. I’ve purchased a POE splitter which will live in the external enclosure if so. This approach will allow just one cable to serve both power and data (ethernet.) But for weather-proofing reasons, I’d rather have the RPi mounted inside (in, say, a garage), and have a long-ish low voltage wire going out to the gauge. I’ve experimented with cable lengths and thus far can confirm that about 15 feet still works very well, even at the low voltages we are talking about. I don’t know if the voltage drop will be too significant beyond that length.
I’ll be adding in a simple email notification system when the value gets below a certain value, and I’ll likely connect the sensor values to something like Azure IoT services to log the levels over time. This will provide nice usage graphs, and even help show if there’s a leak somewhere that needs to be addressed. Hope this technote is a useful starting point for your next RPi project!