DIY Arduino Hamster Speedometer

Click the “Microcontroller” above, then click the top right corner… select “Pin/StarPublic Account to receive the latest articles!

DIY Arduino Hamster SpeedometerDIY Arduino Hamster Speedometer

About three years ago, my nephew got their first pet, a hamster named Nugget. Curiosity about Nugget’s exercise program sparked a project that lasted for Nugget (RIP). This guide outlines a functional fitness wheel optical speedometer. The Hamster Wheel Tachometer (HWT) displays the hamster’s maximum speed (RPM) and total rotations. Nugget’s human family wanted something simple to install and use, but did not want the child to have more screen time. Considering the way rodents interact with the world, I thought a standalone battery-powered device would be great. The HWT will run for about 10 days on a charge. It can record up to 120 RPM depending on the wheel diameter.

Step 1: Parts List

DIY Arduino Hamster Speedometer

About three years ago, my nephews got their first pet, a hamster named Nugget. Curiosity about Nugget’s exercise program sparked a long-lasting project for Nugget (RIP). This guide outlines a functional exercise wheel optical speedometer. The Hamster Wheel Tachometer (HWT) displays the hamster’s maximum speed (RPM) and total rotations. Nugget’s human family wanted something easy to install and use, but did not want the kids to have more screen time. Given the way rodents interact with the world, I thought a battery-powered solution would be great. The HWT will run for about 10 days on a charge. It can record up to 120 RPM depending on the wheel diameter.

Step 1: Parts List

DIY Arduino Hamster Speedometer

Adafruit #2771 Feather 32u4 Basic Proto (with additional wiring – see Step 4: Assemble the Electronics)

Adafruit #3130 0.54″ Four Digit Featherwing Display – Red

Adafruit #2886 Feather Header Kit – 12 Pin and 16 Pin Female Header Kit

Adafruit #805 Breadboard Friendly SPDT Slide Switch

Adafruit #3898 Lithium Polymer Battery perfect for Feather – 3.7V 400mAh

Vishay TS4038 Infrared Sensor Module 2.5-5.5v 38kHz

Vishay TSAL4400 Infrared Emitter T-1

Resistor, 470, 1/4w

Switch, Button, SPST, Momentary, 0.25″ Panel Mount (Jameco P/N 26623 or equivalent)

(4) 2.5mm Nylon Machine Screws with Nuts (or 4-40 Machine Screws – see Step 6: Assemble HWT)

Hamster Wheel Tachometer Enclosure – 3D Printed. (Public TinkerCad file)

Hamster Wheel Tachometer Ring – 3D Printed. (Public TinkerCad file)

Hamster Wheel Tachometer Sensor Enclosure – 3D Printed. (Public TinkerCad file)

Display Contrast Filter. There are three options:

  1. (54mm x 34mm x 3.1mm) 1/8″ Transparent Gray Smoked Polycarbonate (suffix plastic or equivalent).

  2. No Contrast Filter

  3. 3D print a filter using thin translucent PLA and this public TinkerCad file.

Dark Material: Some adhesive non-infrared reflective material. I used black felt from a craft store. Creatology peel-and-stick black polyester felt or equivalent. See also Step 7: Calibration – Dark Area Notes.

Note: Within reasonable limits, you can substitute parts. I tend to support Adafruit because of their quality and support for the maker community. Oh, I love the gold flash pads.

Step 2: Operating Principle

The HWT uses infrared light (IR) to calculate the number of rotations of the spinning exercise wheel. Most plastic exercise wheels reflect infrared light quite well, too well. Even translucent plastic wheels under visible light can reflect enough infrared to trigger the infrared sensor. The user creates a dark area on the wheel using black sticky felt (see Step 7: Calibration – Dark Area Notes). When the HWT detects a reflection to the dark transition, it counts one rotation.

The HWT uses Vishay infrared sensor modules and infrared LED emitters. In typical applications, the Vishay TSS4038 infrared sensor module is used for presence detection – whether something (reflecting IR) is present or not. This is not exactly what the HWT is doing here. The plastic exercise wheel is always there. We trick the sensor by adding an infrared dark area to make the wheel “disappear” in infrared light. Additionally, the HWT takes advantage of the design of the Vishay TSS4038 infrared sensor module to provide a variable range of operating distances. Step 3: Code section and code listing contains more information. Application note Vishay’s TSSP4056 rapid proximity sensing sensor outlines the basic premise.

The Adafruit Feather has an Atmel MEGA32U4 microcontroller and a through-hole prototype area.

Soldered into the prototype area is a Vishay TSAL4400 infrared LED that produces a 38 kHz infrared signal burst (under the control of the 32U4 microcontroller).

The prototype design area also has a Vishay TSS4038 infrared sensor module soldered for reflective sensor, grid, and rapid proximity applications.

If a burst of 38kHz infrared light is received within a certain time, this IR sensor module will produce a signal.

The 32U4 microcontroller generates a 38kHz burst every 32mS. The 32mS rate determines the maximum exercise wheel RPM that can be measured. The 32U4 also monitors the IR sensor module. If the hamster wheel has enough infrared reflection, each burst should cause the infrared sensor module to respond. The dark area of the wheel does not produce an infrared sensor response that the 32U4 notices. When the hamster wheel moves to provide enough infrared reflection, the 32U4 code records this change and logs it as a rotation of the wheel (transition from bright to dark = 1 rotation).

About once a minute, the 32U4 checks whether the last minute’s rotations exceed the previous maximum count and updates this “personal best” score if necessary. The last minute’s RPM count is also added to the total rotations of the wheel.

A button is used to display the count (see Step 9:Normal mode section) and is used to calibrate the HWT (see Step 7: Calibration mode section).

The ON-OFF slide switch controls the power to the HWT and plays a role in calibration (see Step 7: Calibration section).

If the diameter of the exercise wheel is known, the formula for calculating the total distance run is (diameter * total wheel rotations * π).

Step 3: Code

I assume the user knows the Arduino IDE and Adafruit Feather 32U4 board. I used the standard Arduino IDE (1.8.13) with the RocketScream low power library. I worked hard to comment the code extensively, perhaps accurately.

I did not document the quirks and interactions of the Arduino IDE and Adafruit Feather 32U4 system. For example, the 32U4 handles USB communication with the Arduino loader. Getting the host PC running the Arduino IDE to find the Feather 32U4 USB connection can be tricky. There are online forum threads detailing the issues and fixes.

Especially the RocketScream low power library, Feather 32U4 USB operation is interrupted. Therefore, to download the code from the Arduino IDE to the 32U4, the user may have to press the Feather 32U4 reset button until the IDE finds the USB serial port. This is much easier before assembling the HWT.

Attachments

  • nu_41.ino

  • nu_41.pdf

Step 4: Assemble the Electronics

DIY Arduino Hamster Speedometer

DIY Arduino Hamster Speedometer

DIY Arduino Hamster Speedometer

  1. Assemble Adafruit #2771

  • Vishay TSS4038 Infrared Sensor Module

  • Vishay TSAL4400 Infrared Emitter

  • Resistor, 470, 1/4w

  • Hamster Wheel Tachometer Sensor Enclosure – 3D Printed. (Public TinkerCad file)

  1. If minimum power consumption is needed, cut the trace between R7 and the red LED. This will disable the feather indicator light.

  2. Install the Adafruit #2886 Header Kit on the #2771 Feather according to their tutorial. Note that there are several options for header styles. The HWT 3D printed enclosure is sized for this header.

  3. Install the optical components onto the #2771 Feather. See pictures and schematic.

  • Solder the display button switch to the Feather 32U4 printed circuit board assembly (PCBA), schematic.

  • Assemble the Adafruit #3130 0.54″ Four Digit Featherwing Display according to their tutorial.

  • Assemble the power switch/battery assembly according to the images and schematic. Note: The switch lead near the switch needs to be unsoldered for the switch to fit properly in the HWT enclosure.

    Note: You can wire it however you like. This is how I wired it for this guided HWT assembly. Other prototypes may have slightly different wire placements. As long as your wiring matches the schematic and the Vishay sensor and LED housings protrude from the bottom of the HWT enclosure, you should be fine.

    • Adafruit #3898 Lithium Polymer Battery.

    • Adafruit #805 SPDT Slide Switch.

    • Connecting Wires.

    Attachments

    • nu_41_schem.pdf

    Step 5: 3D Print Parts

    DIY Arduino Hamster Speedometer

    DIY Arduino Hamster Speedometer

    DIY Arduino Hamster Speedometer

    The HWT enclosure consists of three 3D printed parts:

    1. Hamster Wheel Tachometer Enclosure – (Public TinkerCad file)

    2. Hamster Wheel Tachometer Baffle – (Public TinkerCad file)

    3. Hamster Wheel Tachometer Sensor Enclosure – (Public TinkerCad file)

    The HWT enclosure, HWT display frame, and HWT sensor enclosure were created in Tinkercad and are public files. One can download copies and modify them as needed. I believe the designs can be optimized. These were printed on a MakerGear M2 using Simplify3D controls. Adafruit has a tutorial on 3D printing cases for Adafruit Feather. I found these 3D printing settings to be a good starting point for my M2 MakerGear printer.

    If necessary, a thin translucent PLA can be used with this Public TinkerCad file to 3D print the display contrast filter.

    Step 6: Assemble HWT

    DIY Arduino Hamster Speedometer

    DIY Arduino Hamster Speedometer

    DIY Arduino Hamster Speedometer

    1. Connect the battery/switch assembly to the Feather #2771 PCBA. It is much easier to do this now than to bolt the Feather #2771 into the HWT enclosure.

    2. Secure the slide switch into its position in the HWT enclosure.

    3. Wire the Feather PCBA into the storage module when placing it.

    4. The sensor enclosure should protrude from the back of the HWT enclosure.

    5. 2.5mm nuts can be tricky to connect to 2.5mm screws. You may want to use 4-40 machine screws as described in the Adafruit tutorial: https://learn.adafruit.com/3d-printed-case-for-adafruit-feather?view=allDIY Arduino Hamster Speedometer

    6. Press the #3130 display PCBA into the Feather #2771 PCBA. Watch for bent or misaligned pins.

    7. Connect the switch to the display baffle.

    8. Clip the display baffle into the HWT enclosure.

    Step 7: Calibration

    In calibration mode, the display continuously shows the output of the infrared sensor. Calibration helps verify:

    1. The hamster wheel reflects enough infrared light.

    2. The dark area is absorbing infrared light.

    3. The range setting is correct for the distance to the exercise wheel.

    • To enter calibration mode:

    1. Use the power slide switch to turn off the HWT.

    2. Press and hold the display button.

    3. Use the power slide switch to turn on the HWT.

    4. The HWT enters calibration mode and displays CAL.

    5. Release the display button. The HWT now displays a letter indicating the range setting (L, M, or S) and the sensor reading. Note that the sensor reading is not the actual distance from the wheel to the HWT . It is a measure of the reflection quality.

  • How to check the wheel’s infrared reflection: If the reflection is sufficient, the sensor display should read around 28. If the wheel is too far from the HWT, the reflection will be insufficient and the sensor display will go blank. If so, move the wheel closer to the HWT. Rotate the wheel; the reading will fluctuate as the wheel turns. A range of 22 to 29 is normal. The sensor reading should not be blank. The range letter (L, M, or S) will always be displayed.

  • How to check the dark area response: Areas that absorb IR (dark areas) will cause the sensor reading to go blank. Rotate the wheel so that the dark area presents to the HWT. The display should go blank, indicating no reflection. If numbers are displayed, the dark area is too close to the HWT , or the dark material used does not absorb enough infrared light. Dark Area Notes Anything that absorbs infrared light can work, such as flat black paint or flat black tape. It is essential to have a flat or matte surface! Shiny black materials may have strong reflectivity under infrared light. The dark area can be located on the circumference of the exercise wheel or on a flat side. Which way to choose depends on the installation location of the HWT. The dark area needs to be large enough that the infrared sensor can only see the dark area and not the adjacent reflective plastic. The infrared emitter projects a conical infrared light. The cone size is proportional to the distance between the HWT and the wheel. A one-to-one ratio is effective. If the HWT is 3 inches from the wheel, the width of the dark area should be 2-3 inches. Sorry for the imperial units. This image shows the TSAL4400 infrared LED illuminating a target from 3 inches away. This image was taken with a NOIR Raspberry Pi camera. Material selection tips: Once I assembled the HWT, I used it as an infrared reflectometer (that’s right). During development, I took the HWT to pet stores, hardware stores, and fabric stores. Many items were “tested.” I checked plastic exercise wheels, dark materials, and the effects of material distance. Doing so helped me understand the performance and limitations of the HWT. This allowed me to place the plastic wheel correctly in the cage and select the correct range setting in calibration mode. Yes, more than once I had to explain to confused store employees what I was doing.

    • How to change the range:

      Note: The HWT will remember the range setting after a reset and even if the battery is dead.

      • (L) Voltage Range = 1.5 to 5″

      • (M) Y Range = 1.3 to 3.5″

      • (S) Short Range = 0.5 to 2″ (uppercase S looks like the number 5)

    1. In calibration mode, the first displayed character is the range setting (L, M, S):

      Note: These ranges depend on the target material and are very approximate.

    2. To change the range, press the display button. The first displayed character will change to show the new range.

    3. To keep this new range, press and hold the display button for 4 seconds. When done, the display will show Savd for two seconds.

  • Success? If the exercise wheel reflects (displaying around 28) and the dark area absorbs (displaying blank), then you are done. Restart the HWT to return to normal mode (see Step 9: Normal mode section). Otherwise, adjust the distance between the HWT and the wheel or change the HWT range until successful.

  • Note: The position of the HWT mounted on the cage affects the calibration of the HWT. You may not be able to place the wheel in the desired position in the cage because that cage position may not be within the HWT’s range. The materials you choose for the wheel and the dark area material (black felt) also become factors.

    Step 8: Mounting in the Cage
    1. Calibrate the HWT and use the calibration process to inform you where to place the exercise wheel and where to mount the HWT on the cage.

    2. The HWT can be tied to the side of the cage using the mounting holes in the HWT enclosure. I used plastic-coated iron wire tie wraps. Zip ties also work.

    3. After mounting the HWT and placing the exercise wheel, verify that the exercise wheel reflects infrared light and the dark area absorbs infrared light.

    4. If needed, the “calibration” section discusses changing the range. Users can select a range of distances in the HWT. There are three overlapping ranges:

    • (L) Voltage Range = 1.5 to 5″

    • (M) Y Range = 1.3 to 3.5″

    • (S) Range = 0.5 to 2″

  • The HWT sensor enclosure (infrared emitter/sensor) must not be obstructed by cage wire. You may need to slightly spread the cage wire to allow the components to poke through the cage wire.

  • Verify that the HWT is correctly recording the rotations of the exercise wheel (see Step 9: Normal operating mode).

  • Step 9: Normal Operating Mode
    1. In normal mode, the HWT counts the rotations of the exercise wheel.

    2. To enter normal mode, use the power slide switch to turn on the HWT.

    3. The display will show nu41 for one second, then display the range setting for one second.

    • Ra=L Long Range

    • Ra=M Medium Range

    • Ra=S Short Range (uppercase S looks like the number 5)

  • During normal operation, a single display LED segment will flash very briefly each minute.

  • Each minute, the count for that minute is compared to the maximum count from previous minutes (the hamster’s personal best) and updated if necessary. The count for each minute is added to the total count.

  • Press and release the display button to see the wheel count. The display shows the following:

    • Now= followed by the wheel rotations since the last minute check. Note: This number will be added to the total in the next minute’s price change.

    • Max= followed by the highest rotation count. Nugget’s personal best since the last restart.

    • Tot= followed by the total rotations since the last power cycle.

    Power cycling (power slide switch off) will reset all counts. These numbers cannot be retrieved.

    The HWT should run for about ten days on a single charge, after which the LiPo cell will automatically shut off. To avoid losing the exercise wheel count, please recharge before the LiPo battery automatically shuts off.

    Step 10: Lithium Polymer Battery Precautions:
    1. Lithium polymer batteries store a large amount of energy using volatile chemicals. Just because mobile phones and laptops use them, one should not be careless and should respect them.

    2. The HWT uses a rechargeable lithium polymer (LiPo) 3.7v battery. The top of the Adafruit LiPo battery is wrapped in amber plastic. This includes an overall charging/discharging safety circuit on a small PCBA. The red and black battery leads with JST connectors are actually soldered to the PCBA. The monitoring circuit between the LiPo and the outside is a very good safety feature.

    3. If the LiPo overall charging/discharging safety circuit determines the LiPo battery is too low, the HWT will lose power. The exercise wheel count will be lost!

    4. If the HWT appears “dead,” it may need a battery charge. Use a micro USB cable to connect the HWT to a standard USB power source.

    5. While charging, a yellow LED will appear in the HWT plastic enclosure.

    6. The LiPo will be fully charged in about 4-5 hours.

    7. The LiPo battery protection circuit does not allow the LiPo to overcharge, but disconnect the micro USB cable when the yellow LED goes out.

    8. As described in the Adafruit #3898 documentation, I initially intended to fit the LiPo unit between the Feather #2771 PCBA and the #3130 display PCBA. I found that my wiring in the Feather #2771 prototype area was too high, and the LiPo battery could not be installed without denting the LiPo battery. This made me nervous. I resorted to placing the battery on one side of the PCBA.

    9. Those red and black wires from the LiPo overall charging/discharging safety circuit do not like to be bent. During development, I broke more than one set of wires. To provide more stress relief, I designed and 3D printed a stress relief. This is the gray block on top of the LiPo unit. It is not necessary, but here it is (public TinkerCad file).

    Step 11: Development History:

    DIY Arduino Hamster Speedometer

    DIY Arduino Hamster Speedometer

    During the three-year lifecycle of the Nugget project, several versions were produced:

    1.x Reliability of the concept and data collection platform.

    The performance range of Nugget was characterized (max RPM, total, active time). At his peak, Nugget reached 100 RPM and was able to run 0.3 miles each night. Data spreadsheets connected various wheels. An attachment was also included that contained actual Nugget RPM records stored on an SD card.

    • Arduino Duemilanove

    • Adafruit #1141 SD Card Data Logger Shield

    • Adafruit #714+#716 LCD Shield

    • Omron E3F2-R2C4 Reflective Optical Sensor

    • AC Wall Transformer (Omron requires 12 volts)

    2.x Exploring Sensors and Hardware.

    A microcontroller and display were established:

    • Adafruit #2771 Feather 32U4

    • Adafruit #3130 14-segment LED display Featherwing.

    This combination was suitable for low power (32U4 sleep mode), battery management (built-in LiPo charger), and cost (LED is cheap and uses less power than LCD + backlight).

    • Explored Hall effect magnetic and discrete optical sensors (i.e., QRD1114). The range was never sufficient. Abandoned.

    • Adafruit #2821 Feather HUZZAH with ESP8266 reporting to Adafruit IO Dashboard. More screen time was not what the client wanted. Abandoned.

    3.x Sensor Work:

    This series also explored alternative sensors, such as using stepper motors as encoders, similar to this Instructable. Viable, but low signal strength at low RPM. More work would make it a viable solution, but it was not a simple retrofit for existing hamster environments. Abandoned.

    4.1 The hardware/software solution described in this instruction.

    5.x More Sensor Work:

    Examined Sharp GP2Y0D810Z0F digital distance sensors with Pololu carriers while still using Adafruit #2771 Feather 32U4 and Adafruit #3130 14-segment LED display Featherwing. Worked well. Made the code trivial. Used more power than the Vishay TSSP4038 solution. Abandoned.

    6.x The Future?

    • Replace some of the mounting standoffs of the HWT enclosure for the Adafruit #2771 Feather with mounting pillars.

    • Replace the on/off switch with a momentary push button switch connected to the Feather reset.

    • Microcontroller ATSAMD21 Cortex M0, as found in the Adafruit #2772 Feather M0 Basic Proto, has many attractive features. I will look closely at this on another revision.

    • Vishay has a new infrared sensor module TSSP94038. It has lower current requirements and clearer responses.

    Attachments

    • nugget_wheel_timing.pdf

    • January 28 Nugget_raw_data_8.csv

    Material Purchase and Resource Download Instructions

    (The materials section in the article with purchase links, please click the bottom left corner: Read the original text to view the original text.)

    Resource Identifier:Hamster-Wheel-Tachometer

    Step 1, open this link in WeChat, copy the “Resource Identifier:” red part above,

    Step 2, click the link below to follow the “Microcontroller” public account, enter the public account dialogue window,

    Step 3, reply with the copied red content, the public account will automatically return the download link!

    Step 4, click the three dots in the upper right corner of the blank page opened in WeChat, open with the browser; or click the link on a PC.

    Recommended Good Articles Click the title to jump

    Must Read for Microcontroller Beginners

    Words from Zhou Ligong to Young People Learning Microcontrollers

    Experts Talk: The Difficulty of Entry and Mastery Time Span of Software and Hardware

    Reflections on Learning 51 Microcontrollers; Recommended Learning Materials; Essential Programs to Write

    Comparison of Several Microcontrollers Used

    Learning Route for ARM+LINUX (Learning Order, Knowledge Points and Book Recommendations)

    Differences and Connections between ARM/DSP/FPGA/CPLD/SOPC/SOC

    Fun Electronic Production: Food Power Generation in the Hands of Artists – Electronic DIY

    My Experience: From a Production Line Worker to a Microcontroller Engineer

    Things Hardware Engineers Should Learn

    “Learning Insights on 51 Microcontrollers: One Connection Leads to Hundreds”

    “Various Sensor Working Principle Dynamic Diagram, Isn’t This Too Full!”

    Be Careful! These items indicate your phone has been monitored“This little thing is actually a generator? Make one yourself and you won’t be afraid of power outages”“Collection of DIY websites and electronic websites abroad (various strange high-energy projects)”“Which APPs are engineers using?”“A Chart to Understand Programmers’ Career Planning”“10 Easy-to-Make Arduino Projects”“When charging a phone, should you plug in the phone or the power source first?”

    “The True Meaning of Learning Analog Electronics”“7 Mechanical Principles Experiments Every Boy Should Learn to Flirt”

    Unless you change the people you associate with and the books you read, your next five years will be exactly the same as now. (Charlie Jones)
    DIY Arduino Hamster SpeedometerWelcome to forward, leave a message, like, share, thank you for your support!

    Leave a Comment

    ×