Immerse yourself in the technical intricacies of developing firmware that empowers a smart water bottle with a wide range of functionalities. This bottle’s purpose extends beyond merely tracking the user’s hydration level; it also timely reminds them to replenish their water intake. Equipped with a microcontroller and sensors, the bottle collects water consumption data and interacts with the user via a mobile application. While a detailed functional overview of this solution can be found here, this blog post will focus on the development of firmware for the embedded microcontroller – the software that orchestrates all processes within the bottle.
Firmware-Driven Key Features of the Smart Bottle
Our smart water bottle is equipped with a range of features, intricately woven into its firmware. While its primary function is to maintain a consistent connection with the mobile app, its capabilities extend further. The bottle is smartly designed to autonomously operate for up to seven days when out of range or disconnected. During this period, it continues its core function of monitoring water levels and logging drinking activity. When the bottle re-establishes its connection with the app, it efficiently uploads all the data it collected during the disconnected period, ensuring users stay updated on their hydration habits without missing a beat. The firmware’s intelligence shines in its ability to distinguish between different user interactions—whether it’s drinking, opening the lid, or even if the bottle is accidentally tilted in a bag. By doing so, it avoids triggering unnecessary reminders and maintains an accurate log of the user’s water intake, ready to be synced with the app at the next opportunity.
The usability of any smart device hinges on intuitive feedback, and in our smart bottle, LED indicators play a pivotal role. During the firmware development, we focused on making these LED notifications not just informative but also intuitively understandable. Each light signal is fine-tuned to convey a distinct message regarding the bottle’s current status or action. A green light denotes full charge, an orange blink indicates charging, and white flashes signal successful water level detection. These indicators are designed to assist users in effortlessly understanding the bottle’s status, even when the app is not actively in use or the phone is in a different room.
Moreover, the firmware is adaptive to the user’s environment. In night mode, LED brightness is thoughtfully adjusted or turned off to prevent sleep disruption while maintaining the essential reminder functionalities. The transition of the smart bottle into night mode is implemented through two methods: a manual activation via the mobile app and an automatic shift based on the bottle’s internal clock during user-defined hours, such as from 10 PM to 6 AM.
Smart Bottle Behavior Detection Functions
In this chapter, we delve into the key aspects of how sensors and algorithms enable the bottle to understand and adapt to user interactions.
Lid Opening Detection
We start by exploring how the firmware detects the moment the lid is opened, marking the first step in the bottle’s interactive process. This is achieved using an integrated Inertial Measurement Unit (IMU), which tracks the tilt angles and acceleration associated with the movement of the lid. The IMU is configured to respond to an acceleration of 1.4g, which corresponds to the user lifting or flipping the lid. The sensor actively monitors changes in the lid’s position every 100 milliseconds. This allows us to quickly and accurately determine whether the lid has been opened. If successful, the system progresses to the next phase – detecting the drinking action. To ascertain the state of being “open” or “closed,” the firmware analyzes the lid’s opening angles, which must meet specific parameters: x:90°±45°, y:110°±45°, z:20°±100°. If the angle values fall within this range, the lid is considered open, and the firmware initiates the next monitoring cycle – water level measurement. If no angle changes indicating lid opening are detected within 1.8 seconds, the system reverts to sleep mode to conserve battery power. This approach ensures efficient energy use of the bottle, contributing to a prolonged battery life.
Detecting Drinking and Water Pouring Actions
Next, let’s discuss the process of determining whether drinking or water pouring is occurring. This is a crucial firmware function that differentiates various types of user interactions with the bottle: drinking, pouring water, and simply opening the lid. Once the user opens the lid, the cap “wakes up,” activating the lid opening detection feature. If the tilt speed exceeds 85° within 180 milliseconds, or if the distance measured by the ToF (Time of Flight) sensor, which calculates the time taken by a light signal to hit an object and return, is greater than 130 mm, the firmware decides that water pouring is taking place. ToF sensors are widely used in applications like smartphone cameras for autofocus functions and in devices like the Apple Watch for heart rate monitoring.
Logic for Determining Water Level
The firmware analyzes data from the ToF sensor and decides on the event that occurred:
- If the new water level is more than 20 mm higher than the previous level, a “water filling” event is registered, and data are sent to the app.
- If the new water level is lower than the previous one, but no pouring or drinking actions were detected, the event is not registered, and no data are sent.
- If the water level changes slightly within the permissible tolerance and pouring or drinking action is detected, the event is also not registered.
- If the water level decreased compared to the previous measurement and pouring or drinking action was detected, the data about the event and water level are updated in the app.
Re-reading Algorithm and Sleep Mode
After the lid is closed and if there are no additional actions from the user within approximately 10 seconds, the firmware determines whether to send data to the app, based on its connection. If the bottle cannot obtain useful data from the ToF sensor within a certain time, it repeats reading attempts every 5 seconds for a maximum of 40 seconds. In case of failure, the system enters sleep mode to preserve battery charge and avoid unnecessary energy consumption.
Energy-Efficient Algorithms for Smart Water Bottle
In developing our smart water bottle’s firmware, one of our most important goals was enhancing energy efficiency to prolong battery life on a single charge. This segment will take a closer look at the key facets of our approach that substantially bolstered the device’s energy management.
Adaptive Microcontroller Energy Management: The microcontroller is fine-tuned to automatically alternate between various energy consumption modes. This includes a deep sleep state and a lowered processor frequency during low activity phases, ensuring optimal energy use tailored to the device’s immediate requirements.
Energy-Efficient Sensor Operations: Key sensors like the accelerometer and ToF sensor are configured to operate in a low-power mode. They activate only when essential for performing measurements, contributing to a reduction in the bottle’s overall energy usage.
Interrupt-Based Active Time Reduction: Our strategy involves using interrupts to prompt the microcontroller into action only for significant events. This approach significantly decreases the duration of active operation, thus conserving power.
Using PWM for Brightness Control: To adjust the brightness of the LEDs, we employ the Pulse Width Modulation (PWM) method. This technique allows the microcontroller to rapidly switch the LED on and off at a high frequency, altering the duration of the LED being on relative to its off time. This creates the effect of changing brightness without physically altering the LED’s light output.
Optimized BLE Module Usage: The Bluetooth module within the bottle is programmed for energy-saving operation. It activates primarily for short bursts of data transmission, which plays a crucial role in lowering the overall energy expenditure. Regarding Bluetooth Low Energy, we encourage you to visit a specific blog post dedicated to this project. In it, we thoroughly detail our approach to enabling communication between this smart device and a mobile application through the BLE communication protocol.
These strategic implementations ensure that the smart bottle not only sustains prolonged usability on a single charge but also upholds its functionality and ease of use for the consumer. Importantly, these energy-saving innovations also aid in reducing the environmental impact by cutting down on the frequency of charging.
Partner with us
Are you looking to implement a solution that requires firmware development for smart devices? You’ve come to the right place! Our team of skilled firmware developers is capable of handling projects of any complexity, whether it involves modifying existing firmware from an IoT device manufacturer or creating entirely new firmware from scratch. Moreover, we can design and produce a custom printed circuit board for you if you’re developing your own smart device.
Let’s explore how we can assist you. Contact us today to start the conversation!