Need help drinking more water? This bottle beats dehydration*

Alexandre Boutoille
The Innostation Publication
5 min readJan 31, 2023

Water is the second most crucial part of life (the first is water) and our bodies are made of 60% water. Yet, 22% of Americans don’t drink the recommended 10 glasses of water per day. The average American only drinks about 5 glasses per day source. This can cause dehydration leading to potential fatigue, sluggish bowel function, persistent headaches and more.

r/HydroHomies

Dehydration is a broad spectrum, it’s not when we are walking in a seemingly endless desert with dream-like hallucinations of an oasis.

Only about 0.6% of the American population does not have access to clean drinking water so we can eliminate that from being the reason that many don’t drink enough. We also can eliminate the lack of information access as a possibility as most people have a computer capable of web browsing. That leads me to think that it’s out of laziness. For me, it’s much easier to remember to drink water when my water bottle is right beside me.

Setting up the project

To solve this problem of humans not drinking enough water there are reminder-based systems. The Spark by Hidrate sends reminders to your phone over BLE. I’ve my own version of a reminder-based water drinking bottle.

To build it I used:

  • 500ml water bottle
  • Resistive moisture sensor
  • 1 x 3 Dupont cable
Wiring Diagram

The brain of the operation is a Raspberry Pi 4. It’s in charge of reading the data from the sensor, processing the data, and sending the output over the network to the client.

To build it make an incision on the side of the bottle near the bottom about the width of the moisture sensor. Try using a hot knife to get a clean cut around the plastic. PET melts at around 260 ºC. Then use hot glue to make a water-tight seal around the sensor and the bottle.

The resistive moisture sensor is plugged into pin 4 for 5V, ping 6 for ground, and pin 8 GPIO14 for the UART connection (receive is Tx).

Now time to bake that Pi! Flash the microSD card with any arm Linux distro, I used Raspbian. Pro tip: for a headless install, ctrl+shift+x opens a “secret menu” where you can add your ssh key, configure networking by adding your Wi-Fi SSID and Password, and add a non-root user. Then put the microSD card into the Pi and turn it on. You may want to set up a static IP to make sure your water bottle always has the same IP address. You can do this by defining an address outside of your DHCP range in this file “/etc/dhcpcd.conf”, or by adding a DHCP reservation.

Now ssh into your Pi and make sure you have Python 3.x installed. If not then install it. Now make a new directory and name it

cd water-bottle

Now let’s make a new file. I’ll be using my favourite text editor to do

nano moist-scirpt.py

No inside of the file you can copy in this code

import RPi.GPIO as GPIO
import time

#setup GPIO
sensor = 14
GPIO.setmode(GPIO.BCM)
GPIO.setup(sensor, GPIO.IN)

def callback_function(sensor):
if GPIO.input(sensor):
print ("Alex is out of water :(")
else:
print ("Alex has water :)")

GPIO.add_event_detect(sensor, GPIO.BOTH, bouncetime=1000)
GPIO.add_event_callback(sensor, callback_function)

while True:
time.sleep(0)

Let’s break down this code into simple steps, to understand what it does.

import RPi.GPIO as GPIO
import time

This adds the libraries we’ll need for this project to function. RPi.GPIO is for the GPIO (general purpose input/output) of the Pi, and the time library is for adding time.

sensor = 14
GPIO.setmode(GPIO.BCM)
GPIO.setup(sensor, GPIO.IN)

The first line tells the code that when we write “sensor” it means 14 as in GPIO14. Next, we tell it to set up the pins referring to the Broadcom SoC. At the bottom, we tell the sensor to listen on GPIO14.

def callback_function(sensor):
if GPIO.input(sensor):
print ("Alex is out of water :(")
else:
print ("Alex has water :)")

Out function checks that if the sensor is NOT detecting moisture it prints “Alex is out of water :(“. Else it prints “Alex has water :)”.

GPIO.add_event_detect(sensor, GPIO.BOTH, bouncetime=1000)
GPIO.add_event_callback(sensor, callback_function)

This code tells the code to check the state of the sensor every second and when a change is detected it runs our function from above.

while True:
time.sleep(0)

At the bottom, this bit just loops the code infinitely.

To save the code (if you’re using Nano) hit ctrl + x to exit, y to save, and then enter to save the name.

Using your water bottle

Fill your water bottle with water and then run your script make sure you are still in the directory you created and run:

python moist-scirpt.py

*replace moist-scirpt.py with your filename

When you finish drinking your water the script will output “Alex is out of water :(“ in your terminal. Then when you fill it back up it will output “Alex has water :)”.

Note to self: add gif of drinking water from the video

Conclusion

By building this project I was able to learn a lot about connecting GPIO devices to a Raspberry Pi and integrating them into my python script. Here’s what I would change if I were to improve it:

Battery

  • When using this water bottle it had to be tethered to the wall to provide power to the Pi. Water bottles are practical because you can move while being hydrated. So a battery powering the Raspberry pi through the GPIO pins, the PoE header, or the USB C port with a portable battery.

Notifications

  • Solutions like the Hidrate Spark have a notification system that reminds you to drink water. My water bottle could implement a notifications system by using the Telegram API. To learn about the Telegram API I could potentially use it in a future project.

If you’ve enjoyed this project and want to learn more, here is my video!

Hey there! Thank you for reading my article. I’m 15, passionate about IoT and an activator at the Knowledge Society (TKS).

Want to chat? Reach out to me on LinkedIn

Want to know what I’m doing? Here is my newsletter

--

--