1 / 11
HAMSTER SPEED TESTER with a rotation counter and a reward upon reaching the goal — zdjęcie 1
1 / 11

HAMSTER SPEED TESTER with a rotation counter and a reward upon reaching the goal

Zamów wydruk tego modelu

Obliczymy ostateczną cenę na podstawie wybranego pliku. Sprawdzisz ją i zaakceptujesz przed płatnością.

Zapisane na tym urządzeniu.

HAMSTER SPEED TESTER by Drwal-Carodziej

Ocena
0 / 5
Polubienia
6
Pobrania
6
Wydruki
0
Wyświetlenia
172
Oceny
0

Aktualizacja u źródła:

Informacje o modelu

Źródło
Printables
Kategoria
Other Gadgets
Licencja
Creative Commons — Attribution — Noncommercial

Hamster Speed Tester

Description:
Have you ever wondered how fast a hamster can run? Or how many times a day it completes a lap around its wheel? Let’s try to find out!

Counter Features:

Can be connected to any hamster wheel

Displays the number of revolutions per minute (RPM) in real time

Stores the maximum speed achieved

Counts the total number of wheel spins since startup

When the entered spin target is reached, the hamster receives a reward from the dispenser

Components Needed for the Project:

Arduino board

SG90 servo motor

Hall sensor module

A few small magnets

Glue or double-sided tape

Zip ties for mounting

2x16 LCD Shield with six buttons

Breadboard

3D printed parts

Power source for Arduino (Power Bank or other)

Arduino code

The program was written using the Arduino IDE.
Tinkercad was used to design the 3D models.
Printing was done using PLA filament at 200°C,
with the print bed heated to 50°C.
Standard quality was set to 0.2 mm.

Assembly and Mounting Instructions:

Mount the LCD onto the Arduino.

Connect the VIN pin to the breadboard; this will power the sensor and servo.

Connect GND to serve as ground for both the sensor and the servo.

Connect the sensor's signal wire to analog pin A1.

Connect the servo signal wire to digital pin 3.

Upload the code to the Arduino.

And that’s all for the "complicated electronics"!
Printing on my ancient printer took three days!
Of course, I had to make a few design changes along the way — and there's still room for improvement.

Next, press the servo into its socket and glue it to the dispenser.
Make sure the servo arm moves between 40° and 120°, so it can properly open the reward box.
You can also extend the servo arm for better motion.

Attach a magnet to the wheel. The current code is written for one magnet.
If you want to use more magnets, you only need to change one line in the code — a comment inside the code explains how.
Mount the sensor as close to the magnet as possible, but make sure it doesn’t get caught.
In the photo, the sensor is attached with hot glue.

Operation:

Once powered on, a setup menu appears on the display to set the reward goal.
Use the up and down buttons to add or subtract 100 spins.
Use left and right buttons to add or subtract 5 spins.
Press the select button to confirm and start measuring.

Have fun! I’d love to see your versions of the project — improve it, play with it, and learn from your experience.
Never give up!
You can also add a real-time clock module and an SD card to save daily stats or activity time,
or add a Wi-Fi module to read results remotely or open the container wirelessly.

The only limit is your imagination!  Code below:

#include <Servo.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

#define BUTTONS_PIN A0
#define UP_BUTTON    0
#define DOWN_BUTTON  1
#define LEFT_BUTTON  2
#define RIGHT_BUTTON 3
#define SELECT_BUTTON 4
#define NO_BUTTON    5

Servo servo;

int prize = 0;
int suma = 0;
int rpm = 0;
int maxspeed = 0;

bool setupDone = false;
bool inLoop = false;
bool servoTriggered = false;

int lastSensorState = LOW;
unsigned long lastRpmTime = 0;
unsigned long highToLowCount = 0;
unsigned long startTime = 0;

unsigned long lastTotalDisplay = 0;
bool showingTotal = false;

int lastButton = NO_BUTTON;

enum SetupStage {
 STAGE_SERVO_INIT,
 STAGE_MSG1,
 STAGE_MSG2,
 STAGE_PRIZE_SELECT,
 STAGE_DONE
};

SetupStage currentStage = STAGE_SERVO_INIT;

unsigned long stageStartTime = 0;

// --- button write LCD Shield ---
int readButton() {
 int value = analogRead(BUTTONS_PIN);
 if (value < 50) return RIGHT_BUTTON;
 if (value < 200) return UP_BUTTON;
 if (value < 400) return DOWN_BUTTON;
 if (value < 600) return LEFT_BUTTON;
 if (value < 800) return SELECT_BUTTON;
 return NO_BUTTON;
}

void setup() {
 pinMode(A1, INPUT);
 lcd.begin(16, 2);
 stageStartTime = millis();
 servo.attach(3);
 servo.write(40); // serwo start position for full rewards box 
}

// --- program start without delay() ---
void handleSetupStages() {
 unsigned long now = millis();

 switch (currentStage) {
   case STAGE_SERVO_INIT:
     if (now - stageStartTime >= 2000) {
       servo.detach();
       lcd.clear();
       lcd.print("I love Hamster");
       stageStartTime = now;
       currentStage = STAGE_MSG1;
     }
     break;

   case STAGE_MSG1:
     if (now - stageStartTime >= 4000) {
       lcd.clear();
       lcd.print("Now infill");
       lcd.setCursor(0, 1);
       lcd.print("reward box");
       stageStartTime = now;
       currentStage = STAGE_MSG2;
     }
     break;

   case STAGE_MSG2:
     if (now - stageStartTime >= 4000) {
       lcd.clear();
       lcd.print("When reward?:^v");
       lcd.setCursor(0, 1);
       lcd.print(prize);
       currentStage = STAGE_PRIZE_SELECT;
     }
     break;

   case STAGE_PRIZE_SELECT: {
     int button = readButton();
     if (button != lastButton && button != NO_BUTTON) {
       switch (button) {
         case UP_BUTTON: prize += 100; break;
         case DOWN_BUTTON: prize -= 100; break;
         case LEFT_BUTTON: prize -= 5; break;
         case RIGHT_BUTTON: prize += 5; break;
         case SELECT_BUTTON:
           lcd.clear();
           lcd.print("Hamster speed:");
           lastRpmTime = now;
           lastTotalDisplay = now;
           currentStage = STAGE_DONE;
           inLoop = true;
           break;
       }
       prize = max(0, prize);
       lcd.setCursor(0, 1);
       lcd.print("                ");
       lcd.setCursor(0, 1);
       lcd.print(prize);
     }
     lastButton = button;
     break;
   }

   case STAGE_DONE:
     setupDone = true;
     break;
 }
}

void loop() {
 if (!setupDone) {
   handleSetupStages();
   return;
 }

 unsigned long now = millis();
 int sensorState = digitalRead(A1);

 
 if (sensorState == HIGH && lastSensorState == LOW) {
   suma++;
 }

 
 if (sensorState == LOW && lastSensorState == HIGH) {
   highToLowCount++;
 }

 lastSensorState = sensorState;

 // if you use wil yuse more magnet change in function if below :
 // for two magnet on whel  "rpm = highToLowCount * 60;" on "rpm = highToLowCount * 30;"
 // for thre magnet on whel  "rpm = highToLowCount * 60;" on "rpm = highToLowCount * 20;"
 // for four magnet on whel  "rpm = highToLowCount * 60;" on "rpm = highToLowCount * 15;"
 // for six magnet on whel  "rpm = highToLowCount * 60;" on "rpm = highToLowCount * 10;"
 // for twelwe magnet on whel  "rpm = highToLowCount * 60;" on "rpm = highToLowCount * 5;"
 // to have better rosoution


 
 if (now - lastRpmTime >= 1000) {
   rpm = highToLowCount * 60;
   highToLowCount = 0;
   lastRpmTime = now;

   if (rpm > maxspeed) maxspeed = rpm;

   if (rpm == 0) {
     lcd.setCursor(5, 1);
     lcd.print("    "); 
     lcd.setCursor(0, 1);
     lcd.print("RPM:");
     lcd.print(rpm);
   } else {
     lcd.setCursor(0, 1);
     lcd.print("RPM:");
     lcd.print(rpm);
   }
 }

 // show total for every 10 second
 if (now - lastTotalDisplay >= 10000) {
   showingTotal = true;
   startTime = now;
   lastTotalDisplay = now;
 }

 if (showingTotal) {
   if (now - startTime < 2000) {
     lcd.setCursor(0, 0);
     lcd.print("Total:         ");
     lcd.setCursor(0, 1);
     lcd.print("        ");
     lcd.setCursor(8, 1);
     lcd.print(suma);
   } else if (now - startTime < 4000) {
     lcd.setCursor(0, 0);
     lcd.print("Max Speed:     ");
     lcd.setCursor(0, 1);
     lcd.print("      ");
     lcd.setCursor(8, 1);
     lcd.print(maxspeed);
   } else {
     showingTotal = false;
     lcd.clear();
     lcd.print("Hamster speed:");
   }
 }

 // Open reward box
 if (!servoTriggered && suma >= prize) {
   servo.attach(3);
   servo.write(110);
   delay(2000);
   servo.detach();    
servoTriggered = true;
   
   
 }
}

Tagi