I knew sitting all day was an issue many of us deal with during the Shelter-in-Place order. As it's been said "We look at the big screen at night to reward ourselves from staring at the medium screen all day, while we're distracted the whole time by our little screens." Home electronics provide great entertainment for many of us, but it doesn't require much more than passive sitting to enjoy.
The tremendous amount of sitting we do is creating recognizable damage to our cardiovascular health. Fortunately the decline is easily prevented and many hours of sitting can be offset by taking intervals of a few minutes at a time to get up and be active. This is what the Sit Minder aims to assist with.
What it does
The Sit Minder uses the ESP32 to create a local server. That server operates as an IoT switch which then triggers a microcontroller-based timer. When the timer is up, the board's "annoying sound" event triggers if you are too close to the IR proximity sensor. To make the Sit Minder effective, the IR proximity sensor should be facing you at your seating place. A large 7 segment LED allows you to see from afar how much time remains (prototyped in seconds, ideally would be in minutes). Once the countdown is completed you may return to your chair and start the timer again when you're ready.
How I built it
Component Testing: I first started with learning how to connect the ESP32 to the internet. Once I ran an example of how to host a local web server, I decided it was operable for my goal.
I then tested the OLED. After about an hour I had that component's given example working.
I then watched the IR LED Proximity sensor video on IDEA Hack's resource page and was inspired to incorporate it into the design - this was where the Sit Minder idea really took off. I created a test code which printed the raw ADC values of the IR photocell to understand it's operation better.
I then tested the Piezo speaker, referencing the ESP32 example for "AnalogOut" codes for how to send a tunable frequency PWM signal.
The final component was the Seven Segment LED Display. I initially thought any of the ESP32 pins were re-programmable as GPIO pins, but learned that was not the case after a few hours of trouble shooting. Once I worked on only GPIO dedicated pins, the display functioned properly.
Assembly: Once I felt confident with each component, I created a mental flow diagram to determine how they could work together to make an effective product. I refined the Sit Minder idea and after deciding the course of it's operation I began programming it.
I had some background in timing and triggering with Arduino's millis() function, which allowed me to carry out operations like refresh the OLED with the timer countdown while the ESP32 was checking for a flag indicating the time had expired.
Challenges I ran into
I did my best to avoid incorporating any of my personal electronics in this besides my laptop. I nearly managed to do this but I ran out of PCB space, so I resorted to grabbing a PCB I had spare.
The Seven Segment LED display initially only had a dim light on the center segment, even though I had correctly noted each pin in the code and set them to their proper digital state. I found out that not only did I connect to pins which are not programmable (falsely advertised) but I also had to specify the pinMode() of each pin leading to the display.
On Friday evening into Saturday morning I spent a good 3 hours working to get the PDM microphone functional. Unfortunately those efforts were in vain, but I did take a nice refresher through FIR filter theory and I made a note to go back to that in order to manually get the PDM mic to work. I also saw in the ESP32 technical reference that there is a PDM setting in the I2S driver library, but without knowing how to address the registers in Arduino's IDE I didn't get very far.
My final hiccup was in getting the IR proximity sensors to trigger the annoying sound of the piezo. It may be for the best at this point, as it's 6 AM and I'm sure my significant other would be pretty mad to hear that going off right now. It may be due to the function calling within a function while in a while loop and also constantly updating time. This is where an interrupt would be preferable (Hardware trigger based on analog reading), but I didn't explore setting up interrupts in Arduino IDE in the time I worked on this.
Accomplishments that I'm proud of
The display of the IP address on the OLED is one thing I'm particularly proud of working out - as it frees me from constantly having the serial monitor open and truly makes this an IoT device.
What I learned
This was my first time working with an I2C device and also creating so much code via Arduino IDE for a non-Arduino microcontroller. I found the access to ready-made libraries very useful, although I wish there was a more straightforward C or C++ approach, as there were moments I was hoping I could directly access registers but I did not know of a way to do that in the Arduino IDE.
A fellow hacker told me about BootStrap, which provides a quick set of code templates for building a website in HTML. I will definitely have use for this in the future.
What's next for Sit Minder?
I will let some friends know about it as an idea and see if they are interested in carrying it forward. I would love to learn how to develop a better website for it so that a person can enter their preferences for a "sit time" and "activity time". The website could also provide suggestions for ways to be active so the person can feel inspired. I would also invest in a better IR sensor or devise another monitoring device that can trigger annoying sounds.