The Happy Crabby

Nov 4, 2012 • alan


In 2009, we got a hermit crab named “Peek-a-boo”. We kept him in a plastic shoebox-sized container with creek sand in the bottom and holes drilled in the lid. He seemed to enjoy his new home, and we enjoyed his company. But some time in the winter, he died.

This turned into an annual tradition. Peek-a-boo was followed by Boo and Sprinkle in 2010, Flicker in 2011, and Blink and Barney in 2012. Some of our crabs only stayed with us a short while; others lived through the winter, but not much longer.

I wanted to know how we could take better care of them, so in 2011, we replaced the plastic box with a small glass terrarium with a glass lid. I suspected that they were getting too cold in the winter, but when I read about crabs, I found that humidity might have been a factor. I know our house gets very dry in the winter.

Oregon Scientific hygrometer

Oregon Scientific hygrometer

It was time to find measure the temperature and humidity inside the cage.

I thought about buying a simple hygrometer. We have one in our hallway . But I wanted to keep a long-running log of temperature and humidity over time.

So I decided to build an Arduino-based crab cage monitor.

The Happy Crabby

I would use an Arduino UNO to control the overall flow. I wanted to add the following peripherals:

SHT11 temperature/humidity sensor

Drivers

The first thing I had to do was write some software to read the temperature and humidity from the SHT11 board. The documentation claimed that it was an I2C device, which should have made it very easy. I knew all about I2C from when I worked at Ericsson. A lot of peripherals used an I2C interface. It’s a simple two-wire protocol where you can just wiggle two output lines in a specific order to send signals to the devices. It turns out that the SHT11 is mostly I2C, but it has a strange quirk that I had to code around.

Hardware Planning

After I was receiving real temperature and humidity readings from the SHT11, I had to start allocating Arduino I/O pins to the peripherals. I made a spreadsheet to keep track of the pins. Some pins on the Arduino have special alternate uses, so I made a note of them there. Since I was working on a prototyping board, I kept changing stuff, and when I did I’d just create a new spreadsheet column. In some configurations, I did not have enough pins… specifically, if I did not use the I2C-to-LCD board, I had to allocate most of my pins to simply driving the LCD display. In other configurations, I had plenty of pins left over.

What I ended up with was this:

PIN FEATURES MY USE
D0 RX serial (future: for Bluetooth)
D1 TX serial (future: for Bluetooth)
D2 relay (future: to control a relay)
D3 PWM
D4
D5 PWM
D6 PWM
D7
D8 bit-banged I2C-SDA for T/H
D9 PWM bit-banged I2C-SCK for T/H
D10 PWM or SPI-SS SPI-SS for SD card
D11 PWM or SPI-MOSI SPI-MOSI for SD card
D12 SPI-MISO SPI-MISO for SD card
D13 LED, SPI-SCK SPI-SCK for SD card
A0 (future) keyboard
A1
A2
A3
A4 SDA I2C-SDA for RTC and LCD
A5 SCK I2C-SCK for RTC and LCD

Software and Integration

I wrote a simple program that takes a temperature and humidity reading, reads the current time, appends a line to a CSV file on the SD card, and updates the LCD display. Then it sleeps for a minute and does it all over again.

For a long while, we ran the Happy Crabby on the prototype board, with wires hanging out all over.

prototype

The Happy Crabby.

LCD

The display, up close.

What we learned

We ran in this configuration for a long time. We had been thinking that we would eventually add a relay to control either a heat lamp or a terrarium heater pad. But after taking measurements for several months, we decided that temperature was nearly as much of a problem in our house as humidity.

So we kept an eye on the humidity and we rearranged the inside of the cage, dumping a few inches of moist sand into the bottom. They like to dig tunnels and hide, especially when they are molting. Overall, they seem to be healthier now that the cage is not so dry, and they are less stressed because they have a place to hide.

Almost a year after we originally started taking measurements, we decided that our design was OK enough to make “permanent”. So we bought a “shield” board and soldered all of the pieces down. I made sure that all of the pieces still plug together, in case we feel like changing it down the road. It looks a little nicer without all of the rats nest of wires, and it’s a lot less likely to get messed up if somebody bumps it.

boards

The component boards.

assembled

Fully assembled.

Resources

Source code that we wrote for this project can be found on github.