Hamster Wheel Tachometer
About three years ago, the nephews got their first pet, a hamster named Nugget. Curiosity about Nugget's exercise routine started a project that has long out lasted Nugget (RIP). This Instructable outlines a functional exercise wheel optical tachometer. The Hamster Wheel Tachometer (HWT) displays the hamster's highest speed (RPM) and the total number of revolutions. Nugget's human family wanted something simple to install and use, but did not want more screen time for the kids. Given rodents' chewy way of interacting with the world, I thought self-contained battery power would be good. The HWT will run for about 10 days on a charge. It can record up to 120 RPM depending on the wheel diameter.
Parts List
Adafruit #2771 Feather 32u4 Basic Proto (with supplemental wiring- see Step 4: Assemble Electronics)
Adafruit #3130 0.54" Quad Alphanumeric FeatherWing Display - Red
Adafruit #2886 Header Kit for Feather - 12-pin and 16-pin Female Header Set
Adafruit #805 Breadboard-friendly SPDT Slide Switch
Adafruit #3898 Lithium Ion Polymer Battery Ideal For Feathers - 3.7V 400mAh
Vishay TSS4038 IR Sensor Module 2.5-5.5v 38kHz
Vishay TSAL4400 Infrared Emitter T-1 pkg
Resistor, 470, 1/4w
Switch, push button, SPST, momentary on, 0.25" panel mount (Jameco P/N 26623 or equivalent)
(4) 2.5mm nylon machine screws with nuts (or 4-40 machine screw - see Step 6: Assemble the HWT)
Hamster Wheel Tachometer enclosure - 3D printed. (Public TinkerCad file)
Hamster Wheel Tachometer bezel - 3D printed. (Public TinkerCad file)
Hamster Wheel Tachometer Sensor housing - 3D printed. (Public TinkerCad file)
Display contrast filter. There are three options:
- (54mm x 34mm x 3.1mm) 1/8" Transparent Grey Smoked Polycarbonate (estreetplastics or equivalent).
- No contrast filter
- 3D print a filter using thin translucent PLA and this Public TinkerCad file.
Dark matter: some stick-on non-IR reflective material. I used stick-on black felt from a crafts store. Creatology Peel and Stick Black polyester felt or equivalent. See also Step 7: Calibration - Notes on Dark Area.
Note: Within reason, you may substitute parts. I tend to support Adafruit because of their quality and support of the maker community. Oh and I love gold-flashed solder pads.
Theory of Operation
The HWT uses infrared light (IR) to count revolutions of a rotating exercise wheel. Most plastic exercise wheels reflect IR light rather well, too well. Even plastic wheels that are translucent in visible light may reflect sufficient IR to trigger IR sensors. The user creates a dark area on the wheel using black stick-on felt (see Step 7: Calibration - Notes on the Dark Area). When a reflective to dark transition is detected by the HWT, one revolution is tallied.
The HWT uses a Vishay IR Sensor Module and IR LED emitter. In a typical application, the Vishay TSS4038 IR Sensor Module is used for presence detection - is something there (reflecting IR) or something is not there. That is not exactly what the HWT is doing here. The plastic exercise wheel is always there. We are fooling the sensor by adding an IR dark area to make the wheel 'disappear' in IR light. In addition, the HWT makes use of the Vishay TSS4038 IR Sensor Module's design to provide a variable range operating distance. Step 3: Code section and code listing has more information. The basic premise is outlined in Application Note Vishay’s TSSP4056 Sensor for Fast Proximity Sensing.
The Adafruit Feather has an Atmel MEGA32U4 microcontroller and a thru-hole prototyping area.
Soldered in the prototyping area is a Vishay TSAL4400 IR LED which creates bursts of 38 kHz IR signals (under the control of the 32U4 microcontroller).
Also soldered in the prototyping area is a Vishay TSS4038 IR Sensor Module for Reflective Sensor, Light Barrier, and Fast Proximity Applications.
This IR sensor module produces a signal if a burst of 38kHz IR light is received for a certain amount of time.
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. With sufficient IR reflection from the hamster wheel, each burst should cause the IR sensor module to respond. A dark area of the wheel yields no IR sensor response which the 32U4 notes. When the hamster wheel has moved so there is sufficient IR reflection, the 32U4 code notes the change and tallies this as one revolution of the wheel (light to dark transition= 1 revolution).
Approximately every minute, the 32U4 checks if the revolutions in the last minute has exceeded that previous highest RPM count and updates this 'personal best' score if needed. The number of RPM in the last minute is also added to the total number of wheel revolutions.
A push button is used to display the number of revolutions (see Step 9: Normal Mode section) and used in calibrate the HWT (see the Step 7: Calibration Mode section).
An ON-OFF slide switch controls power to the HWT and has a role in the calibration (see Step 7: Calibration section).
If the exercise wheel diameter is known the total distance run is calculated as (Diameter * Total wheel revolutions * π).
Code
I am assuming the user knows their way around the Arduino IDE and Adafruit Feather 32U4 board. I used the standard Arduino IDE (1.8.13) with the RocketScream Low Power Library. I endeavored to comment the code profusely and perhaps accurately.
I have not documented quirks and interactions of the Arduino IDE and the Adafruit Feather 32U4 system. For example, the 32U4 handles the USB communication with the Arduino loader. Getting the host PC running the Arduino IDE to find the Feather 32U4 USB connection can be troublesome. There are on-line forum threads detailing problems and fixes.
Particular to the RocketScream Low Power library, the Feather 32U4 USB operations are disrupted. Thus to download code from the Arduino IDE to the 32U4, the user may have to press the Feather 32U4 reset button until the IDE finds a USB serial port. This is so much easier to do before you assemble the HWT.
Assemble Electronics
- Assemble Adafruit #2771
- If lowest power drain is desired, cut the trace between R7 and the Red LED. This disables the Feather LED.
- Install the Adafruit #2886 Header Kit on the #2771 Feather per their tutorial. Note there are several options for header styles. The HWT 3D printed enclosure is sized for this header.
- Install the optical components on the #2771 Feather. Refer to the pictures and the schematic.
- Vishay TSS4038 IR Sensor Module
- Vishay TSAL4400 Infrared Emitter
- Resistor, 470, 1/4w
- Hamster Wheel Tachometer Sensor enclosure - 3D printed. (Public TinkerCad file)
- Solder the display push button switch to the Feather 32U4 printed circuit board assembly (PCBA) per the schematic.
- Assemble the Adafruit #3130 0.54" Quad Alphanumeric FeatherWing Display per their tutorial.
- Assemble the power switch / battery assembly per the images and the schematic. Note: the switch leads close to the switch need to be free of solder for the switch to fit properly in the HWT enclosure.
- Adafruit #3898 LiPo Battery.
- Adafruit #805 SPDT Slide Switch.
- Hookup wire.
Note: Feel free to wire as you wish. This is just how I assembled the HWT for this Instructable. Other prototypes had wires placed slightly differently. As long as your wiring conforms to the schematic and the Vishay sensor and LED housing pokes out the bottom of the HWT enclosure, you are good.
Downloads
3-D Printed Parts
The HWT housing consists of three 3D printed pieces:
- Hamster Wheel Tachometer enclosure - (Public TinkerCad file)
- Hamster Wheel Tachometer bezel - (Public TinkerCad file)
- Hamster Wheel Tachometer Sensor housing - (Public TinkerCad file)
The HWT housing, HWT display bezel and HWT sensor housing were created in Tinkercad and are public files. A person can down load copies and modify as wanted. I am sure the design can be optimized. These are printed on a MakerGear M2 using Simplify3D control. Adafruit has a tutorial for a 3D Printed Case for Adafruit Feather. I found those 3D printer settings to be a good starting point for my M2 MakerGear printer.
If needed a display contrast filter can be 3D printed using thin translucent PLA and this Public TinkerCad file.
Assemble the HWT
- Connect the battery/switch assembly to the Feather #2771 PCBA. It is much easier to do this now than when the Feather #2771 is bolted into the HWT enclosure.
- Seat the slide switch into its location in the HWT enclosure.
- Route the wires out of the way as you place the Feather PCBA into the enclosure.
- The sensor housing should stick out the back of the HWT enclosure.
- The 2.5mm nuts are difficult to attach to the 2.5mm screws. You may wish to use 4-40 machine screws as described in the Adafruit tutorial.
- Press the #3130 display PCBA into the Feather #2771 PCBA. Watch for bent or misaligned pins.
- Attach the switch to the display bezel.
- Snap the display bezel into the HWT enclosure.
Calibration
In Calibrate mode, the display continuously shows the output from the IR sensor. Calibration assists in verifying:
- The hamster wheel is reflecting sufficient IR light.
- The dark area is absorbing IR light.
- The range settings are correct for the distance to the exercise wheel.
- To enter Calibrate mode:
- Turn off the HWT using the Power slide switch.
- Press and hold the Display button.
- Turn on the HWT using the Power slide switch.
- The HWT enters Calibrate mode and displays CAL.
- Release the Display button. The HWT now displays a letter representing the range setting (L, M or S) and the sensor reading. Note the sensor reading is not the actual distance from wheel to HWT. It is a measure of the quality of reflection.
- How to check wheel IR reflections:
With an adequate reflection, the sensor display should read around 28. If the wheel is too far away from the HWT there is insufficient reflection and the sensor display will go blank. If so move the wheel closer to the HWT. Rotate the wheel; the readings will fluctuate as the wheel turns. A range of 22 to 29 is normal. The sensor reading should not blank. The range letter (L,M or S) will always be displayed.
- How to check dark area response:
An area that absorbs IR (dark area) will cause the sensor reading to go blank. Rotate the wheel so the dark area is presented to the HWT. The display should go blank meaning no reflection. If numbers are displayed, the dark area is too close to the HWT OR the dark material used doesn't absorb sufficient IR light.
Notes on the Dark Area
Anything that absorbs IR light will work, e.g. flat black paint or flat black tape. A flat or matte finish is important! A shiny black material might be very reflective in IR light. The dark area can be on the circumference or the flat side of the exercise wheel. Which you choose depends on where you mount the HWT.
The dark area needs to be of sufficient size that the IR sensor will see only the dark area, not adjacent reflective plastic. The IR emitter projects a cone of IR light. The cone size is proportional to the distance between the HWT and the wheel. A one-to-one ratio works. If the HWT is 3 inches from the wheel, the dark area should be 2-3 inches across. Sorry for the Imperial units.
The image shows the TSAL4400 IR LED illuminating a target from 3 inches away. The image was taken with a NOIR Raspberry Pi camera.
Material Selection Hint: Once I had assembled a HWT, I used it as an IR Reflectance meter (that is what it is). During development, I took the HWT to pet stores, hardware stores and fabric stores. Many items were 'tested'. I examined plastic exercise wheels, the dark materials and the effects on distance from the materials. Doing this I got a sense of the performance and limitations of the HWT. This allowed me to properly locate the plastic wheel in the cage and chose the correct range setting in Calibration mode. Yes, more than once, I did have to explain what I was doing to puzzled store staff.
- How to change range:
- In Calibrate mode, the first display character is the range setting (L,M,S):
- (L)ong range = 1.5 to 5"
- (M)edium range = 1.3 to 3.5"
- (S)hort range = 0.5 to 2" (capital S looks like a number 5)
Note: These ranges depend on target materials and are very approximate.
- To change the range press the Display button. The first display character will change to show the new range.
- To keep this new range press and hold the Display button for 4 seconds. The display will show Savd for two seconds when the action is complete.
Note: The HWT will remember the range settings after reset and even if the battery goes dead.
- In Calibrate mode, the first display character is the range setting (L,M,S):
- Success? If the exercise wheel reflects (display is around 28) and the dark area absorbs (display blanks) you are done. Power cycle the HWT to resume Normal mode (see Step 9: Normal Mode section). Otherwise, change the distance between the HWT and wheel or change the HWT range until you are successful.
Note: Where the HWT is installed on the cage and the calibration of the HWT are related. You may not be able to put the wheel where you want in the cage because that cage location is not in the range of the HWT. The wheel material and the dark area material (black felt) you have chosen also becomes a factor.
Installation on Cage
- Calibrate the HWT and use the Calibration process to inform where you will place the exercise wheel and where the HWT is installed on the cage.
- The HWT can be tied to the side of the cage using the HWT case's mounting holes. I used plastic-coated wire bread ties. Wire ties work also.
- With the HWT installed and the exercise wheel placed, verify the exercise wheel reflects IR light and the dark area absorbs IR.
- If needed, changing the range is described in the Calibration section. A range of distances can be user selected in the HWT. There are three overlapping ranges:
- (L)ong range = 1.5 to 5"
- (M)edium range = 1.3 to 3.5"
- (S)hort range = 0.5 to 2"
- The HWT Sensor housing (IR emitter/sensor) must not be obscured by the cage wire. You may have to spread the cage wire slightly to allow the assembly to poke through the cage wires.
- Verify the HWT records the exercise wheel revolutions correctly (see Step 9: Normal Operation mode).
Normal Operation Mode
- In Normal mode, the HWT counts revolutions of the exercise wheel.
- To enter Normal mode, turn on the HWT using the Power slide switch.
- 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 (capital S looks like a number 5)
- During Normal operation a single display LED segment will flash very briefly every minute.
- Every minute, the count for that minute is compared to the maximum count (the hamster's personal best) from previous minutes. The maximum count is updated if needed. Each minute the count is added to a total count.
- Press and release the Display button to see the wheel counts. The display shows the following:
- Now= followed by the number of wheel revolutions since the last minute check. Note: this number will be added to the total after the next one minute tick.
- Max= followed by the highest number of revolutions. Nugget's personal best since the power was cycled last.
- Tot= followed by the total number of revolutions since the last power cycle.
Power cycling (power slide switch off-on) the HWT will zero all counts. There is no getting those numbers back.
The HWT should run for about ten days on a charge and then the LiPo cell will do an auto-shutdown. To avoid loss of exercise wheel counts, recharge before the auto-shutdown of the LiPo cell.
LiPo Cell Notes:
- LiPo cells store a lot of energy using volatile chemicals. Just because cell phones and laptops use them doesn't they shouldn't be treated with caution and respect.
- The HWT uses a rechargeable Lithium Polymer (LiPo) 3.7v cell. The top of the Adafruit LiPo cells are wrapped with an amber plastic. This covers an integral charge / discharge safety circuit on a small PCBA. The red and black cell leads with the JST connector are actually soldered to the PCBA. It is very nice safety feature having the monitoring circuit between the LiPo and the outside world.
- The HWT will lose power if the LiPo integral charge / discharge safety circuit decides that the LiPo cell is too low. Exercise wheel counts will be lost!
- If the HWT seems 'dead' it probably needs a cell recharge. Connect the HWT using a micro USB cable to a standard USB power source.
- When charging a yellow LED will be visible in the HWT plastic enclosure.
- The LiPo will be fully charged in about 4 - 5 hours.
- The LiPo cell protection circuitry will not allow the LiPo to overcharge, but disconnect the micro-USB cable when the yellow LED goes off.
- As described in the Adafruit #3898 documentation, I had originally intended for the LiPo cell to fit between the Feather #2771 PCBA and the #3130 display PCBA. I found that my wiring in the Feather #2771 prototype area was too tall for the LiPo cell to fit without denting the LiPo cell. That made me nervous. I resorted to placing the battery on its side next to the PCBAs.
- Those red and black wires of the LiPo integral charge / discharge safety circuit do not like being flexed. In the course of development I have broken more than one set of wires. To provide more strain relief, I designed and 3D printed a strain relief. That is the gray block on top of the LiPo cell. It is not needed, but here it is (Public TinkerCad file).
Development History:
Over the three year life of the Nugget project several versions resulted:
1.x Proof of concept and data gathering platform.
Nugget's range of performance was characterized (max RPM, totals, times of activity). In his prime, Nugget was achieved 100 RPM and was able to run 0.3 miles a night. Spreadsheet of data calculations for various wheels attached. Attached also is a file with actual Nugget RPM records stored on the SD card.
- Arduino Duemilanove
- Adafruit #1141 SD card datalogger shield
- Adafruit #714+#716 LCD shield
- OMRON E3F2-R2C4 Retroreflective Optical Sensor
- AC wall transformer (Omron needed 12 volts)
2.x Sensors and hardware explored.
Established the microcontroller and displays:
- Adafruit #2771 Feather 32U4
- Adafruit #3130 14 segment LED display Featherwing.
This combo was chosen for low power consumption (32U4 sleep modes), battery management (built-in LiPo charger) and cost (LEDs inexpensive and lower power than LCD+backlight).
- Hall-effect magnetic and discrete optical pair sensors (i.e. QRD1114 ) were examined. Range was always insufficient. Abandoned.
- Adafruit #2821 Feather HUZZAH with ESP8266 that reported to an Adafruit IO dashboard. More screen time was not what the customer wanted. Abandoned.
3.x Sensor work:
This series also investigated alternative sensors such as using a stepper motor as an encoder similar to this Instructable. Feasible but for low signal strength at low RPM. A little more work would turn this into a viable solution, but it is not a simple retrofit with the existing hamster environment. Abandoned.
4.1 The hardware/software solution described in this Instructable.
5.x More Sensor work:
Examined Sharp GP2Y0D810Z0F Digital Distance Sensor with Pololu Carrier while still using Adafruit #2771 Feather 32U4 and Adafruit #3130 14 segment LED display Featherwing. Worked well. Made code trivial. Used more power than the Vishay TSSP4038 solution. Abandoned.
6.x The future?
- Replace some of the HWT enclosure mounting bosses for the Adafruit #2771 Feather with mounting posts.
- Replace the on/off switch with a push button switch connected to Feather reset.
- The ATSAMD21 Cortex M0 microcontroller, such as found on the Adafruit #2772 Feather M0 Basic Proto, has many attractive features. I would look at this closely on another revision.
- Vishay has a new IR sensor module, the TSSP94038. It has lower current needs and a more defined response.