Over the past few years we've seen ever-more novel apps that utilise your phone's on-board sensor data, but what if you wanted more? What if your app needed a metric that you couldn't garner with the included device sensors? What measurement could be genuinely helpful to people in their day-to-day lives? How would one go about adding an extra sensor to their device?
That's what we've been working on in Redweb Labs for the past few months, and we've come up with a prototype for what we've called the Blaze UV Key.
A little while ago, we came across a UV sensor that allowed us to measure the watts per square cm of UV radiation. It's not a complicated piece of kit – it’s just a little sensor – but we thought it might be handy if we could turn that w/cm into a metric that would be useful to people, say a UV Index meter for where you are right there and then, not what the reading was at a weather station 20 miles away, three hours ago. Given that the incidence rates for skin cancer in the UK have more than quadrupled since the mid-70s and others had tried novel approaches to making people aware of their UV exposure, we decided that we'd make a prototype.
There were many different aspects to this project, but the aspect we're going to detail in this blog is how we got the data from our sensors into our phones. So, how did we go about that? Well, there's a couple of techniques that we considered using...
With an iPhone, there's the Lightning port, but getting access to that involves a lot of red tape with Apple. There's Bluetooth, it's cheaper and lower powered than ever before, but widespread device compatibility can be a little tricky at times and dependent on the type of Bluetooth chip you're using. Also, keeping track of a disconnected bluetooth device can be a nightmare. Wi-Fi? That requires a network to get the devices talking to each other, not to mention the power requirements of creating an ad-hoc network on either device to connect the pair. With all of that in mind, we decided to go for the headphone jack.
By using a technique called frequency-shift keying (FSK) we can transmit data through tones that signify 1s and 0s et al. Connecting devices with the headphone jack is nothing new; if you cast your mind back to the era of the Sinclair ZX81, loading a program was done with an audio cassette that had a program stored on it with FSK. By playing the audio tape to the Sinclair, you were loading the program into the device.
Though not widespread, this technique has made appearances in recent technologies (such as the Jawbone UP), but we couldn't find a great deal of resources to help us figure out the circuit we needed to connect to our phones. The 3.5mm jacks you have on your iOS/Android devices aren't just line-ins like a lot of older sound cards were; because they can switch from being an input to an output, there is a software switch that we have to trigger.
This is not simply a matter of plugging in a jack and passing a current through it to get a signal – in order for the phone to detect that the port should be used to receive input, the jack connected to the device has to have a certain amount of resistance and grounding. Again, documentation for this isn't great, maybe that's because a lot of people who need to know this stuff can figure it out on their own, but I struggled initially. After a bit of digging, we found a circuit diagram that allowed for microphone input. Once we'd set about putting that circuit together, we used an Arduino Uno to pass some simple signals through to my MacBook (which shares a similar audio jack with that of the iPhone/Android devices).