Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Manufacturing Technology >> Manufacturing process

Track Your Hamster’s Daily Exercise with a Raspberry Pi Fitness Tracker

Curious about how much your hamster runs in a day? Our 9‑year‑old daughter sparked this project, and the results were both surprising and insightful. By combining a Raspberry Pi, a laser break‑beam sensor, and a simple script, you can effortlessly measure your pet’s distance traveled and speed.

What You’ll Need

Step 1: Measurement Concept

The system works by detecting each full rotation of the wheel. A small target on the wheel reflects the laser beam once per revolution. The Raspberry Pi counts these events, calculates the distance (wheel circumference) and speed, and streams the data to a real‑time dashboard you can check every morning.

Step 2: Hardware Setup

The Adafruit laser break‑beam sensor is compact and requires no extra weight on the wheel – essential for a 2 oz. dwarf hamster. It contains both transmitter and receiver in a single housing. When the beam is interrupted by the target, the sensor outputs a signal.

Safety Note: Never shine the laser directly into the living area or the hamster’s eyes. The beam can damage vision.

Step 3: Software Setup

To visualize the data, use Initial State’s real‑time dashboard. Follow these quick‑start instructions to install the Initial State streamer on your Pi.

Create a new Python file, e.g., hamster_fitness.py, and paste the following code:

import time
import initialstate
from gpiozero import Button

# Replace with your own client key
client_key = "PUT YOUR CLIENT KEY HERE"
bucket_name = "Hamster Fitness Tracker"

# Create a new stream in the specified bucket
stream = initialstate.Stream.create(bucket_name, client_key)

# Set up the sensor pin (change 17 to your chosen GPIO)
sensor = Button(17)

# Calculate wheel circumference (example: 10 cm radius)
wheel_radius_cm = 10
circumference_cm = 2 * 3.14159 * wheel_radius_cm

rotations = 0
start_time = time.time()

while True:
    sensor.wait_for_press()
    rotations += 1
    elapsed = time.time() - start_time
    distance = rotations * circumference_cm
    speed = distance / elapsed  # cm per second
    # Send data to Initial State
    stream.publish({"rotations": rotations, "distance_cm": distance, "speed_cm_per_s": speed})
    print(f"Rotations: {rotations}, Distance: {distance:.1f} cm, Speed: {speed:.2f} cm/s")
    time.sleep(0.1)  # debounce

Each time the script runs, a new bucket named Hamster Fitness Tracker is created under your Initial State account, and all subsequent data points are stored there. The dashboard will update live, giving you instant insight into your hamster’s activity.

With this setup, you’ll discover just how active your furry friend really is, even while you sleep!

Manufacturing process

  1. Build a Raspberry Pi Temperature Logger with a $5 I2C Sensor
  2. Control an LED with a PIR Motion Sensor on Raspberry Pi
  3. Build a Low‑Cost Raspberry Pi Soil Moisture Sensor for Smart Irrigation
  4. Track Your Hamster’s Daily Exercise with a Raspberry Pi Fitness Tracker
  5. Build Your First IoT Project with Raspberry Pi, DHT11, and ThingSpeak
  6. Build a Raspberry Pi Home Temperature Monitor with MCP9808, InfluxDB & Grafana
  7. Transform Your RC Car Into a Bluetooth‑Controlled Vehicle
  8. Advanced Hiking Tracker with Arduino: GPS, Sensors & Battery Pack
  9. Transform Your IoT Idea into a Market‑Ready Product
  10. From Concept to Reality: Turning Creative Designs into Tangible Products