Low-power table football game detector

I never used an Arduino or a Raspberry Pi before. This is my first project of this kind.

At work we have a table football that is used quite intensively.

I would like to tape up a device hidden below it that would record when games are played. Then, in 6 months, when I would have accumulated enough data, I will publish a statistical analysis of our office's table football activity.

I'm thinking of two ways to sense whether a game is currently played or not: capt vibrations using an accelerometer or record sound (it would be very easy to detect the sound of the ball shocks).

I much prefer the first solution for 2 reasons: (1) lower frequency, so cheaper to store/transfer, (2) I am not recording my colleagues' voices, which could be considered illegal. Also, I imagine an accelerometer uses less power than a microphone, but that might be false.

I am concerned about the power supply of the device. I would like to record for months, without having to recharge the battery too often. I'm willing to buy an external battery, like a TeckNet PowerZen 16750mAh, but I'm not even sure that can be used to charge an Arduino.

So, I have many questions unanswered and I need the experts.

How would YOU do it?

I think one of these vibration sensors would work. You could initially make a temporary measurement unit and take readings of the vibration levels at various places on the table to see what works best and doesn’t give you false triggers.

Srijal97:
I think one of these vibration sensors would work. You could initially make a temporary measurement unit and take readings of the vibration levels at various places on the table to see what works best and doesn’t give you false triggers.

Great. Someone one reddit told me “You could probably do it with an esp32 and a couple piezo detectors. That would give you longer battery life.”. What do you think about esp32 for my case?

Why would I want to have several piezo detectors rather than one?

At moments when the table is not being used, no one touches the table. How could it possibly give false positives? (just wondering)

Thank you for your answer. :slight_smile:

Yes, using an esp8226 (esp32 isn't really required here, though it would work too), would be a good idea. Once it gets connected to the internet via WiFi, you could send the piezo triggers to a web script written by you and do all kinds of things with all that data. So it would be wireless and can be made into a low power system.

At moments when the table is not being used, no one touches the table. How could it possibly give false positives?

The vibration level isn't actually a binary value, it is a range of levels based on the amount of vibration present. So when a person walks near the table a slight vibration may be transmitted through the table legs to the sensor. More so, if someone jumps near it? Maybe someone is wearing heels? Maybe someone bumps into the table? You just need to measure all the different cases and see what level of vibration, and the frequency with which it occurs would most accurately define the state of a game being played on the table. More sensors placed at different locations on the table would just help you make these predictions accurately. In your case, I think one sensor would be enough, maybe add an extra one later if you feel like it.

Srijal97: Yes, using an esp8226 (esp32 isn't really required here, though it would work too), would be a good idea. Once it gets connected to the internet via WiFi, you could send the piezo triggers to a web script written by you and do all kinds of things with all that data. So it would be wireless and can be made into a low power system.

Perfect. Thank you for all that info. About the "can be made into [...]": how would you make it a low power system? What kind of battery should I use? Are you able to estimate how long the battery would last?

Srijal97: The vibration level isn't actually a binary value, it is a range of levels based on the amount of vibration present. So when a person walks near the table a slight vibration may be transmitted through the table legs to the sensor. More so, if someone jumps near it? Maybe someone is wearing heels? Maybe someone bumps into the table? You just need to measure all the different cases and see what level of vibration, and the frequency with which it occurs would most accurately define the state of a game being played on the table. More sensors placed at different locations on the table would just help you make these predictions accurately. In your case, I think one sensor would be enough, maybe add an extra one later if you feel like it.

Thank you for all the details! You rock. I'm a machine learning researcher: if I'm not able to build a simple statistical model that tells whether the piezo signal over a given time window corresponds to a table football game or not, I pretty much suck at my job!

mergejoin: What kind of battery should I use? Are you able to estimate how long the battery would last?

I bet that you can. Make the device and attach your battery. Let it run. Monitor the run time and battery voltage. Use this to guestimate how log the battery will last. Use this to set a schedule on when you will need to change the batteries.

If I were working on this project, I would want 2 of the rechargeable batteries. That way on battery changing day, you could unplug the spent battery and plug in the charged battery. Very little down time.

Have you considered putting in a RTC for this? without it you are stuck using micros() for timing. Good for small duration events, but it drifts too much over long term. A real time clock gives much more accurate time info. You could then log events like start playing or end playing with actual date/time values to help with data analysis later.

Have you considered how you will be storing the data or transferring it to your PC for analysis? I would think that a microSD card or similar would do the trick. Again, with 2 of them. On battery changing day, you remove the filled card and put in a properly prepared/formatted card. The arduino powers up and starts logging to the new card. You take the old card to your PC, load the data and then prepare the card for the next battery change cycle.

Low power means putting your Arduino to sleep most of the time. Same for the ESP8266 solution. When awake and active they suck dry your battery in a few days.

This one is supposed to be monitoring pretty much constantly, so the best you can do is let it sleep for say a second at a time, then wake up, measure activity, go back to sleep. Maybe extend that to every 5 seconds, depending on how precise you want it to be. Game play is going on if 2, 3, maybe 4 subsequent samples are "high". That filters the bumps and walks.

Processor: I'd go for the ESP8266 for it's huge memory (4 MB) compared to the Arduino (16 kB), and the SPIFFS ability (basically a file system in flash - up to 3 MB of storage, makes for a lot of storing). Then maybe once a day or once a week have the ESP upload that file in one go to your web server for analyses. That way you minimise WiFi activity, which takes a lot of power. During normal measurements you can keep WiFi disabled.

You're going to need a real time clock to have any idea of what hours of the day the games are played (even with the ESP which can get time from Internet, but that takes a lot of power: it has to wake up the WiFi, connect to the router, connect to NTP - that's 10 seconds easy of high-power WiFi activity). This can also help you to go to sleep when your office is closed, until the next morning, for extra power savings.

Those are some good suggestions. Though instead of waking every time and checking the sensor, would it be possible to use some external circuitry to send an interrupt to the esp and wake it up only when triggered? I was thinking of some kind of comparator, but that too should not consume much power. Any ideas?

You could use an old-fashioned tilt sensor, used in pinball machines or so, that make (or break) a contact when the machine is handled too roughly. Such a sensor can be used to wake your device and doesn't use any power until triggered. But then it'll be awake until the movement stops long enough.

You should be able to do this with a regular Arduino which would make the programming easier than using an ESP8266.

You have not said how much data you will want to record - over 6 months the quantity could mount up and you may need to use an SD Card. But do some calculations to see if you could squeeze the data into the Arduino’s onboard EEPROM memory.

For very low power consumption just build an Atmega 328 chip (as used in an Uno) on a piece of Veroboard (stripboard) and have the chip spend most of the time asleep. Use the watchdog timer to wake it up at intervals. By using the Atmega 328 on its own you are not wasting energy on other items on an Arduino Uno board.

Whatever hardware you use if it checks the state of play once every 5 minutes it would probably capture all uses of the table football game with sufficient accuracy.

As someone else mentioned an RTC module seems essential. I haven’t used one, and maybe it can arranged to wake up the Arduino.

…R

Some RTC modules have an "alarm clock" function that can send a wake up signal.

An Arduino's EEPROM has just 2048 bytes, not likely you can squeeze 6 months of data in that. A timestamp is 4 bytes already.

vinceherman: I bet that you can. Make the device and attach your battery. Let it run. Monitor the run time and battery voltage. Use this to guestimate how log the battery will last. Use this to set a schedule on when you will need to change the batteries.

I could do that but then I would need to first buy the battery. I want to do an estimation before buying the battery, to know which battery I want to buy.

If I can send the data over the network as it is being collected, then I can store it on a server and don't need to have a storage module on the device itself. Plus, I get to have real-time (with quite some latency due to the low frequency of collection) information about whether a game is currently being played or not. I am in a pretty big office, this information is very valuable for my colleagues and I, to know whether the table is available or not.

I haven't decided the frequency at which I want to store the data. I would like the data to be accurate enough to be able to measure the average duration of a game.

But of course, this is a trade-off. If being able to have live data and more accurate data means that I have to change the battery every day, I'm willing to give up live data and accuracy.

I am willing to change the battery once/twice a week.

The RTC module is a good point. Timestamps are essential for my statistical analysis.

Also, recording data on week-ends or between 10PM and 8AM on working days would be useless. Putting the device to sleep at those times makes total sense.

I'm starting to get lost with all those references to boards. I am not sure which set of components I should use now!

mergejoin: If I can send the data over the network as it is being collected, then I can store it on a server and don't need to have a storage module on the device itself.

As I said before, the ESP has lots of memory built in (no extra modules needed), and network communications take a lot of power - for the WiFi and keeping the device awake for an extended time. Using that storage and limiting the network communications to once a day (say 22:00 before going to extended sleep) can save you lots of battery.

wvmarle: As I said before, the ESP has lots of memory built in (no extra modules needed), and network communications take a lot of power - for the WiFi and keeping the device awake for an extended time. Using that storage and limiting the network communications to once a day (say 22:00 before going to extended sleep) can save you lots of battery.

That makes sense. I can transfer the data to a server every day, before going to sleep.

Regarding the RTC module. Maybe I can use the NTP protocol once a day (at the same time I transfer the data) to synchronize the internal clock? That way, I don't need an RTC module. I read this blog post, http://www.instructables.com/id/TESTED-Timekeeping-on-ESP8266-Arduino-Uno-WITHOUT-/ which gave me this idea.

mergejoin: I'm starting to get lost with all those references to boards. I am not sure which set of components I should use now!

Get an esp8266 development board, the sensor and start working on it. Make changes to your plan as you go ahead, you can add/subtract modules later. Even if you decide to switch to something different, it won't be a blow to your wallet since these are relatively cheap.

Once you have a basic setup working, you can take current measurements to determine what power saving plan and battery capacity you should use to get an estimated run time.

mergejoin:
Regarding the RTC module. Maybe I can use the NTP protocol once a day (at the same time I transfer the data) to synchronize the internal clock? That way, I don’t need an RTC module. I read this blog post,

NTP works great, using it myself normally, but the internal clock stops ticking in deep sleep mode. I haven’t used the sleep options myself, there are different stages, maybe a not-so-deep-sleep keeps it ticking. You can also have it get time over NTC upon startup (after complete power down) and use it to set the RTC.

The RTC can also be used as wake-up timer, some models at least, there are many different parts out there.

Hi,

Just a thought, a magnet placed on a couple of the rods or players feet, and a hall effect or reed switch, to detect the playing of the game. No vibration to detect, just good old HIGH/LOW digital signal.

Tom... :)

wvmarle: The RTC can also be used as wake-up timer, some models at least, there are many different parts out there.

Ah, that's true. I actually need the RTC module to make the device go to sleep and wake up at the right time. Those RTC modules have their own battery: they are still keeping track of the time when the device itself is asleep.

Can anyone recommend a good RTC module I can plug to my esp8266?

I'm planning on using micropython on the esp8266.

I found the ds3231 RTC module, for which there's already an example of how to interact with it in micropython on GitHub: https://github.com/peterhinch/micropython-samples/blob/master/DS3231/ds3231_pb.py

Is this a good choice?

Also, I'm not sure which esp8266 I should buy. I found two:

Any advice?

TomGeorge: Just a thought, a magnet placed on a couple of the rods or players feet, and a hall effect or reed switch, to detect the playing of the game. No vibration to detect, just good old HIGH/LOW digital signal.

I love this idea. However I don't really know how a hall effect sensor or a reed switch would work. From what I read, I understand they are triggered when a magnet is nearby, but I feel like it needs to be really close. However, I plan on sticking the device below the table, like this:

|500x408

Would that work for the kind of detectors you are talking about?

I'm using nodemcu boards and barebones ESP-12 modules. No experience with those two boards.

For RTC those DS types are popular in the Arduino world, and in what what works with an Arduino usually works just fine with the ESP. Should be a safe choice.