Mouse Wheel Speed ​​Counter

    I must say right away that I already read a post about a wheel speed counter with a squirrel . A similar task confronted me a long time ago - it was curious how many my little mouse (normal, live, not computer!) Runs and at what speed.


    Only I decided not to reinvent the wheel and took an old unnecessary speedometer from a bicycle that perfectly performs these functions.

    For a month, the mouse ran about 100 km, but I wanted to know in detail - how much did he run on each day, what time of day is he more active, how does his activity change throughout life? The speed, on the other hand, worried me a little - it was almost always 1-1.5 km / h. A typical pointless, but interesting task, as I like.

    For all this, the data from the cell must somehow be sent to the server. In theory, everything is simple - you need a microcontroller, and a reed switch counting the wheel speed, but the cell often moves around the room, so the option with wires disappears immediately. I somehow didn’t feel like messing with the radio either, and the necessary components were not at hand. And then it dawned on me - I already have a home-made remote control receiver, which is visible from anywhere in the room and connected to the network of my "smart home" - so why not use IR signals? Of the details, nothing more is needed except the IR LED.

    As a microcontroller, I took the familiar ATMEGA8A. The first thing that came up was whether she had enough power, and how quickly did she put the battery down? Immediately I began to look at the datasheet - the eighth “mega” with the “A” index can work with a wide voltage range of 2.7V-5.5V, which allows you to use a battery like CR2032 or CR2025. The current consumption in the deepest sleep mode is only 0.5 microamps. The microcontroller can wake up from this mode by means of external interrupts INT0 and INT1, on which I decided to hang the reed switch and a single button, as well as by the asynchronous timer that will be needed to periodically send data. For the latter, it is necessary to set the external quartz at 32768 Hz, with the maximum divider, the microcontroller will wake up every 8 seconds, which is quite rare.

    I would like to somehow control the battery level, so I decided to use also an analog-to-digital converter to measure voltage. ATMEGA8 allows you to measure it relative to 2.56 volts. Using a voltage divider from two identical resistors, you can get exactly half the voltage that we have on the battery, and we will measure and send it every half hour.

    This is how a very simple device gradually grows into a bunch of components. It is also necessary not to forget the ordinary LED. Having comprehended all this, I quickly sketched the device board:


    Soon the device itself was ready in two copies (I have two cells and two mice):



    I decided to stick two batteries there, they fit perfectly there.

    After installation on the cells, it looked something like this:


    I decided to install this business on a hill so as not to accidentally obscure the back of the chair. The important point is to protect the wires from mice.

    The rest was the writing of software. With the firmware, everything was quite simple - the device needs to almost always sleep. By external interruption, add speed. By interrupting the timer, take the time, send the number of revolutions passed every three minutes and save it in EEPROM (what if I suddenly remove the battery?), And when I press the button, do it right away - to check.

    For data transfer, I took as the basis the most common protocol for remote controls - RC-5, for which I already had a code for both the receiver and the transmitter (command the TV / receiver from the computer), it transmits four bytes of data. This is just for me: one byte is the wheel / battery number, two bytes is the number of revolutions / battery voltage and one byte is the checksum. To distinguish my signals from the signals of the consoles themselves, I only changed the duration of the start signals.

    I modified my software on the PC a bit and ... The data from the mice has already gone :) Next, I only had to write a few bash scripts to send them to the server. For processing and drawing graphs, I took the familiar RRDtool:



    This graph shows how many meters each of the mice ran in one hour intervals. They now compete with me :) The battery voltage ceased to fall rapidly after increasing the nominal value of the resistors on the divider and wiping the circuit board from the flux :)

    Actually graphs: Battery
    voltage graphs: v
    Endomondo Pinky mouse account:
    Pinky mouse twitter: = Oo =
    And his contact person :

    Pinky sends hi to you all:


    PS Jokes about generating electricity from mice I'm already pretty tired of it, every first one tells me about it.
    PPS I'm not crazy, I'm having so much fun.

    Also popular now: