In 2011, someone was vandalizing my bike. They would flatten my tires and mess up the seat almost every day. The bike was stored just inside the building, but there was no cameras inside. However, there was a card reader and a camera just outside the door. I figured I could make a device to detect when my bike was being abused, log the time, and compare that to camera and card access logs at the office.
Since the task was relatively simple, I decided to use this as an opportunity to try out the Arduino. I got an Arduino Uno and a ADXL335 accelerometer breakout board from SparkFun, added some LED's, batteries and switches, wrote a little software and came up with a nifty little device.
The device is powered by a 9V battery. When it is turned on, it blinks an LED and waits. At this time, a serial control interface is active. You can send it a 'p' to print the time log from memory, a 'c' to clear the log, or a 't' to print the current time. However, the device is waiting for you to send it the current 10 digit Unix time. When the device is turned off, it looses all power and is unable to maintian the time, so you have to send it the time. Once the time is sent to it, the device will blink another LED and wait for a switch to be pressed. When the switch is activated, the device takes a “baseline” reading of the accelerometer and then becomes “armed”.
In the “armed” state, the device will poll the accelerometer once a second. It compares the current values to the baseline, and when they exceed a certain threshold, the device considers this “motion”. It will then write the 4-byte unix time to the flash EEPROM. No other data is stored, just the time. Later, this time data can be printed over the serial interface.
Although this specific device has pretty limited use, it was a fun project to see some of the Arduino's capabilities. The code has some elements that could be used in other projects:
In the end, I never caught the person who was vandalizing my bike. Once I put the device on my bike, they no longer vandalized it.
I thought of a few things to add if I ever wanted to develop this device further. First, there needs to be some power management implemented because the 9V battery is drained within a few days. Second, I bought a Real Time Clock module which could be used to remember the time. This would eliminate the need to send the time everytime the device is turned on. But for now, I accomplished what I set out to complete.