October 2014 Archives

Oil fill sensor

I wanted a way to automatically detect how much fuel oil I have. There are some off-the-shelf remote sensors of varying cost, but I wanted something that could interface with my computerized environmental monitoring and notification system and wasn't too expensive.

There are two common types of sensors, a magneto-resistive sensor with a float and an ultrasonic sensor. Ultrasonic is neat, but the ones designed for use in fuel tanks are quite expensive, so I went with the less expensive float sensor.

I got one from Syba Systems for $ 129. I got the 0 - 5 VDC output model, 42" long, for a vertical 275 gallon tank. It's accurate to about 1/2" which isn't great, but is acceptable for my purposes. It fits in a 1 1/2" NPT hole, but my tank had a 2", so there's a reducing adapter as well. There was previously a 2" plug in that hole. That does raise the sensor up a little so there's probably a little bit more oil than the sensor would indicate, but that's not really a problem.

This is what it looked like before installation. The black thing on the left is the float, which slides up and down the stainless steel rod.

It requires a power supply of 12-24 VDC. Normally you'd need a 12 VDC adapter, but I already had one with sufficient capacity that powers the existing proximity sensor and electronic lock at my front door.

The 0 - 5 VDC sensor analog output I decided to attach it to my existing Phidgets 8/8/8 USB-based analog and digital I/O board. That board has 5 V analog inputs and is already integrated with my server infrastructure, so that was a logical choice.

If I were starting out from scratch, I'd probably use a SparkCore instead of Phidgets. It's less expensive, and has built-in Wi-Fi. There's one caveat to this - it has 3.3V analog inputs, but that's not that big of a deal, as I'll explain. 

I'm glad I tested the sensor, because it seems that it can output more than 5 VDC - I got 6.19 volts!

To be safe I put a resistor voltage divider made with 10K resistors in front of the ADC (analog to digital converter) input. This will result in a maximum of around 3V, but since the Phidgets ADC is 10-bits, there's still plenty of resolution. This is also the solution to using a SparkCore since that will be sure to keep the input below 3.3V.

divider.jpgThis is the Phidgets installation.

The Phidgets ADC outputs a value of 0-1000, I think. With my voltage divider I seem to get something around 0-619, which seems about right.

The other issue is when translating the gallons, the curvature of the tank. This is just a simple math problem, the area of a circular segment given its height. I didn't remember the formula, but it only took a few seconds of searching to find it.

I already have an infrastructure where my Apache Tomcat webapps can send Apple Push Notifications to a custom app (called "Lock") on my iPhone. Here it is letting me know I'm low on oil:

And that the tank is currently being filled:

One of the problems I'm having is that the data from the sensor is not particularly stable. I'm not sure whether it's the sensor or the ADC, but I'm tracking it to see how best to smooth the data. Well, samples 11-19 are during filling, so it's expected that those would be varying, but the other ones are more concerning. Maybe I should have gone with ultrasonic!

Until I figure out how to smooth the data and get a larger sample of data, I'll wait before implementing the next part, an analysis of how much oil I'm consuming. I have accurate outdoor temperature values by the hour from my weather station, so I should be able to accurately calculate heating degree days for comparison, as well.

Spotify Next Track Button

Wouldn't it be handy to have a big button you could hit that would activate the Spotify Next Track button? It wasn't that hard to do! I had the prototype working in couple hours.

The reason for this is that I often listen to other people's public Spotify playlists, and there are always a few songs I don't really like and would rather skip over. Hitting the next track button when I'm sitting at my Mac is no problem, but I use Airfoil and Apple Airport Expresses to pipe music all over my house. It's less convenient from my kitchen.

I could open up my iPhone and use the next track button in Remoteless, but that takes several seconds. A big button would be more fun.

Before you get too excited about this project, I should warn you that not all of the code is included. There is a piece that's not published. I'll tell you how it works, but you'll need to implement that yourself. Sorry about that.

The hardware couldn't be simpler. This is my prototype, which has a little button, but it works the same as the big button. It uses a SparkCore from spark.io. It's a tiny computer designed to work with the cloud. It's mostly software compatible with the Arduino but with built-in Wi-Fi and cloud computing support. It's powered by Micro USB and can be battery powered. And it's only $ 39!

The button is connected to the D0 input, and the inputs can be configured with internal pull-ups, so the switch only needs to be connected to ground. Easy!

I got the button from SparkFun for $ 9.95. It comes in several colors, and there's a less expensive version for about half the price. It's big - almost 4" (100 mm). The button has an light in it, but I did not use the light in this project - I only used the switch.

I also got the mini-modular protoboard from SparkFun for $ 3.95. It's not strictly necessary, but it's a convenient size to fit inside the project box. That's not the one above, that one came with the SparkCore, but I wanted a smaller one inside the box. A soldered protoboard would also be a reasonable choice.

Finally, I got the 2A (5V) micro-usb power supply from SparkFun for $ 5.95. Any micro-USB power supply will work. And the SparkCore uses a miniscule amount of energy - less than 1W at 120V at the wall plug with this power supply.

The only other thing I purchased was a box from Digi-Key, $ 8.40. It's a 4.6" x 4.6" x 2.4" Black ABS plastic utility box. It was just the right size for the button.

You set up the SparkCore first using the smartphone app, associating it with your account and telling it your Wi-Fi password.

Programming it is done using Wiring, the same C-like language as the Arduino, but you can program it right from your web browser and flash the Spark over Wi-Fi. It's pretty cool. Here's my code:

Not much to it! The main thing is that when you press the button an event is sent into the cloud.

One of the nice things about the Spark system is that even though my code is essentially listening for events, my code makes requests outbound using HTTP Server Side Events (SSE). This eliminates having to open ports in the firewall, deal with dynamic IP addresses, etc.. Easy and pretty efficient.

My code is written in Java and runs in Apache Tomcat. I'm not releasing the source because it contains a bunch of proprietary code that I don't want to release. That infrastructure is why I was able to write it so quickly, however. But I will explain how it works, and you could easily do something similar in your favored language.

The Java code basically runs a SSE client that makes a connection to the Spark API server and waits for messages. If the connection is lost, it just makes a new connection. One of the messages is an event message, which signals that the button was pressed. I then call an AppleScript to trigger Spotify to advance to the next track.

And finally, the AppleScript. This tells Spotify to advance to the next track. I'm not sure if Spotify for Windows has similar capabilities, but this is super quick and easy on the Mac. Well, if you have Java code that can use osascript on the Mac to interface with AppleScript. That's left as an exercise for the reader.

As for the box, mark the location of the holes:

I started with smaller drills are worked up to larger sizes to reduce the risk of shattering the box, though ABS is pretty forgiving. The side hole is for the power supply and is 1/2" (the USB connector end needs to fit through it). The top hole is 1" to hold the switch, though I only had a 7/8" twist drill so I used that and just widened it a bit with rocking the drill bit and a utility knife.

drilled.jpgThis is what the button looks like:

On the bottom is the microswitch and lamp (not used). A little twist allows that to be removed, at which point you can unscrew the white nut.

Here are the leads soldered to the switch after I mounted the switch the top of the box.

And here's the insides:

And that's it. The final product is show at the top of the page.

About this Archive

This page is an archive of entries from October 2014 listed from newest to oldest.

October 2013 is the previous archive.

November 2014 is the next archive.

Find recent content on the main index or look in the archives to find all content.