Holding a smoke alarm, battery installed, is somewhat like holding an unwound jack-in-the-box. While you know that it shouldn’t go off, there’s still a nagging suspicion that it might. I get a similar feeling when I check news websites in the morning – somewhere in the back of my mind, I suspect that the world might have caught on fire while I was asleep. So, it made at least some degree of sense to me to build a News Alarm – a device that sounds an alarm when specific new stories are detected ‘off the wire’.
Last week, I wrote a simple set of Classes in Processing which connect to the New York Times NewsWire API. The NewsWire has been described by the NYT R&D guys as a ‘firehose’ – it send out a live stream of articles as (or before) they are posted or published by the Times. The Processing Classes allow you to hook up to the feed, and to set up alerts that are triggered when stories with specific keywords or descriptors are published. By attaching filters, you can in effect adjust the tolerance of the alerts, so that you can be notified when a key word, person, or location appears at all, or when it appears repeatedly over a period of time. For example, I might want to be alerted when any story about Canadian Prime Minister Stephen Harper comes across the NewsWire. I can set this up like so:
NYTNewsWire wire = new NYTNewsWire();
wire.addFilter(“person”, “HARPER, STEPHEN”, 0);
I’ve asked the NYTNewsWire object to listen for stories tagged with Mr. Harper. I’ve set a tolerance of 0, which means that I’ll be alerted if stories come up at any frequency. If I wanted the alert to only be published if a LOT of stories about Harper came across the wire (if he were, say, to resign, or be impeached, or disappear, or other such good news), I can adjust this frequency number. Here, I’ll only be alerted if more than 25% of the wire stories are about him:
NYTNewsWire wire = new NYTNewsWire();
wire.addFilter(“person”, “HARPER, STEPHEN”, 0.25);
Obviously, we can set up any number of filters and get our alerts to be specific as possible. Which is useful if you are going to, say, be hooking up the alert to a 85 dB smoke alarm.
Smoke detectors work by detecting small particles of smoke as they pass through the sensor inside the device itself. There is a good parallel here to what our software ‘news detector’ does (detecting small particles of news as they pass through the feed), so I thought it would be an interesting proof-of-concept to wire up a smoke alarm to the NewsWire and bring the virtual news stream into the physical world. As it turned out, this was fairly simple. All smoke detectors have a text button which sounds the alarm – you can see the bracket-shaped metal contact for the test button on our alarm above. What we ended up doing was wiring into the test contacts, then running these wires through a breadboard to a programmed Arduino, and from the Arduino via USB to my MacBook.
I am not particularly skilled with electronics, so I asked my friend and colleague Dennis Rosenfeld to do most of the dirty work. Dennis has a wealth of electronics and software knowledge, as well as being a talented artist in various media. ‘Hacking’ the smoke detector took about 30 minutes all told, and in short order we had a device that was ready to be connected to my simple Processing App.
In the photo above, you see a list of news items that have been broadcast over the NewsWire while the application has been running. As each of these news stories appears, they are checked against a filter. If the filter is matched, a signal is sent through the Arduino to the NewsAlarm, which sounds for about 1 second (this duration can be controlled in the Processing app, to produce a short chirp or a long alarm). A successful ‘hit’ also lights a small LED on the breadboard.
As you can see, it works! Our next step will be to put the components onto a small circuit board, and to implement a wireless relay so that the alarm doesn’t need to be connected to the computer via a cable.
Ultimately, I’d like to produce an array of these devices that can be installed as a sort of ‘News Alarm Centre’.
In the meantime, I have the news alarm running – queued up to sound if more than 50% of the NYTimes headlines contain the word ‘aliens’. You never know… right?