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 ) 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!