Here are my Tutorials to bring your hamster to the internet:

  • hamster wheel
  • hamster tv
  • hamster cams
  • hamster server
  • hamster twitter
  • hamster code

  • hamster wheel

    it was a bit difficult to find the right way to install the reed contact to the wheel. my first attemps fail hard:
    i have to get a more stable and secure position for the reed and wheel magnet. my greatest fear was, that the hamster can catch the magnet or the cable from the reed contact.
    now i can clean up the whole cage and get sure, the magnet/reed connection always get the same position. this is really important! (catch later).
    the reed contact is wired to an arduino:
  • fritzing sheet: (download)
  • code base for hamster wheel with reed contact:

  • #include 
    #define REEDSWITCH 3
    #define STATOSWITCH 0
    #define AUTH_KEY 235235
    #define WHEELSIZE 0.91
    // Ethernet
    byte mac[]    = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    byte ip[]     = { 192, 168, 178, 120};
    byte gateway[] = { 192, 168, 178, 1};
    byte subnet[] = { 255, 255, 255, 0};
    byte server[] = { 188, 138, 127, 107 };
    // byte server[] = { 192, 168, 178, 22 };
    EthernetClient client;
    // Variables für die Berechnung
    volatile unsigned long rotations = 0;
    float meter = 0.0;
    volatile unsigned long lastactive = 0;
    // Debounce Variablen
    volatile unsigned long last_micros;
    unsigned long debouncing_time = 160;              //Debouncing Time in Milliseconds
    int tempcf; 
    void setup()
      //Ethernet.begin(mac, ip, dns, gateway, subnet);
      Ethernet.begin(mac, ip);
      // Reed Sensor (Interrupt) 
      attachInterrupt(digitalPinToInterrupt(REEDSWITCH), debounceInterrupt, FALLING);
      pinMode(REEDSWITCH, INPUT);
      // Den Wert mit einem Wert != 0 besetzen, damit die spätere berrechnung bereits vorab einen Wert hat. 
      lastactive = millis();
    void loop()
      if ( rotations >= 1 && ((millis() - lastactive) >= 1500) ) {
        // Berechnen wielange der Hamster für die Umdrehungen benötigt hat
        meter = rotations * WHEELSIZE; 
        Serial.print("Rotations: "); 
        // Ausgabe der Daten an den Server 
        tempcf = client.connect(server, 80);
        if (tempcf) {
          client.print("GET /hamster_update.php?");
        // Werte wieder zurücksetzen für den nächsten Durchlauf
        rotations = 0;                      
        meter = 0.0;
    // ----- Helper Functions 
    void debounceInterrupt() {
      if ( micros() < last_micros ) {
        last_micros = micros();
      if ((unsigned long)(micros() - last_micros) >= debouncing_time * 1000) {
        // Wert erhöhen, sofern der Knopf gedrückt wurde 
        last_micros = micros(); 
        lastactive = millis();
    this code is really tricky, cause i had to deal with debouncing reed contacts. the position is really important for my debouncing time, so 160ms now is working for me.

    wikipedia:Contact bounce (also called chatter) is a common problem with mechanical switches and relays. Switch and relay contacts are usually made of springy metals. When the contacts strike together, their momentum and elasticity act together to cause them to bounce apart one or more times before making steady contact. The result is a rapidly pulsed electric current instead of a clean transition from zero to full current.

    hamster tv

    the hamster tv is a simple Raspberry pi 3 with a Kuman 3.5 inch 320*480 Resolution Touch Screen TFT LCD Display Module SPI Interface with Touch Pen
    it is a bit difficult to get the display running with an updated raspbian debian version, so i have to use the original image from my vendor. just contact me if you need the image.
    to display the message, i created a simple bash file:
    while true
    wget -q -O message.txt
    cat message.txt
    sleep 15

    so every 15 seconds, the script is looking for a new message. the php script hamster_output.php just gets the latest message from database and display them to match the lcd display.

    hamster cams

    i have two webcams running:
  • TeckNet® C018 Full HD 1080p Pro Webcam
  • Phillips SPC 530
  • i use mjpg_streamer for streaming webcams and still images (twitter)

    hamster server

    for the server you can use a common raspberry pi, but to use mjpeg_streamer you need some powerfull ressources. hd cams can leech lots of cpu. you will need following software
  • apache
  • mysql
  • php

  • there are lots of tutorials to setup a lamp server. just google em.

    hamster twitter

    for twitter i use codebird-php. a really good and easy to use php interface to post statuses and images to twitter.

    hamster code

    this website and my code for arduino is created with these following tools:
  • vim
  • bootstrap
  • codi
  • qtip2