Tracking hamster activity with a Raspberry Pi

Raspberry Pi answers: Are my hamsters lazy or super athletes?

Posted 28 Oct 2015 by 

up
55 readers like this
Gadgets and open hardware
Image by : 

opensource.com

Last year, I brought two new Roborovski hamster pups into our home. They looked identical at the time, so I named them both Hamtaro. (Fast forward the 1.5 years I've owned them, and one has grown significantly tubbier than the other... So I've nicknamed her Hamtaro Grande.)

After having the Hamtaros home for about a week, one thing became extremely clear@mdash;they run all the time. At least, that's how it feels when I'm trying to sleep through their squeaky wheel.

That's Hamtaro on the wheel, and Grande on the ground

Curiosity led me to start researching my hamsters on the Internet. Confirming my suspicion, I read that Roborovski hamsters in particular are one of the most active hamster breeds in the world, and run "an equivalent of four human marathons each night on average." So, it got me wondering: Could it be possible that my Roborovski hamsters are really running the hamster equivalent of four marathons a night? And if they are, what does that even mean? I mean, what even is the "hamster equivalent" of a marathon? With these questions in mind, I decided to put my hamsters to the test with some citizen science.

Here's how it works

Mod the hamster wheel to allow for safe tracking

Luckily, I had already done the work to mod my wheel back in January. Back then, I had two goals in mind:

  1. Silencing the incessant squeaking of constant running that was keeping me up at night. (The ball bearings that are designed to play a video tape smoothly allow for relatively frictionless—and therefore nearly silent—rotation.)
  2. Provide a surface external to the cage to attach other apparatuses safely outside of hamster reach. (The VCR head has an axle that can reach through the cage bars, allowing me to mount the head itself to the outside of the cage.)

You can see detailed instructions on how to mod your own hamster wheel here.

Build a device to record hamster data

The hamstrometer itself is essentially just an ethernet-connected pedometer. I'm a huge fan of recycling and open source, so I made a personal choice to opt for open source solutions and recycled parts in my design whenever possible. If you want to build you own hamstrometer, you can download the Fritzing model for this circuit on my GitHub.

Here's my parts list:

  • Raspberry Pi
  • Raspberry Pi peripherals (in an effort to cut down on waste, I got all of mine second-hand out of the CRASH Space junk bins): monitor, mouse, ethernet cable, HDMI cable, power cord (taken from an old modem), USB cord
  • Sticky-backed breadboard
  • Hall effect sensor
  • Rare earth magnet
  • LED (Optional: for notification and debugging)
  • Jumper wires

The primary functionality in the circuit is happening between the rare-earth magnet and the hall effect sensor. Hall effect sensors sense the presence of a magnetic field, and are therefore capable of counting rotations once we have mounted the rare-earth magnet to the rotating portion of the VCR head on our hamster wheel.

Notice the magnet stuck to the wheel, spinning past the sensor on the circuit

The logging of our rotation data and any additional calculation is handled by the Raspberry Pi. After observing my hamsters' behavior, I determined that they generally tend to wander on and off of the wheel several times within a very short timespan. Because of this, I decided to record their data in "sprints." Whenever the sensor senses the presence of the magnet, it considers this to be the start of a new sprint. Each consecutive time it senses the magnet after that initial pass, it logs the current timestamp. The sensor will continue to record as long as it senses the magnet. If five seconds go by without any activity, it terminates the sprint and logs the sprint data to a SQLite database.

Measure and calculate distances

The claim made by the Internet is that my hamsters run, on average, the equivalent of four marathons a night. So to determine whether this is true, we first have to ask ourselves: What is the "hamster equivalent" of four human marathons?

To determine this, I decided it would be fair to assume that if it takes a human X human-sized strides to run a human-sized marathon, then it must therefore take a hamster X hamster-sized strides to run a "hamster marathon."

To solve this problem, I had to answer a few other questions first:

Q: How far does a hamster run in one wheel rotation?

The hamstrometer is recording rotations of the wheel, so we need to ensure that we are converting properly between wheel rotations and feet.

I measured the diameter of my hamster wheel, and it is 0.5 ft.

0.5 ft X PI = ~1.5 ft

A: The distance a hamster runs in one wheel rotation is 1.5 ft

Q: How long is the average human stride?

Luckily, this data is readily available all over the Internet. I chose to go with the value of 2.2 ft, as that was quoted as being the average female human's stride length, and my hamsters are ladies.

A: The average female human stride length is 2.2 ft.

Q: How long is the average Roborovski hamster stride?

This one was a bit harder to figure out. The internet appears to have significantly less data on the average stride of a female Roborovski hamster just lying around for the taking.

I started crafting ideas for tests, and threw a few of them out on Twitter to see whether any would stick. The community was full of suggestions! We all chatted back and forth about the pros and cons of the various ideas, how much work they would require, how accurate they might be, and how irritated my hamsters might be by the whole ordeal.

Then one of us came up with the perfect idea:

Brilliant!

This would enable us not only to see the steps the hamsters took very clearly, but is also unobtrusive to the hamsters' normal lifestyle.

Luckily, the bottom of my hamster cage is translucent plastic, so an extra pane of glass wasn't necessary. With a ruler, a pen, and some tape, I graphed and labeled the

WORLD'S MOST SOPHISTICATED HAMSTER STRIDE MEASUREMENT SYSTEM!

And voila! After filming them and playing the footage back in slow-mo, I was able to get several measurements of hamster strides, and take the average.

Photo by Michelle Leonhart. CC BY-SA 4.0

A: The average stride length of my Roborovski hamsters is 0.166 ft.

Q: How many human strides are in one mile?

(5,280 ft / mile) * (1 human stride / 2.2 ft) = 2,400 human strides / mile

A: There are 2,400 human strides in one mile.

Q: How far does a hamster travel in 2,400 strides?

(0.166 ft / hamster stride) * (2,400 strides / mile) = 400 ft / hamster mile

A: A hamster travels 400 ft in one mile.

Q: How long is four hamster marathons?

(400 ft / hamster mile) * (26.2 miles / marathon) = 10,487 ft / hamster marathons

(10,487 ft / hamster marathon) * (4 marathons) = 41,950 ft / four hamster marathons

A: Four hamster marathons is 41,950 ft long.

Upload and track the data

I've been using ThingSpeak to host my data. ThingSpeak is an affordable and open source platform for hosting your IoT data. There is an API you can plug directly in to your project to upload your data, generate CSV files, and graph your data in near real time. You can watch my hamsters' live data here on my website.

The code I wrote for this project is in Python, with the exception of the database and tables, which are supported by SQLite. You can find the code I wrote for this project here on Github, available under the GPL-3.0 license.

Analyzing the data

I tracked my hamster's activity for one month straight, and (spoiler alert):

Not one time did they make the cut.

Photo by Michelle Leonhart. CC BY-SA 4.0

Wow.

Perhaps this is because my hamsters are getting old? Perhaps domesticated Roborovskis don't perform as well as they do in the wild? Or maybe mine are just ...really lazy? OR MAYBE THE INTERNET WAS LYING ALL ALONG?!?

But really, I probably shouldn't be so disappointed that they didn't make the four marathons a day marker. They're averaging between one and two hamster marathons a day, which translates to between two and five human miles a day. Those are pretty impressive numbers for a creature that maxes out at about two inches long.

Github | GPL-3.0 license

12 Comments

Davide Repetto

From what I see in the picture you may have measured the "wrong stride".
Shouldn't stride be the distance between two paired legs while walking and not , as you measured, the distant between the front and and the back ones?
Well, if I'm right, then the actual stride is probably about half your measurement and thus the 4 marathons may still be within your hamster-ladies grasp...

Vote up!
0
Vote down!
0
mleonhart

The stride measurement is calculated as the distance between the initial location of a single foot and the final location of that same foot after a single step. I think your confusion is because in the image, the front portion of the hamster's right paw is coincidentally near what was the final location of the back of the hamster's rear paw, which is the paw being measured in the image.

Vote up!
0
Vote down!
0
Onan the Barbarian

The value of 2.2ft (66cm in metric units) for a human stride looks like the distance between the location of one foot and that of the other foot, that is, half of your definition of stride.
I also guess that's the stride length when one is walking. When running, the stride is significantly longer.
Combining these two effects together, you're probably overestimating the number of strides in a marathon by a factor of three or four.

Vote up!
0
Vote down!
0
sethkenlon

Strangely captivating article! Surely the next step can only be to power the Pi via the Hamster wheel (but possibly several additional hamsters, since yours are, apparently, sadly lazy).

Vote up!
1
Vote down!
0
Don Watkins

I love it! Great article.

Vote up!
1
Vote down!
0
bbehrens

This is the kind of article that makes me so happy Opensource.com exists. Awesome job, Michelle.

Vote up!
1
Vote down!
0
mleonhart

Thank you!

Vote up!
0
Vote down!
0
CFWhitman

I know for things like this they often use body length as the comparator. That is, instead of stride length, they might use the ratio of the average height of a person to distance run in a marathon compared to the ratio of average length of the hamster to distance run. Of course for an animal with a significant tail, the tail would not be included, but hamsters don't really have a significant tail.

Vote up!
0
Vote down!
0
JustNiz

Since you apparently have multiple hamsters in the same cage, you don't know if they are both equally active or if only one is doing most of the work.
You could tag them with unique rfid chips and put an rfid reader near the wheel to be able to tell which hamster is currently using it,

It would have been super cool if you could have actually powered the Pi from the hamster wheel too!

Vote up!
0
Vote down!
0
L

If one hamster is fatter than the other, it is probable that it is slower too. Maybe she could tell the hamsters apart from the average rotation speed. Of course, it is less reliable, may mix up data if one hamster gets out and the other gets in quickly, which is probably happening now with the 5 second timer for stride end... but uses less material.

Vote up!
0
Vote down!
0
Shazin

Great work. I have one question why did you want to measure the stride length of the hamster. What's wrong with calculating the Parameter of the rotating wheel and measuring the rotations and calculating the distance the hamster have run?

Vote up!
0
Vote down!
0
lauren.egts

This is a really cool article! I'd do this with my guinea pig except she only moves when bribed with food.

Vote up!
0
Vote down!
0

Hi! I'm Michelle Leonhart, a Los Angeles-based software engineer. When not coding for work or fun, you can find me co-running the hackerspace CRASH Space: a non-profit organization aimed at the proliferation of STEAM* education, which I feel very passionate about.

In the past, I've worked with the MythBusters on the Discovery Channel, lectured at the university level, coached an all-girls FIRST Robotics team, and designed and taught a number of classes in programming and electronics