Track How Far Your Hamster Runs




Have you ever wondered how far your hamster runs each day? Most hamsters (like mine) love their wheels. What if there was a way to track how far your hamster ran in its wheel? Well there is! And all you'll need are a few dollars in parts that you can pick up at a hardware and electronics store and a computer. Follow this Instructable and you'll be tracking your hamster in no time!

Step 1: Get a Hamster and a Wheel

If you don't already have one get (1) hamster and (1) hamster wheel. I got a Syrian hamster named Lizzie and a "Wodent Wheel". Apparently this type of wheel is better for her back because of the relatively large radius.

Step 2: Gather Materials

Here's the list of things you'll need:

1. DB9 Female DSUB Solder Connector
This should plug into the serial port on your computer. There are a number of different types of these connectors but the cheap variety that you can get at your local electronics store should be sufficient. They even make non solder varieties if you want (but I would recommend just learning how to solder).

2. Magnetic Contact Switch
The easiest way to get one of these is to use one that's meant for windows in a home security system. It is important to get one that is "normally closed" so that when you bring a magnet nearby it "closes" and allows current to flow between the screws. Note that they have versions that do both "normally closed" and "normally open" (as mine below) which will have three screws.

Please don't take one off your house. In general I found I had to go to an electronics store like Fry's Electronics to find these. They didn't have them at the Home Depot I checked. These are also available online at

3. Magnets
You'll need a magnet to set off the contact switch every time the wheel goes around. Two magnets are ideal since you can put them on other side of the wheel and secure them without any glue or tape (better for the hamster). I used hard drive magnets because they're strong (neodymium rare earth metal magnets) and I happened to have a few laying around.

4. Switch Mounting Supplies
I used zip ties a pen (with the ink removed of course) and hot glue to fasten the switch securly and out of reach of the hamster. More details on this in later steps.

Step 3: Gather Tools

You'll need a couple standard tools for this project.

1. Soldering Iron (and some solder of course)
2. Wire Cutters
3. Multimeter (to check your solder joints)
4. Helping hands (to hold the wire while you solder)
5. Glue Gun (to keep everything together)

If you really want, you can probably do without the multimeter and the helping hands. However, if you're on this site you could probably find significant use from these later.

If you don't yet know, I would suggest learning how to solder.

Step 4: Choose Some Wire

The choice of wire for this project is important. No matter where you put the wire assume that your hamster will be able to reach it and therefore chew on it. As a result it is necessary to use fairly thick wire. I suggest 14 or 12 gauge solid electrical wire that you can buy at your local hardware store.

During my first iteration of this project the hamster chewed through my shoddily protected, thin wire a number of times before I switched to the heavy gauge wire. Now the hamster has managed to strip each wire but since the copper is so thick (like the bars of a cage) the system still works. Don't worry, the voltage going through these wires is very low and the hamster is perfectly safe.

To solder the serial port connector to the wire it may be nice to get some significantly smaller gauge wire to act as an intermediary. I cannibalized an Ethernet cable for this purpose.

Step 5: Assemble the Sensor

The next step is to put the contact switch on the mount and attach the wires to it. A large part of how this looks will depend on what you contact switch looks like and how you're attaching the switch to the wheel.

If you're using the same materials as me you can use the zip ties combined with some hot glue to attach the the contact switch to the pen case. Once the switch is secured to the pen, attach the wires using the screws.

Step 6: Choose the Right Contacts

If your switch has three terminals make sure to pick the one that indicates normally closed. On the contact switch I used there was a diagram on the other side that showed which terminal was which.

Step 7: Solder the Serial Port Connector

Now attach the smaller gauge wires to the large wires and solder them to the serial port connector. You'll need to solder the wires to pins 4 and 6. Since we're just completing a circuit, it doesn't matter which wire goes to which pin just make sure you get 4 and 6. The connector you get will be labeled with the pin numbers and you can also see which pins you need to attach to below.

Pin 4 on a serial port is also known as "DTR" or Data Terminal Ready. Pin 6 is also known as "DSR" or Data Set Ready. When we write our program we'll be able to set DSR to +5V and check if DTR is +5V. As a result we will be able to determine whether or not the magnet is over the switch. And if we check very quickly then we'll be able to figure out how often and how quickly the wheel turns to determine both number of rotations and speed of each rotation.

Step 8: Measure Your Wheel

Since you're only measuring how many times the wheel has turned, you'll need to know the circumference of your wheel to get distance your hamster runs. In case you've forgotten your high school geometry, remember the equation

circumference = pi * diameter

Use Google to get the circumference into your favorite units of distance.

Step 9: Assemble the Wheel

Now you'll need to attach your sensor assembly to the wheel as well as attach the magnet. Here again I've used zip ties and hot glue to secure the pen casing to the wheel stand.

Make sure that when you attach the sensor assembly and the magnet that they are close enough for the switch to trigger but that the wheel still spins freely. Also ensure that the switch is facing the correct direction. When you purchase the contact switch, many times they will specify the minimum distance to the magnet. If you use a stronger magnet (like a neodymium hard drive magnet) you may have a little more leeway.

If you listen carefully you can usually hear a click every time the wheel goes around. If you don't hear that click it might be worth checking your switch / magnet configuration to ensure everything is aligned correctly.

Step 10: Install the Wheel

Now that you've completed the wheel, its time to install it. Place it in the cage and connect the connector to a free serial port on your computer. I used a serial port extension cable since the cable I made was too short to reach my computer on the floor.

If your computer is too new to have a serial port you can buy one for cheap on Amazon or at your local electronics store. If you're running some variety of Linux or Mac I would recommend this one from Keyspan that will work well.

Step 11: Write the Program

Now remember that we've connected DTR (pin 4) to DSR (pin 6) on the serial port through a switch that is activated every time the hamster runs once around the wheel. We can write a pretty quick program in Python that will let us set DTR and monitor DSR for when the switch is activated.

Note that I've chosen Python in this tutorial since its pretty easy to learn and use. If you're comfortable with another language and it has a library for accessing the serial port, I would suggest going with that as it will give you more flexibility with what you want to do later.

Assuming you're using Python you'll need to install a couple of things
- Python : Follow the instructions for installation on the type of system you will be using. If you haven't had too much programming experience it might be worth running through a couple tutorials. However, I have provided some code listed below.
- pySerial : To access the pins on the serial port reference above you'll need to to install this library. This allows you to "import serial" so you can connect to the serial port.

Once you have these installed, here's some code you can use to record the distance your hamster runs. I've tried to comment it as thoroughly as possibly so even beginner programmers know what's going on.

In addition to recording and printing the distance every time the wheel turns, it will write the speed and time of each revolution to a file. If the program ever crashes then you can count the number of rows and multiply that number by the circumference. Once you've downloaded the script you can run the program from the command line like this and it will write each rotation of the wheel to "progress.txt".

python progress.txt



    • 1 Hour Challenge

      1 Hour Challenge
    • Colors of the Rainbow Contest

      Colors of the Rainbow Contest
    • Beauty Tips Contest

      Beauty Tips Contest

    75 Discussions


    1 year ago

    If I had one I would put the magnet on the outside of the wheel and the sensor under the cage. Maybe if I get another rat. If you use a permanent magnet motor as a bearing you could use the little guy to run a night light or charge your phone. Swap the solar panel in a garden light for a DC motor attached to the hamster wheel.


    2 years ago

    is it possible to program python to automatically record the number of rotations made in hourly intervals rather than distance travelled?


    10 years ago on Introduction

    You could also just buy a bike spedomiter and put it on the hamster wheel. You can get cheap ones for about $10. Nice instructable, though.

    16 replies

    Reply 10 years ago on Introduction

    You can usually just set them to the MM in width, and Mine can go down to 1 MM. THat would be a small wheel.


    Reply 10 years ago on Introduction

    My daughter and I got a bike speedometer to work with her hamster wheel without much trouble. The speedometer was set up so you could calibrate it to any wheel diameter using a little table. We were astounded to find that our hamster was running 5 to 8 miles a night!! At first we thought we had made a mistake, but we found a few people on the web with similar results. It worked great and was really easy and fun- the only thing we would change is that we we would add some kind of protection to the wires leading from the wheel to the speedometer - the hamster eventually got bored and chewed through.


    Reply 10 years ago on Introduction

    more... My post made it sound like our hamster died from chewing through the wires. It was fine. The wires don't carry much current; just a little signal from the wheel.


    Reply 10 years ago on Introduction

    Cool! I would do this with my guinea pig but she runs about 2 meters a week, so Im not so sure that it would be worth it. 8 miles! Thats a lot! Farther than I run... A lot farther.

    Your guinea pig should not have a wheel. Bad for thier back.. no hamster ball either while you're at it. And yes I know the package had a pic of a guinea pig on it. They are wrong.


    Reply 10 years ago on Introduction

    lol, probibly not faster... the hamster has all night to do it :P you may olny have a while :)


    Reply 10 years ago on Introduction

    small question: what speedometer did you use? i am trying to find a good one for my hamster wheel.


    Reply 10 years ago on Introduction

    It's been a while, so I'm not exactly sure. Judging from the pictures and prices of the different speedometer/odometers on Amazon, I'm pretty sure it was a "Bell SpinFit Calorie Bike Speedometer", which costs around $15.00.


    3 years ago

    This project is awesome! Very clear instructions from 0 to finish.

    Based on the data collected from my hamster (Maszat) I created a tiny webpage where I display his performance on the running wheel:

    Thanks for the instructions!