We have a pet Hamster, which is mostly active at night being that they are nocturnal animals. Playing in silence all on its own, which may be a good thing but to me that sounds lonely. So I thought I would give it the option to have a bit of a boogie at night. So I built a music player with sensor triggers.

PetPlayer MP3 for a Hamster

Originally I thought it would be good to having buttons and lights, which turned out to be not such a good idea. Basically Hamsters can't see much and their colour vision is in shades of green and yellow.  So most coloured lights would be invisible to them. For example a blue or red coloured LED would not be seen, the same as we can't see the Infra Red light on a TV remote control flashing.

Hamsters have very good hearing so using sound would be a much better option.

PetPlayer parts

So I have gone with a Music player. The cage is fitted with a couple of infrared distance sensors in the parts of the cage that are away of the main travel areas, to minimise accidental activations. The sensors have a range of 5cm so she has to be fairly close to set them off.

The setup consists of:

  • A Raspberry Pi Zero2
  • A Pimoroni Mono Audio Amp SHIM
  • 2 x Pololu Carrier with Sharp GP2Y0D805Z0F Digital Infra Red Distance Sensor up to 5cm
  • 3 watt speaker mounted in a plastic pot.
  • Power off Button
  • Option to add a third IR sensor
  • Option to add I2C device

When a sensor is active the music plays until the sensor is deactivated. If the Hamster re-activates the sensor again within one minute then the music continues where it left off, any longer and the song will start again. Each sensor plays a different song.

I have written a python script that uses the VLC media players python library to control the music.

As sensors can sometimes activate because of interference or rouge IR signals in the room, there is a feature to stop the music playing all night long. If the music plays continuously for 20 minutes then it will be deactivated. We don't want to upset our Hamster.

Logging the Activities

Each time the sensors are activated, the time and duration is logged and sent via a Mosquito (mqtt) broker to a Node Red server for display on a dashboard of night time activities.

The graph shows that she was boogying at around midnight, 3am and 4:30am. She was mostly in a dancing mood shortly after midnight with a 280 second dance.

 PetPlayer Graphs1

The cage has several areas where she can chew various things such as treats, wood, cardboard the cage bars  but she does choose to chew the metal brackets that are holding the sensors on.

PetPlayer Cage Sensors

I like to think that she likes that locations, so she can chew and listen to music. She may well be trying to chew the brackets off to stop that annoying music playing! 

I get the impression she likes it. This is because on most nights, as soon as we switch the room lights off to go to bed, within a minute the music starts up. Each sensor plays one song all night selected randomly from a playlist. So she may be checking out what tune she has playing tonight.

The music selection was picked to be jolly and musical so the playlist comes from a Disney Theme Park CD and a few songs from Jean Michel Jarre. 

Future Additions

I plan to change the python script so it changes the song several times a night to see if she has a favourite with more activity for certain songs. I will also run the sensors without playing music to see if she uses them less when the music is not available.

There is also an option to add a third sensor and possibly a camera to capture her night time activities.


Add comment