📜 ⬆️ ⬇️

Mouse Wheel Speed ​​Counter

I must say that the post about the wheel speed counter squirrel I have already read. I had a similar task for a long time - it was curious how much my little mouse (normal, live, not computer!) Runs and with what speed.

image

Only I decided not to reinvent the wheel and took the old unnecessary speedometer from the bike, which ideally performs these functions.
')
For a month, the mouse ran for about 100 km, but I wanted to know in detail - how many exactly did he run on each of the days, at what time of the day is he more active, how does his activity change during his life? The speed I was already slightly worried - it is almost always 1-1.5 km / h. 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, yes a reed switch that counts wheel revolutions, but the cell often moves around the room, so the option with wires disappears immediately. I also didn’t want to mess with the radio, and the necessary components were not at hand. And then it dawned on me - I already have a self-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 parts, you do not need anything extra except the IR LED.

As a microcontroller, I took ATMEGA8A, which I am used to. First of all, the question arose - would she have enough power, and how quickly would she put the battery in? Immediately I started watching the datasheet - the eighth “mega” with the “A” index can work with a wide voltage range of 2.7V-5.5V, which allows using a battery like CR2032 or CR2025. The current consumed in the deepest sleep mode is only 0.5 micro amperes. A microcontroller can wake up from this mode by using external interrupts INT0 and INT1, to which I decided to hang the reed switch and a single button, as well as an asynchronous timer, which will be needed to periodically send data. For the latter, it is necessary to set the external quartz to 32768 Hz, at the maximum divider the microcontroller will wake up every 8 seconds, which is rarely enough. I decided to send the data about once every three minutes.

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

This is how a very simple device gradually acquires a bunch of components. It is also necessary to forget the usual LED. Having understood all this, I quickly sketched the device board:

image

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

image

image

I decided to put two batteries in there at once, they fit in perfectly.

Once installed on the cells, it looked something like this:

image

I decided to install this case on a height, so as not to accidentally block the back of the chair. The important point is to protect the wires from mice.

Then it was up to writing software. With the firmware everything was quite simple - the device should almost always sleep. By external interruption to add momentum. To interrupt the timer, count the time, every three minutes, send the number of revolutions passed and save it to the EEPROM (will I suddenly pull out the battery?), And when the button is pressed, do it right away - for checking.

For data transmission, I took the most common remote control protocol, RC-5, for which I already had code for both the receiver and the transmitter (commanded by the TV / receiver from a computer), it transmits four bytes of data. To me, this is exactly: one byte is the number of the wheel / battery, two bytes is the number of revolutions / voltage on the battery, and one byte is the checksum. To distinguish my signals from the signals of the consoles themselves, I only changed the duration of the starting signals.

Slightly finalized my software on a PC and ...

image

The data from the mice have already gone :) Then it remained to write only a few bash-scripts to send them to the server. For processing and drawing graphs, I took RRDtool already familiar to me:

image

On this graph you can see how many meters each of the mice ran at intervals of one hour. They are now competing with me :) The voltage on the batteries stopped falling rapidly after increasing the resistor rating on the divider and wiping the board off the flux :)

Actually graphics: clusterrr.com/sensors/w
Battery voltage charts: clusterrr.com/sensors/v
Endomondo account Pinky Mysh: www.endomondo.com/profile/8088037
Twitter mouse Pinky: twitter.com/pinky__mouse = Oo =
And his contact : vk.com/id185163744

Pinky sends you hello to all:

image

PS Jokes about generating electricity at the expense of mice, I was already pretty bored, every first one tells me about it.
PPS I'm not crazy, I am having so much fun.

Source: https://habr.com/ru/post/165269/


All Articles