Now that we’ve built the sensor for our Raspberry Pi-based oil tank monitor, it’s time to build the interface and integrate the Pi hardware.

Proof-of-concept interface circuit on solderless breadboard.

Proof-of-concept interface circuit on solderless breadboard, attached to a Raspberry Pi Model B+.

The interface is pretty simple. For the I2C bus, it’s pretty much just wiring jumpers to terminal blocks. For the Ping))) sensor, there’s a bidirectional voltage divider to adapt the Ping)))’s 5-volt interface to the Pi’s 3.3-volt logic. (This board was a lot more complex when I was playing with the I2C bus extender!)

Circuit schematic.

Circuit schematic—click to enlarge.

Parts

  • J1: Six-pin male header. I chose a right-angle header.
  • J2–J4: Two-position screw terminal.
  • C1: 100nF ceramic capacitor (noise filter).
  • R1: 330-ohm 1/4-watt resistor
  • R2: 1.8k-ohm 1/4-watt resistor
  • R3: 3.3k-ohm 1/4-watt resistor
  • D1: 1N5226B 3.3-volt Zener diode
  • D2: 1N6263 Schottky diode

Except for the headers and terminals, I got these parts out of the following parts kits available on Amazon. They’re nice kits if you need an assortment of standard parts:

Assembly

After testing the circuit on solderless breadboard, I wired it down onto a SparkFun Solder-able Breadboard. These neat little boards have internal traces that match solderless breadboard, making it easy to transfer designs over.

soldered-circuit

The completed circuit on solder-able breadboard, with the sensor wires and jumpers attached.

The back side of the breadboard. Note jumper routed on back to avoid blocking the header pins.

The back side of the breadboard. Note jumper routed on back to avoid blocking the header pins.

I used a spare length of Cat3 wire to make the jumper connections. I was careful to match the wire colors to the colors used on the sensor lead; this makes it easy to match up which wire goes to which terminal.

A set of female-female jumpers is used to connect the board to the Raspberry Pi’s GPIO connector. Any GPIO pin can be used for the Ping))) sensor, but I chose GPIO 4 to keep everything close together.

In the picture above, the jumpers connect to the following pins, in order of appearance:

  • RED: Pin 4 “+5V”
  • BLACK: Pin 6 “Ground”
  • BLUE: Pin 1 “+3.3V”
  • YELLOW: Pin 3 “SDA”
  • GREEN: Pin 5 “SCL”
  • BLUE: Pin 7 “GPIO 4”

I also connected a PL2303HX USB to TTL UART serial adapter cable to the Pi, for use as a console. The PL2303HX is cheap, so I’ll just leave it attached for convenience. It attaches as follows:

  • WHITE: Pin 8 “UART TXD”
  • GREEN: Pin 10 “UART RXD”
  • BLACK: Pin 14 “Ground”
  • RED: Wrap in electrical tape and zip-tie out of the way. This cable supplies +5V from the USB connection when the cable is plugged in; it’s of no use here.
Interface board and USB cable attachments to the Raspberry Pi's GPIO header.

Interface board and USB cable attachments to the Raspberry Pi’s GPIO header.

For Internet connectivity, I added a Linksys USB10T Ethernet adapter I had sitting around. This interface is only 10Mbps, but that’s plenty for this use. The USB10T uses the Pegasus chipset and is supported out of the box by Raspbian Linux. Because my oil tank is a short distance from my home’s central Ethernet switch, it made sense to use the wired hardware. You could use a WiFi adapter, or use a Raspberry Pi B+ board with built-in Ethernet.

To hold all this stuff, I found an old electrical time switch with a mechanical clock movement inside. The clock movement popped right out, giving me a nice metal case with pre-drilled holes and wall-mounting brackets. I drilled a few holes and secured the boards with appropriate screws, nuts, and nylon standoffs. (I carefully used M3 screws, but it was a tight fit for the Pi. You should use M2 screws and standoffs.)

The Pi, interface board, USB cable, and USB Ethernet adapter in the repurposed time-switch case.

The Pi, interface board, USB cable, and USB Ethernet adapter in the repurposed time-switch case.

The Pi is mounted on two sets of 6mm standoffs to provide extra clearance for the USB cable over the interface board. The network adapter is attached to the lid of the case using a large piece of industrial-strength Velcro. I attached a three-foot Ethernet cable to the adapter and threaded it through the case, attaching a zip-tie to keep it from being pulled out too far. I will run an Ethernet jack next to the unit. In the meantime, an 8P8C modular coupler lets it attach to a longer Ethernet cable. The USB power cord and sensor cable are held in place by the standard electrical clamp.

The completed hardware, installed on the (cobweb-covered) wall near the oil tank with the sensor in place and attached.

The completed hardware, installed on the (cobweb-covered) wall near the oil tank with the sensor in place and attached.

Next: Basic software for reading the tank level.

 

Leave a Reply