Monitoring the family pet - introducing the Hamster Tracker!

With the kids stuck at home due to the lockdown here in the UK, we’ve been doing some daft projects to keep their brains ticking over. Last week, we happened to purchase a new exercise wheel for the family hamster because he loves running at night, but the old one wasn’t very free running and he was clearly struggling to get up to maximum speed. This, of course, raised an interesting question…

Just how fast and how far does a hamster run?

After a bit of scribbling on the back of some unused schoolwork (hah!) we came up with a simple design, built around an ESP8266, SSD1306 display, A3144E hall effect sensor and some very powerful magnets:

First prototype, using a NodeMCU dev board to test the sensitivity of the hall-effect sensor (the 3-pin package at the front of the breadboard) - we had to swap for a different one to get a more reliable pickup:


We used a “bespoke sensor mount” (i.e. we raided the kids’ lego box and made extensive use of the hot glue gun :slight_smile:) to mount the hall-effect sensor and magnets to the hamster wheel itself:

First overnight run with the prototype - wow, he went much further than we expected!

Building the final version with a Wemos D1 mini so we can fit it into a smaller box:

Final version sat next to the prototype. (Still needs a bezel for the display!)

In terms of software, there’s nothing complicated - a bespoke Arduino sketch to run on the ESP8266 to capture the events from the wheel and calculate distance and speed, and send back to both Home Assistant via MQTT and IotPlotter via HTTP. In Home Assistant there’s are conventional sensors to wire this up:

- platform: mqtt
  name: "Hamster Cumulative Distance"
  state_topic: "hamstermonitor/data"
  unit_of_measurement: 'km'
  value_template: "{{ value_json.hamsterCumulativeDistanceKm }}"
  icon: "mdi:ruler"

- platform: mqtt
  name: "Hamster Speed"
  state_topic: "hamstermonitor/data"
  unit_of_measurement: 'km/h'
  value_template: "{{ '%.2f' | format(value_json.hamsterSpeedKph) }}"
  icon: "mdi:speedometer"

Due to the lack of RTC on the ESP8266, there is also a server-triggered event to reset the cumulative counters every day (ideally while the hamster is asleep!) so that we get a daily cumulative distance measure:

- id: 'reset_hamster_monitor'
  alias: 'Reset Hamster Monitor'
  trigger:
    platform: time
    at: "18:00:00"
  action:
    - service: mqtt.publish
      data:
        topic: "hamstermonitor/commands"
        payload: "{ resetCounter : 1 }"  

These sensors are then exposed on a tab within Home Assistant (also including the camera that sits and points at the hamster so we can see what he’s up to at night):


…and clicking through gives the history of his speed:

And of course we can’t finish without a picture of the hamster himself - say hello to Gus!

48 Likes

Crazy! :smiley:
I think that’s something for the Community Highlights.

11 Likes

This is “the most fun” waste of time I’ve ever seen.
I would love to have a dad like you when I was growing up.
:+1:

Though, I am concerned for the Gus’s civil liberties
:rofl:

4 Likes

With this you can start a worldwide hamster run competition! :rofl: You need to create a website with the world records and ranking list.

But do not give him any steroids to speed him up!

Great idea! :+1:

4 Likes

This would be a great write up for https://www.hackster.io/home-assistant/products/home-assistant

2 Likes

Why do that ? If you want to ‘cheat’ just add a pulse injection subroutine !
:rofl:

“My Hamster Runs Faster Than Yours ! Na Na, Na Na Nar !”
:rofl: :rofl:

1 Like

Providing he doesn’t sue me for breach of the working time directive, I reckon I’ll be ok!

Last bit of software fettling at lunchtime as my daughter wanted to make the display screen look a bit “cooler”. Quite pleased with how our updated layout worked, although I wish I was better at cutting holes in boxes!

Next job - hunt down a 3d printer to make a proper bezel for the display :slight_smile:

This is obviously just a leisure time activity so that wouldn’t count.
That would change if you hooked the wheel upto a generator and used him to power the house.
What do you reckon you’d get ? 0.05 W peak ?

Acting as his interim manager, I demand that his rate be upped to 12 sesame seeds per km !
(though admit, that may mean he starts injecting his own pulses)

1 Like

This is probably the coolest thing I’ve seen on Home Assistant. Our hamster is a little shy and only runs at night when nobody is around. We know he’s running because he has a VERY squeaky wheel. To this day, we have never actually SEEN him on the wheel.

I’d love to see a step-by-step write up of how you achieved the electronics and coding. It would definitely make the wife more approving of Home Assistant :slight_smile:

1 Like

I’d have to spend a bit of time sorting out the software first as it’s all a big spidery mess at the moment, but the electronics are trivial - the actual A3144E sensor just needs 3 connections - 3.3v, GND and data, which has a 10k pullup resistor to the 3.3v supply (you can see this soldered to the PCB in one of the pics). This then drives an interrupt so every time the magnet passes the sensor, a function is fired in the code (which just increments a counter). Everything else is just a bit of basic maths, and scaffolding to get the data back to HassIO for MQTT.

If I have time, I’ll try to sort it out later.

No pressure - would be amazing to be able to implement myself. My knowledge in this regard is a little limited. Absolute kudos again on a wonderful project - the kids must love it!

1 Like

When I saw the first picture with the breadboard, I thought “poor hamster”, that’s going to be heavy" :wink:
Good stuff :slight_smile:

GV

This is the most amazing thing I have seen all month.

You need to add another full colour LCD screen that Gus can see from his wheel (might necessitate tracking the direction he runs, easily done with another magnet offset from the first and another Hall sensor) so he can track his stats in a hamster friendly way. Display graphs of his favourite food items, etc. And while he runs, overlay scenes of excellent hamster running terrain for encouragement.

And obviously, his stats need to be Tweeted every day.

One never shares pictures of the scientific failures…

Ooooh, direction of travel would indeed be an interesting thing to add. In fact, we would need two more magnets, as I need to install them in matched pairs so as to avoid imbalancing the wheel - it really does go round quite quickly! I’ll ask my eldest whether she wants to do this or not - it’s her project and up to her!

Favourite food items is easy - strawberry biscuit treats, typically dispensed by me which is why the hamster always comes to see me when he hears my voice!

Great stuff. Interested in building something similar myself. Care to share the code you are using on the board?

Fantastic stuff. Would love to make it for my hamster. Do you mind sharing the code.