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 http://www.smarthome.com/7113.html.

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 hamster-serial.py progress.txt

<p>is it possible to program python to automatically record the number of rotations made in hourly intervals rather than distance travelled?</p>
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.
thats true too, although it may not work on such a small weel :o
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.
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.
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.
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.
lol, probibly not faster... the hamster has all night to do it :P you may olny have a while :)
True, but still...
lol :) pwnt me eh? :D
small question: what speedometer did you use? i am trying to find a good one for my hamster wheel.
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.
oh sweet thanks so much :)
good i thought he died lol
lol, okay :P u might be right, idk much about it ;)
Me neither. MY guinea pig is way too lazy to use a wheel...
thanks lol :)
<p>This project is awesome! Very clear instructions from 0 to finish.</p><p>Based on the data collected from my hamster (Maszat) I created a tiny webpage where I display his performance on the running wheel:</p><p><a href="http://www.zsygab.com/hamster" rel="nofollow">http://www.zsygab.com/hamster</a></p><p>Thanks for the instructions!</p>
Aaaahhhh :( The website doesn't exist.
Or you could measure the outside with a fabric (cloth) tape (ruler).
I am making something similar to this for my pet hedgehog. Instead of hooking it up to a computer, I'm going to use a calculator as described in this instructable:<br><br>https://www.instructables.com/id/Versatile-and-Low-Cost-Digital-Counter/?ALLSTEPS
no matter how thick your wire, do not let your hamster anywhere near it. that's very important.
could the magnets kill your hamster
No, magnets will not hurt a hamster. The fields used for MRI use magnetic fields that are much larger, and are used routinely in hospitals.
that makes me wonder about this project... hmm...
Ummm...can&nbsp; you upload it somewhere else?<br />
like my hamster?
Looks like its ready to run!
shes not exactly the sort of hamster that will sit down and watch tv so ye she enjoys running
Oh man...if I ever get a hamster, I'm making one of these.
Does the python program run all the time on your comuter in the background? or do you start it at night and stop it in the morning? Also, won't writing a file every revolution wear down the harddisk? I've seen hamsters run in wheels and they pretty darn fast...
Yup, it runs continuously on my computer just in case she runs a little during the day as well. This won't really wear down a hard disk any faster than normal. While hamsters look fast to you and I, there are programs that write data much more quickly than the hamster can run.
it,s good
i see a dead hamster next to a chewed up wire.... uh ohs not good.
The wires are actually have incredibly little power going through them, only 5 V and about 10mA. That is way to low to cause any harm to hamster or person.
15 mA kills a human... -PKT
The key here is voltage. If the current cannot flow then it is harmless. If you touch any of the ports on the back of your computer 5v is what you'r touching. That's what's going through these wires.
Great idea and nice job presenting!
prettty difficult to me... nice project. i wonder how far my hamster can run
Can you just give me the compiled EXE instead of me having to do it from scratch?
So this can determine the RPM's of a spinning object? I think i just sparked an idea...
This is so cool - I really want to do this but am failing when it comes to the writing programme bit... I know its cheating but does anyone know where I can download these? or get a step by step how to set this bit up? Please help....
Very cool ible. You may want to consider counter-weighting the magnets... to Lizzie, the difference could be enormous (imagine running over a thousand little hills).
That's a good point. Very unscientifically we figured it wasn't too much of an issue since the friction inherent in the wheel and caused by the bedding she stuffs under it meant the magnet doesn't cause the wheel to turn on its own. However, I wonder if there's better way to measure this as well as how much this added friction affects how far she can run.
I wonder if she purposely stuffs the bedding under the wheel to increase the turning resistance for more exercise, the equivalent of running up a steady incline versus level ground. ??<br/>The off-balance caused by the magnet would still have an effect, tho disguised by the friction caused by the bedding, resulting in a likeness of running <em>up</em> a thousand little hills. Now, if only there was a way to measure the effect of this exercise. Sounds like a topic for another Ible.<br/>
This is a great project - really easy to do! I managed to put it all together and adjust the python file etc pretty easily!! I thought about doing the cycle computer, but it just isnt as cool as having it logged and uploading to the web automatically!<br/><br/>you can see my set up here:<br/><br/><a rel="nofollow" href="http://hamsterhike.co.uk/blog/?page_id=63">Hamster Hike</a><br/><br/>i've turned this into a website too with the blessing of the hamster across america guys!<br/>
Wodent Wheels makes (or used to make) a Wodometer to attach to their wheels
SWEET! have you ever calculated the top speed?
Yup just went through the data right now. Looks like her top speed is somewhere around 2.5 mph and she prefers to run at about 1.75 mph. Interestingly the graph how much time she spends at each speed is a pretty neat curve. <a rel="nofollow" href="http://www.int8.com/SpeedDistribution.jpg">Here's</a> a bigger version of the graph below.<br/><br/>

About This Instructable




More by dduke11:Track How Far Your Hamster Runs 
Add instructable to: