My house is heated by an oil-fired hot-air furnace. The oil tanks are in the far corner of the basement. Occasionally, I’ll walk over and glance at the float gauge to see if it’s time to order more oil. Often, I forget to check for a while, and then it’s a panic…

Now that computing power and electronic components are cheap, I set out to see if technology could solve my problem! There are a number of commercial solutions, but they’re all quite expensive. Some of the commercial level sensors cost hundreds of dollars themselves, not including anything to actually display the level!

I drew inspiration from Mike Podruchny’s blog, where he describes building an ultrasonic tank sensor for an outdoor tank using an Arduino. As a professional UNIX geek, I’m partial to the Raspberry Pi instead—and with the new Model A+, the Pi can be a cheaper solution if you’re looking to use a ready-made microcontroller.

This sensor head unit uses an ultrasonic rangefinder to measure heating oil in a standard 275-gallon indoor tank.

This sensor head unit uses an ultrasonic rangefinder to measure heating oil in a standard 275-gallon indoor tank.

My monitor features:

  • Controlled by a Raspberry Pi running Raspbian Linux
  • Collects oil level data from a Parallax Ping))) ultrasonic distance sensor
  • Calibrates the Ping))) with temperature data from a SparkFun TMP102 temperature sensor

I intend to add software for automatic monitoring and alerting when the oil level is low. I may also integrate it with my Nest thermostat, so that the heating temperature is automatically lowered when the oil level is critical.

IMPORTANT: These plans are provided without warranty or certification. They have not been inspected or approved by any authority. By using these plans, you accept all risks associated with the device. No representation is made that this device is free from hazards or suitable for the purpose for which it is presented.

This sensor is designed for indoor use only. It is not weathertight, and technical limitations require the Raspberry Pi device to be mounted within four feet of the device.


The distance sensor

I chose to use the name-brand Ping))) sensor because it’s reasonably priced and accurate. There are nearly identical generic sensors available at about a tenth the price (the HC-SR04) that could be used instead, although they will require wiring and code changes. The HC-SR04 uses separate leads for initiating the distance measurement and getting the result; the Ping))) uses a single lead for both.

The Ping))) is theoretically accurate to 1 centimeter. However, that requires precise timing as well as temperature calibration. It is difficult to obtain that precision with a preemptive-multitasking OS like Linux, especially using a scripting language.

The temperature sensor

The TMP102 temperature sensor is pre-calibrated and uses the I2C bus to communicate with the Pi. It’s more expensive than standalone temperature sensors like the LM32, but it won’t require an analog-to-digital conversion circuit for use with the Pi.

It does introduce a major limit, however. The I2C bus has strict capacitance limits, and those limits can be exceeded by modest lengths of Category 5e cable. Therefore, the sensor unit must be mounted very close to the Raspberry Pi in order for the TMP102 (and any other I2C devices) to work. That makes my design unsuitable for outdoor tanks, unless you want to build a weathertight Pi enclosure.

Theoretically, you can build a buffered I2C-bus extension. I tried doing this using TI P82B96 chips; I couldn’t get it to work. But then, I’m a UNIX admin, not an electrical engineer.

Constructing the sensor head unit

This sensor is designed to fit a standard American 225-gallon heating-oil tank. It should work with any other tank having an available 2″ threaded port on the top.

From time to time, it may be necessary to remove the ultrasonic sensor for cleaning. For example, oil may splash on it when the tank is filled. To make it easier to do this, I designed the housing with a three-inch cleanout on the top. A two-inch cleanout wouldn’t leave enough room to get your hands inside and get the sensor out. As a result, the sensor unit is pretty large compared to the actual working bits inside.

WARNING: The sensors are not sealed from the oil tank. You must not install the sensor head in a location where oil may enter the sensor head. If you have multiple interconnected oil tanks, you should usually install the sensor head on the tank farthest from the filler pipe. Do not allow your oil company to overfill your tanks or damage to the sensor may result.

Bill of Materials

Plumbing (from your local home center)

PVC and acrylic plastic have very good resistance to diesel oil. Home heating oil is essentially identical to diesel oil, so these are good choices for constructing our sensor.


You will also need soldering equipment and supplies.


  • Drill (cordless recommended)
  • 11/16″ drill bit, Forstner preferred, but spade will do
  • 1/4″ twist drill bit
  • 1/8″ twist drill bit
  • Scrap wood block for drilling
  • Hacksaw with fine teeth
  • Coarse to medium sandpaper
  • Squeeze clamps
  • Small needlenose pliers
  • Linesman’s/Electrician’s pliers
  • Sharp utility knife
  • Countersink bit

1. Fabricating the sensor mount

In some ways, the hardest part of this build is making the plate that the Ping))) sensor will mount to. I chose to use a leftover piece of 1/8″ thick clear acrylic (sometimes called Plexiglas, but any brand will do). Acrylic likes to crack when you work with it, so work slowly, carefully, and with plenty of support.

The completed sensor bracket with Ping))) sensor installed.

The completed sensor bracket with Ping))) sensor installed.

Do not remove the protective label covering the acrylic until you have completed cutting and drilling the bracket.

  1. Download the Ping))) Datasheet. Print out page 1, making sure you print at 100% scale. (Most PDF viewers default to “scale to fit,” and thus may print out the datasheet at the wrong scale.) Use a ruler to verify that the diagram at the bottom of the page printed at the dimensions shown. If not, adjust the print enlargement scale and print it again until you have an actual-scale printout.
  2. Place the 2″ PVC pipe against the acrylic sheet. Using a Sharpie, trace tightly around the pipe, creating a circle on the sheet’s backing.
  3. Working carefully, cut along the inside of the traced line. You want your circle to be ever so slightly smaller in diameter than the pipe’s outside dimensions, so that it will fit snugly in the threaded adapter.
  4. Test-fit the circle in the threaded adapter. Use the hacksaw or sandpaper to adjust any high points until it fits snugly. You should be able to press it into place with finger pressure, but it should not fall out.
  5. When you have cut out the circle, place it on top of the datasheet printout. Use the left-hand picture of the Ping))) as a guide, centering the module’s sensors on the acrylic circle. Make sure that there will be enough clearance between the corners of the Ping))) and the edge of the circle to accommodate the thickness of the 2″ Schedule 40 DWV pipe that will be inserted over it! Mark the centers of the sensors and the mounting holes on the acrylic with the Sharpie.
  6. Clamp the circle securely to a block of scrap wood. With an 11/16″ drill bit, carefully drill out the holes for the sensors. If using a cordless drill with multiple gears, select the slowest gear. Use a speed that is fast enough to avoid catching the drill, but not so fast that you risk melting the plastic.
  7. Use a 1/8″ drill bit to drill the mounting holes. Work with extreme care; the mounting holes are close to the sensor holes, and the acrylic will want to split.
  8. Attach the two nylon spacers to the acrylic circle using the two M6 screws. The threaded portion of the nylon spacers should point away from the acrylic. The Ping))) will rest over the nylon threads when the unit is assembled.
    Note: Some of the pictures show an earlier prototype assembly where the spacers are attached with nuts; this is impractical as it prevents easy disassembly of the sensor head for cleaning.

2. Wiring the Ping))) sensor

The Ping))) has three header pins. It’s not practical to fit a standard female header connector onto these pins inside a 2″ pipe. I chose to solder wires directly to the header pins. Alternatively, you could desolder the right-angle header pins and replace them with straight-up header pins, and then use an appropriate header connector.

My prototype, pictured, used four-conductor hookup wire (with one conductor stripped off) for this connection. That proved to be an error when I abandoned the I2C extender. That’s why these instructions don’t quite match the photos.

  1. Cut a 4.5-foot length of Category 3 or better twisted-pair cable.
  2. Remove about six inches of the outer jacket from one end of the cable. Separate the wire pairs, but do not untwist them!
  3. Using a spare piece of twisted-pair cable—not the five-foot length you just cut—obtain about six inches of white-with-blue-stripe wire.
  4. Solder wires as follows, stripping about one inch of insulation and wrapping the wire tightly around the header with fine needlenose pliers before applying solder:
    SIG: Orange with white stripes
    5V: White with orange stripes
    Spare length of white with blue stripes

3. Wiring and attaching the TMP102 sensor

The TMP102 sensor installed in the PVC pipe. In this prototype, hookup wire was used instead of twisted-pair cable.

The TMP102 sensor installed in the PVC pipe. In this prototype, hookup wire was used instead of twisted-pair cable.

  1. Cut a 1.5″ length of the 2″ Schedule 40 DWV pipe. (This should be just long enough to mate the male threaded adapter to the 3″x2″ reducer.)
  2. Place the TMP102 breakout board against the inner edge of the cut pipe. Using a Sharpie, mark the location of the mounting holes.
  3. Using an appropriate small drill bit , drill holes for mounting screws in the PVC pipe. You’ll need small wood screws that will attach the TMP102 securely without protruding from the pipe, and without shorting any circuit traces on the TMP102.
  4. Untwisting the wires the least amount necessary to do so, solder wires from the twisted-pair cable to the TMP102 as follows:
    SCL: Blue with white stripes
    SDA: Green with white stripes
    GND: Spare length of white with blue stripes
    3V3: White with green stripes
  5. Wrap the unused brown pair of wires along the outer sheath of the cable.
  6. Using the IDC, connect the three white-with-blue-stripes wires.
    Hint: Use a hemostat to keep the three wires from slipping relative to each other while you use your linesman’s pliers to crimp the IDC.
  7. Slide the PVC pipe over the twisted-pair cable, with the screw holes toward the Ping))) sensor.
  8. Attach the TMP102 to the PVC pipe with the wood screws.

4. Gluing the PVC

WARNING! PVC primer and cement fumes are toxic! Work in a well-ventilated area and/or use an appropriate respirator. Wear nitrile gloves.

WARNING! PVC primer and cement may permanently damage sensors and wires! Use extreme care when applying and handling these chemicals to avoid damage. The primer is especially prone to dripping where you don’t want it.

NOTE: The pictures show a prototype version of the sensor that used hookup wire instead of twisted-pair wire. Your wiring will look different.

The plastic components are assembled in this order. This prototype used hookup wire instead of twisted-pair cable.

The plastic components are assembled in this order. This prototype used hookup wire instead of twisted-pair cable.

  1. Insert the acrylic circle into the threaded male adapter. Ensure that it is firmly seated.
  2. Push the Ping))) sensor onto the nylon spacers. Ensure it is firmly seated. The M3 connectors are somewhat large for the Ping)))’s mounting holes, so this should work fine.
  3. Carefully test-fit the PVC pipe into the male adapter, being careful not to shove the TMP102 against the Ping))). You’ll want to wind up with the TMP102 along the long side of the Ping))) that doesn’t have the header pins. Mark both PVC pieces with the Sharpie to indicate the correct orientation before taking them apart again.
  4. While being very careful to avoid dripping on the wire or electronics, very carefully apply a small amount of PVC primer to the inside of the male adapter and the matching outside end of the PVC pipe (the end with the TMP102) following the manufacturer’s directions. When the primer is ready, apply a thin layer of PVC cement to the primed surfaces, being careful not to apply so much that it will squeeze out onto the electronics. Then immediately push the pieces together, very slightly out of alignment, and give them a slight turn into their final orientation. (This will help create a gas-tight seal.)
  5. Thread the 3″x2″ reducer over the twisted-pair cable. Use primer and cement to glue it to the 2″ pipe using the same care and technique.
  6. Thread the cleanout adapter (female thread) over the twisted-pair cable. Use primer and cement to glue it to the reducer, using the same care and technique.
  7. Wait at least ten minutes for the PVC cement to set.
  8. Being careful not to drill into the wire, clamp the assembled sensor unit to your workbench and drill a hole into the side of the 3″ x 2″ reducer to accommodate the twisted-pair cable. For most cable, a 1/4″ twist bit should fit nicely. You want a hole that’s snug, to minimize any oil fume leakage.
  9. Using a sharp utility knife and/or a countersink bit, round off the outside edge of the wire hole to prevent sharp edges from cutting the cable.
  10. Hold the countersink bit in your fingers. Place it on the inside of the wire hole and twist it to deburr the hole and file off any sharp edges that could damage the cable.

    Deburring the inside of the wire hole using a countersink bit.

    Deburring the inside of the wire hole using a countersink bit.

  11. Wrap electrical tape around the cable on the inside of the sensor to prevent it from pulling through the hole. This will act as a strain relief.

    Electrical tape wrapped around the end of the cable's outer jacket will prevent it from being pulled through the hole, acting as a strain relief.

    Electrical tape wrapped around the end of the cable’s outer jacket will prevent it from being pulled through the hole, acting as a strain relief.

  12. Thread the twisted-pair cable through the wire hole. Leave enough slack inside the sensor casing to avoid strain and allow for maintenance.
  13. Install the 3″ threaded plug snugly.

This completes construction of the sensor head unit. Set it aside until you’ve built the interface board and tested it. The interface board will be covered in the next post.

The completed sensor head  assembly. As mentioned, the purple PVC primer is very runny and gets everywhere, even when you're being careful.

The completed sensor head assembly. As mentioned, the purple PVC primer is very runny and gets everywhere, even when you’re being careful.


The business end of the completed sensor head unit. Note that the author failed to carefully note the position of the TMP102 module compared to the Ping))) while gluing the unit together. Thankfully, there’s just enough clearance between the Ping))) headers and the TMP102 board. This may not have been true if using the cheaper HC-SR04 sensors, which have four header pins instead of three.

Continue to Part 2: the interface board.


Leave a Reply