This is a project about earthquakes. On the 29th September 2009 a strong, magnitude 8 earthquake struck of the coast of Samoa. It happened early in the morning and caused a Tsunami which killed nearly 200 people. It was evening, after work when I heard the news here in the UK.
The next day at work I was curious and wanted to learn more about this event, so I looked up the USGS website and started reading. As I looked around the site, I came across a page with a picture of the globe on it and a large yellow square over the Samoan Islands. As I looked at this chart, and briefly refreshed the page, another large square, this time red, appeared over the coast of Indonesia. The mouse-over read that it was a magnitude 7.6 earthquake. It had occurred minutes, if not seconds before I saw that red square appear.
I had just witnessed an earthquake occur on the other side of the world. While part of me was geeking out over how cool the near-real-time technology was, a much larger part of me spent those next few minutes thinking about the human impact, and what it must be have been like. The UK is not known for it's seismic activity, it's not something I'd spent much time thinking about before. However, because of the immediacy of the information, I felt much closer to it.
I told everyone in the office about what I'd just seen, but there was nothing on any of the regular news outlets about this, Only the red box on the map. It was about 1/2 hour later when the news of this earthquake broke on Reuters, AP and the BBC, with their first pictures of the devastation. Although slightly less strong than the Samoan earthquake of the night before, the Sumatran earthquake struck much closer to a densely populated area. More than 1000 people lost their lives, over 130,000 homes were destroyed. At least 20 countries have responded to the disaster with aid. My own response is significantly less practical but I'm hoping it can help somehow, even if only on a psychological level.
I'd like to introduce you to what i'm calling 'the Seismic Reflector'.
[Wikipedia sources here and here]
This project has two strands, a software and a hardware component. The aim is to build a device which responds to earthquakes being reported in near-real time via the USGS RSS feeds. The device responds by illustrating the magnitude of the reported earthquake via two fairly chunky vibration motors of the kind used in video game controllers. The device is connected to a PC via a virtual com port over USB (thanks to an on board Arduino). On the PC, an application sits there checking the RSS feed periodically and when a new event it posted to the RSS feed, the desktop app parses the data out of it and presents the magnitude of the quake to the Arduino which interpreters this as rate at which to activate the vibration motors.
[Images below from Boston.com Big Picture and USGS]
Step 1: Gather the Parts
First you will need a Computer, connected to the internet. It helps if this is a computer that you use (or is just on) pretty much all the time, I use my work computer, but if you have a media centre PC or home server, that would be ideal. Onto this PC you need to load the "Processing" Environment, which you can download here.
Download Processing from http://www.processing.org
Next, you will need to download the program that I've written to read the USGS feeds. You can find this at the bottom of the page here. This is loaded into the Processing IDE and run. You will need to make one change to it, change the reference to "COM6" to be whatever COM port your computer uses to talk to an Arduino.
Speaking of Arduino's, the next requirement is for an Arduino of some kind. In this project I used a Boarduino from Adafruit, because they rock. They are also very easy to use with breadboards.
Learn more about Arduino
Learn more about Boarduino
Speaking of breadboards, I'd advise you use one to build this project with at the start, unless you are super-cool and want to dive straight into PCB fabrication, or some kind of rats-nest stylee. I've used a breadboard thorough this project as you'll see from the photos.
Next you will need some components. Other than the Arduino, perhaps the biggest things going here are the vibration motors. I used vibration motors out of a playstation dual -shock controller which are probably rated about 5v although I'm guessing here. You can use anything you can get your hands on, but it should be able to fling itself around a bit, so you probably need something bigger than a pager motor. Most game controllers, including the Playstation dual-shocks have both a low frequency motor with a big weight on, and a high frequency motor with a small weight. This is useful for us as it creates a nice organic feeling vibration when they are both used together.
Powering motors straight from arduino pins looks like it should work, but actually it's really bad. You can fry your pin very easily, so don't do it kids. If you have some kind of H-Bridge lying around then you can do that, or just use some transistor based setup to take the current load away from the pin, and prevent current flowing back. I learned how to do this from the excellent ITP resource on controling high current loads with transistors.
Learn more about using transistors to control motors at ITP
I've used two motors so I've built two independent circuits to control them via PWM from arduino pins. If you only have one motor, or more then you will need to duplicate the components for each motor you want to drive.
For each motor circuit I used:
1x TIP120 transistor (NPN) (datasheet)
1x 1k Ohm resistor
1x Power Diode
some interconnecting wire
You can see the circuit diagram for this, and a more detailed parts list at the ITP page that I linked to above, I can't tell you what a cool resource ITP is.
In my code, I'm using pins 9 and 10 on the arduino, but you can change the code to use whichever (PWM) pins you like.
Step 2: The Software
The role of this software is to check the USGS 1day Earthquake RSS feed and trigger an event if a new entry is added to the list. Right now the app checks the feed every 30 seconds which I think is probably a bit too often, but you can modify that if needed.
If a new event is added to the Feed and the app finds this, it sends a packet to the hardware containing the magnitude of the earthquake. The hardware takes over at this point and knows how to respond to different strengths. The app also has the ability to play an audible alert (which I've set to be an WW2 air raid siren) when a new earthquake is posted.
A row of buttons at the bottom of the application allows for a certain degree of configuration and testing, but it's not exactly a complex interface.
It would be great if I could get the processing app to sit in the system tray on a PC, perhaps someone knows how to do that. I know you can get Third party apps that minimise other applications to the tray, but that seems like cheating. It's also a good size to be a Vista or Win7 widget, so if anyone wants to take the code and run with it, be my guest!
The attached zip file is the latest version of the code. The connect button does not show the correct behaviour yet, although it should work (as long as you've changed the COM port to reflect what is used in your set-up). This release of the software also includes the Air Raid siren which I downloaded from the very excellent Freesound.org (link to sample is here). Future releases won't have this sample included in the zip due to the file size, so grab it while it's hot!
There are doubtless a few bugs in this code, I've not tested it too well, but If you have problems with it, then leave a comment and I'll do my best to respond. I want to give a shout out to Bruno Nadeau, the author of the RomeFeeder Lib for Processing (link) who helped me get the USGS feed working. Please check Bruno's site for the latest versions of the library. (you will need this to compile the app)
Step 3: The Arduino Firmware
Have a look at the attached .PDE, I've commented the code but if there is anything that you don't understand I'll try and answer it in the comments. I'm not sure about all the map() stuff, I think I'll need to review that in a later release!
There are certainly more things I'd like to do with this code. For a start there should be much more 'interesting' ways of creating the vibration profile. Right now it's as simple as it could be, the magnitude that is passed in is used both to determine the value to pass out of the PWM pins (how fast the motors spin) and the length they spin for. A much more sophisticated function could be used that pulses the motors along a simulation of an actual seismic waveform. This would produce the 'organic' feeling that I've been aiming for.
Step 4: Putting It All Together, Final Thoughts
The reason I'll be doing this as a next step is that I'm also planning on ditching USB both as a means of power, and serial. Instead I'll be powering the device from batteries (4xAA cells most likely) and using Xbee's for a wireless serial link. This will achieve the ambition of having the device as a stand alone object, not seemingly thethered. I'll have to find a nice enclosure for it too.
Finally, I'd just like to stress that this project is about empathising in some small way with victims of earthquakes. I'm not trying to make light of peoples anguish or suffering, and I'm not trying to play on peoples fears of an impending "big one". I do not experience many earthquakes where I live, but I know a lot of people around the world (specifically around the Med and the Pacific) do. This is my attempt to understand that feeling a bit better. Thanks for reading!