You are currently browsing John McCombs’s articles.

This was a quick weekend project, inspired by some YouTube videos.


Three small servos, stuck together with double-sided tape, form the body of the bot. Two servos point upwards and the centre one points forwards. Hot-glue connects the galvanised wire legs to the servo horns. The parts are small, so use a small hot-glue gun if you have one. Hot-glue and double-sided tape are strong enough for the bot, but not so strong that the parts can’t be disassembled and re-used.

The robot walks by pushing the middle leg down on one side, then using the servo on the opposite side to swing the body of the robot forwards. The servo on the near side also rotates in the same direction at the same time, so as to be in position for the next step.

To turn the bot, the top servos are rotated in opposite directions during each half cycle.

A standard Arduino is far too big for this bot, however, an Arduino Pro Mini is smaller than the back of the bot (18mm x 33mm). The Pro Mini is a full featured Arduino, but without the USB interface. To program this board you also need an FTDI adapter like the Sparkfun FTDI breakout. There is no connector on the Arduino, but you can just hold the header pins on the FTDI breakout against the holes along the end of the Arduino.

The Arduino Pro Mini I had was the 5V version. Lacking a boost converter to turn the 3.7V battery into 5V, I tried wiring the battery directly to the Arduino and everything worked. The 110mAh battery I used is tiny and fits underneath the bot.

An infra-red LED and infra-red photo-transistor form the obstacle detector. The photo-transistor is wired with its emitter to ground and its collector to Vcc, via a 5.5k resistor. The Arduino measures the voltage across the photo-transistor. There is a fair amount of ambient infra-red light, so the bot measures the voltage on the photo-transistor with the LED turned off, then again with it turned on. If the voltages are much different, it’s time to turn. In a sunlit room, a black paper tube to shield the sides of the photo-transistor will make detection more reliable.


If you live in New Zealand MindKits and Nicegear are good sources for this stuff.

The Arduino sketch can be downloaded from or cloned from the bitbucket repo


As previously noted, we’ve had a few earthquakes. A feature of the period after a large quake is that there are many aftershocks. The name aftershock gives the wrong idea. Aftershock means earthquake and we have had over 7000, up to magnitude 6.3, close to our city.

The frequent occurrence of  nearby aftershocks was an opportunity to get some measurements of our own and learn more about seismology and what was happening under our city.

Here’s a magnitude 5.4 quake that we captured in the evening of 21 June. The quake was centred about 12km away.

The three graphs show the ground acceleration in all three dimensions. The Y-axis is north-south and the Z-axis is vertical acceleration. The units of acceleration are expressed as a percentage of Earth’s gravity. The peak acceleration we experienced in this quake was about 9%g, about 880mm/s2.

Looking at the Z-axis graph, you can clearly see the higher frequency P-wave, arrive just over a second before the lower frequency S-wave. The difference in propagation speed between the P and S waves is about 8km/s.

I used a Fourier transform to extract the constituent frequencies of the shaking, from the accelerometer data. The top graph shows strong peaks in the three to five Hertz range for the S-wave. The P-wave around 20Hz is clear in the Z-axis plot.

Fourier transform - x-axis

Fourier transform - z-axis

You can see the accelerations at other points in the city on the shaking map on the GeoNet website. First zoom in the central Christchurch, then select PGA from the Add Instrument Shaking drop-down menu. Put your mouse over the square icons to see the ground acceleration. Close to the quake, the accelerations reached 60%g, strong enough to cause damage.

How was it done

There are many designs for amateur seismographs. The best known are from Scientific American articles, Lehman seismograph from 1979 and the Shackleford-Gundersen design from 1975. Both these instruments involve a fair amount of mechanical fabrication and electronics.

So to get something working quickly we used a Bosch micro-machined accelerometer chip, which which can record nearby quakes with strong ground acceleration, i.e. like those we have been experiencing. This type of instrument is classed as a strong motion accelerograph.

The instrument is built around an Arduino Mega2560, using microSD storage. A ChronoDot provides timekeeping. An LCD display and a couple of LED’s provide status information.


The Bosch BMA180 has the best performance of all the devices I tried. It is a digital sensor with a high sample rate, SPI and I2C interfaces and built-in low-pass filters. The seventy page datasheet is a little intimidating.

I also tried a Freescale MMA7260Q and Analog Devices ADXL345 accelerometers. Both devices had lower sample rates and higher noise floors than the Bosch device. The ADXL345 would be adequate for this application. These sensors are all MEMS technology.

The BMA180 is powered from the Arduino 3.3V pin and connected directly to the I2C pins (pins 20 and 21).

The program uses a timer to trigger an interrupt to read the accelerometer at regular intervals. A sample rate of 200Hz is more than adequate for seismic signals, which are below 20-30Hz.

The main limitation of MEMS accelerometers is the noise level. A magnitude 3.7 quake within about 15km is the lower limit for getting a good signal.

Data capture

 The original plan was to transmit the data direct to a PC, via ethernet. However, given that mains power failures often accompany stronger quakes, this perhaps wasn’t the best possible solution.

The Arduino Ethernet shield also has built-in microSD card slot. This can easily write the accelerometer data to the microSD card faster than it is captured.

When an event is detected the data in the ring buffer is written to the microSD card and the program keeps writing for several seconds after the end of the event.

A ring buffer is a common pattern for capturing data. Readings are added to the end of the buffer until it is full. At that point the oldest reading is overwritten. In this program, the accelerometer is read continuously and data is stored in a ring buffer 399 points long. When an event is triggered the main program loop writes data from the buffer to the microSD card, as long as the recording continues. A standard Arduino doesn’t have enough RAM for this size ring buffer, hence the Mega2560.

Using a ring buffer with a timer ensures that the samples are read at even intervals regardless of the timing of writing data to the microSD card. Since there are already 399 samples in the buffer at the start of the event, the recording includes data for two seconds before the event was detected.

A series of consecutive readings above the noise threshold triggers recording and it continues for several seconds after the signal drops below the threshold. Once the event is complete, the file is closed and another one opened.


When there is a powerful earthquake the electrical power distribution system shuts down to protect itself. Battery backup ensures continuous recording even if mains power fails.

The Sparkfun combination LiPoly charger and boost converter makes this easy. The board supplies power to the instrument and charges the LiPoly battery. If the power fails, the boost converter on the board supplies regulated 5V to the Arduino board. Power is wired directly to the 5V pin on the Arduino.

The 1200 mAh battery can run the unit for 5-6 hours. More if the LCD backlight is disconnected.

Data Processing

I used Microsoft Excel to process the comma-delimited text files from the microSD cards and make the graphs. The Excel Analysis Toolpack includes a Fast Fourier Transform function.

More things to try

  • look for ways of reducing accelerometer noise
  • add web server to the instrument to remotely read status and download data
  • automated processing
  • alternate sensors, e.g a geophone or one of the designs from Scientific American


The Arduino sketch can be downloaded, or cloned from the bitbucket repository

The Arduino is a great tool for investigating the world. We often build gadgets to measure something. An Arduino can measure time and voltage, interface with a huge array of I2C and SPI digital sensors and connect to computers and the Internet.

Compressing or expanding time is a recurring theme. Capturing data from very fast or slow events and then displaying it at human scale.

We had a problem getting the temperature in the fridge right. A few degrees too cold and the food freezes. To warm and the life of items like dairy suffers. Here’s a gadget we built to make some measurements. A protoshield with a breadboard is sandwiched between the Ardiuno and the LCD on top.

It measures the temperature every few seconds and plots a graph on the LCD so you can see what happens over the course of the day.

The Dallas DS18B20 is a favourite.  It’s a digital thermometer with 0.5 degree accuracy which communicates over a 1-Wire bus. You can connect a bunch of these to the same set of three wires – each sensor has it own address that you use to read the value.

The LCD shield in the gadget is home-made and gets used a lot. It’s built from a ST7565 LCD, nylon standoffs, rubber bands and an Adafruit protoshield. A 4050 level shifter is required to convert the 5V Arduino logic to the 3.3V required by the display. The result is a shield that’s easy to use for basic data visualisation.

For this type of application, you want to use a display with a serial interface, rather than parallel. The ST7565 uses 4 or 5 pins. The more common KS0108 LCD’s uses 13 or 14 pins, which leaves very few pins for your project. Adafruit also have an SPI LCD that would be good for general use.

Here’s the result. The graph shows the temperature in our freezer over several hours. The freezer is self defrosting. You can see it rapidly drives the air temperature in the compartment to just above zero to melt the surface ice. Then the cooling cycle starts and the melted surface ice evaporates and condenses on the freezer coils. However, most of the time the freezer compartment is below -20 degrees C.

We also used the gadget to adjust the refrigerator temperature so that it was as cold as possible, without ever approaching freezing.

Arduino source code is here or in the repository.

Flickr Photos

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

%d bloggers like this: