How many times are you waking up in the night and it seems to hear your libble buddy running and running...and running again?
So it came a simple question: "How far can cover my hamster nightly? Why not to measure it?"
The first idea was using an encoder connected on the wheel, but encoders are too expensive for a such of application ;-) so i thought to hall sensor properties: i could glue some magnets to the wheel and let the Arduino counts how many times the magnets are passing under the hall sensor. That's it!
Basics mathematicsLet's take our school books with elementary formulas that show the irrational relationship between diameter and circumference: C = π x d . This formula could be enough if we use only one magnet, but to have more precision i put 4 magnets so every transition we have to count the division by 4: space = C/4
Choosing the componentsThe Arduino Uno was not a 100% weighted technical choice, i simply already had in my DIY box ;-) and the number of input/output are enough for the purpose.
For the hall sensor module (KY003) i searched a hall sensor with a digital output (easy to count the transitions) that cn be supplied with same voltage (5V) from Arduino Uno board.
For the display, needed to visualise the hamster's progress, i choose a simple and cheap I2C LCD character display module that has 4 lines of 20 LCD characters.
Attached to the display there is a I2C module that convert signals I2C to the 16 pins: it's easier to use only 4 wires (SCL, SDA, VDD, GND). On the I2C module there is a variable resistance to modify the display contrast.
CodingFor this tutorial,it is necessary to download and install the LiquidCrystal_I2C
library. LiquidCrystal_I2C is a library of Arduino which enables serial LCD 20x4 connect with Arduino. To be able to interface the serial LCD with arduino, you will have to download this library and save it into your Arduino's libraries.
To detect the the single magnet transition i can't use a simple if(S == HIGH) {cycle++}
inside the loop because the uC is faster than the hamster :D, so i needed to detect the single transition magnet using 2 states of hall sensor: HIGH (magnet near sensor), LOW (magnet far from sensor). Only a complete transition (from LOW to HIGH and from HIGH to LOW) decide the "+1".
First use glue to attach magnets to the wheel and band together the hall sensor to a wood stick (chopsticks are ok).
When sensor is fixed, take your time to adjust the sensor position moving the wood sticks and keeping the distance between magnet and sensor around 1-2 cm. Pay attention to have the sensor centred on the magnet when it's gettin under. (Fig. 2)
Bread board has been used only to ease to supply two boards: hall sensor and display (Fig. 3). To have more detailed info on connection look at the Fritzing schematics
To avoid waisting energy and to limit bothering the hamster's nightly run, i added a timer in order to switch off the display if the wheel is not in use. So after every magnet transition display is lighted for 5 seconds and then it has been switched off until next transition.
Have fun!!
Next stepsI'm working on a version 2.0 of hte project where the hamster's progress is logged into a database. With the database you could know when is mostly running duting the night.
Stay tuned!!!
Comments
Please log in or sign up to comment.