Redrate: a Device That Helps You Stay Hydrated
by Ian Van Cauwenberg in Circuits > Raspberry Pi
256 Views, 1 Favorites, 0 Comments
Redrate: a Device That Helps You Stay Hydrated
If you're like me, you probably forget to drink enough water. We all know it's important for your health, but sometimes we're just busy and need a reminder. Hopefully this device can help you to build a habit and avoid a dry throat or even nasty headaches.
This project mainly aims to do two things:
- It gives you a sign every time you need to take a sip.
- It tracks how much you've drunk and how much you still need to drink to reach your daily goal.
On top of that it can also keep track of how much you've drunk this week, the current temperature and humidity and it works for any bottle. You can also tweak the settings to your needs.
So how does it work?
Once the device has booted the LED strip will light up red, you can now place any bottle on top and press the button to take that as your baseline. Then surf to the webserver installed on your Pi by giving in the IP address displayed on the screen in a browser. Then tweak the settings to your liking. You can change the following:
- How much time it takes before the LED strip turns red again (notification period)
- How much you want to drink each day (Minimum daily amount)
Then take a few sips every time it lights red and the website will keep track for you! All you need to do is refill the bottle from time to time. Once you reach your daily goal the LED strip will turn blue instead of white.
But how do you make it? Take a bottle of crisp cold water and I'll walk you through it.
Supplies and Materials
load cellHere's all of the components you need:
Raspberry Pi:
- A Raspberry Pi (I used a model 4B with 2GB of RAM) + official USB-C Power Supply + microSDHC card and reader (I'd recommend at least 16GB)
General components:
- A T-cobbler (not strictly necessary, but it does make it easier)
- 2 breadboards (might fit on one without a cobbler) + a breadboard PSU (both 3.3 and 5V!) + a 9 or 12V Universal Power Adapter (1A or more) for your area.
- A bunch of resistors (I used 470, 1k, 2k, 4.7k, 100k Ω) + a 10k Ω potentiometer
- A ton of cables to connect everything (both FTM & MTM). You can never have too many of them ; )
- A button
Tip: Test the breadboard PSU with a multimeter before using. If the voltages aren't reasonably close to 3.3V and 5V you might have a defective one. This way you also won't fry anything if it completely defective and puts out 12V. Personally I had one for which the onboard LED lit up, but neither of the rails put out any voltage or current whatsoever.
Minimum materials:
- Two boards for the load sensor (I'd recommend plywood of around 1cm thick, can be thicker for the bottom one)
- In my case 2 x M4 + 2 x M5 bolts + some matching nuts and washers. Take a good look at the documentation of your load cell because this can be different!
- Materials for a case, I used chipboard and screws, but you can do it in anything really.
- Required tools: soldering iron (+ solder and heat shrink tubing) + wire cutter + wire stripper + anything you need for the case
Sensors:
- A loadcell (I'd get at least one of 2kg if you want to stick to smaller bottles of 0.5 - 1l) + a HX711 to read it
- A one-wire temperature sensor like the DS18B20
- A relative humidity sensor like the HIH-4000-001 + MCP3008 ADC
Now where the action happens:
- Any SM5050 12V standard ledstrip + PSU + powerjack:
- 3 transistors, I used IRLZ34s
- A 16 x 2 LCD (pins will likely need to be soldered on depending on the one you get) + PCF8574 I2C Expander (I used a loose chip on my breadboard, but a breakout board should work the same way).
An extra idea to spice this up, but I didn't use or test these:
- A speaker + amplifier + 3.5mm jack
Underneath is a Excel sheet for reference, but it's mostly for stores local to my area.
Downloads
Setting Everything Up
I hope you got everything you need, because we're about to start!
I've provided some schematics below, both a general schematic and a breadboard one. It might seem confusing at first, but don't worry! I'll try to get you through it.
Start planning how you want your case to look, make sure that all your electronics will fit in it! I've made a very simple and I'll admit not that pretty one. If you want to make something that isn't an eyesore, I've put my original plan further down below. But I have two left hands, so I didn't get around to it.
Wiring the Sensors (part 1)
DS18B20 (temperature)
Tip: make sure one-wire is enabled in the configuration of your Raspberry Pi!
- Connect the GND pin to the ground
- Connect the DQ pin to the GPIO4 pin of the Pi
- Connect the VDD pin to the 3.3V side of your breadboard PSU
- Make sure the DQ and VDD side are connected with a 4.7k Ω resistor
HIH4000-001 (relative humidity)
- Connect the VCC pin (+) to the 5V side of your breadboard PSU
- Connect the GND pin (-) to the ground
- The OUT pin should be connected to both the GND with a 100k Ω resistor and a voltage devider to get the signal down to 3.3V. Here's how to make one:
- Connect the OUT pin to the 1k resistor.
- Make sure there's a path between the 1k and 2k resistor and put a wire on there. This wire should go to Channel 0 of the MCP3008.
- The 2k resistor should be connected to the ground.
MCP3008 (ADC)
The top of the chip is marked with a little notch.
- Connect the Vdd and Vref pins to the 3.3V side of your PSU
- Connect AGND and DGND to the ground
- Connect CLK to GPIO 11 / SPI0_SCLK
- Connect Dout to GPIO 9 / SPI0_MISO and Din to GPIO 10 / SPI0_MOSI
- Connect CS to GPIO 8 / SPI0_CE0_N
- Make sure the humidity sensor is connected to channel 0! You can ground the others if you want to. (but I didn't)
Hooking Up the LCD
Warning: this one is a mess of cables
I inlcluded the general schematic instead of the breadboard one for this reason.
PCF8574 (I2C expander)
Tip: Make sure that the I2C bus of your Pi is enabled
Just like the MCP3008 the top of the chip is marked with a little notch.
- Connect A0, A1, A2 and GND to the ground
- Connect VCC to the 3.3V of your PSU
- Connect SDA to GPIO 2 / SDA1 I2C and SCL to GPIO3 / SCL1 I2C
LCD
- Connect VSS, K and R/W to the ground (since we won't be reading anything from the display we might as well put it on the ground instead so it's always on write mode)
- Connect VDD and A to the 5V side of your PSU
- Connect the potentiometer to 5V on one side and the ground on the other. Connect the middle pin to the V0 of your LCD. This variable resistor can be used to adjust the contrast of the display.
- Connect RS to GPIO 20
- Connect E to GPIO 21
- Now link all DB pins to the corresponding channels of the I2C expander
Hooking Up the LED Strip
Warning: although 12V is generally far from enough to hurt you (simply not enough tension to get through your skin most of the time), you're still working with higher currents (potentially multiple Amps depending on the length of the strip). So don't touch the circuit while it's in operation, you might get a small shock. Only supply the LEDs with the correspending PSU, and like always never connect different voltage sources to each other (only the grounds) or you will fry everything!
- Connect the drain of each MOSFET to the correspending grounds of the LED strip (R, G, B). Depending on the strip you'll need to solder some wires onto it to connect it to your breadboard.
- Connect all of the sources to the ground
- Connect all the gates to the corresponding GPIO pins of the Pi. Make sure to put a safety resistor in between (for example 4.7k Ω)! I put blue on GPIO 13, green on GPIO 19 and red on GPIO 26
- Connect the 12V wire of the ledstrip to the VDD side of the powerjack (+), this also might require some soldering. Connect the GND side of the powerjack (-) to the ground
Wiring + Mounting the Load Cell and Weight Sensor
Start by soldering the wires from the load cell to jumper wires so they become female cables. Most likely your HX711 will also arrive with unsoldered pins, so solder those on with the long side up.
Mounting the load cell
Before the load cell is connected to the HX711, it should be mounted on the two plates. Mark the holes on the bottom plate and drill the holes. This plate will be the bottom of your case so make it as big as you need to. Insert the bolts and put some nuts on them. Screw them securely into the load cell. Check if the little arrow on the side of the cell points to the bottom plate and tighten the nuts. Now make sure the load cell is mounted flush! If not loosen the nuts and bolts and realign! The load cell can under no condition touch the bottom or top plate as that messes with the readings.
Unlike the bottom plate the top plate needs to be light as it counts towards the absolute weight. Certainly don't use any heavy wood for this, but opt for some plywood of around 1cm thick (3d-printing could also be an option). It needs to be light, but not flexible and able to handle the weight on top. Use the same aproach as for the bottom plate. Make sure that the center of the top plate hovers over the center of the load cell to assure the most accurate readings possible.
HX711 (weight sensor)
- Connect DO/RX to GPIO 25
- Connect CK/TX to GPIO 24
- Connect Vcc to the 3.3V side of the PSU
- Connect GND to the ground
Connecting the Load cell to the HX711
- Connect the red wire to E+ and black one to E-
- Connect the white wire to A+ and green one to A-
I hope everything went smoothly so far. Hopefully you now have a close to working prototype, but first we got to make a case.
Make Your Case
I'm gonna be honest with you. I suck at this, so feel free to make your own as it's not really important to the functionality. It only has to meet 3 conditions:
- Have enough space inside for all the components (surprise, I know)
- Have a hole in which the LCD fits in and can be mounted.
- Have a place to mount a button
Since my bottom plate was a square of 32cm x 32cm, I made a front and back plate of 32cm wide and 10cm tall. Then I made the side plates so they fit snuggly between the front and back plate. They come in slightly shorter, because they are mounted on top of the bottom plate, not next to it like the front and back. Cut a hole in the front for the LCD (approximately 8.2cm wide and 3.8cm tall, but this depends on your display) and the button (+- 1cm in diameter) Mounting the former with two small screws and the latter with a nut and some wood glue. Drilled some screws through the back and front into the bottom plate to secure everything. I made one side removable for convenience, while I secured the other with screws to give it some strength. Made a small hole in the back for the three power cables to go through. Make a 'lid' of 32cm x 32cm with a hole for the top plate of the load cell and that's it.
If you haven't already, mount the rest of the circuit in the case.
Downloads
Wrapping Everything Up
I hope you haven't died of thirst by now, but we're almost there.
The code can be found in the following directory: https://github.com/VanCauwenbergIan/Redrate-hydrationdevice
Clone the repository to your Raspberry Pi and make sure it meets the requirements. You can find them in the read me file along with further explanation.
Now:
- Boot the pi, power on the breadboard PSU and plug the LED PSU into the powerjack. . Change the contrast of the LCD with the potentiometer Put them into a power strip for an easy on-off switch. Always do a clean shut down of the Pi first though, unless you like corrupted SD cards. I've provided a switch on the site for that in the settings.
- Hopefully if your pi is connected to your WiFi network it will show it's IP address on the LCD.
- Give that into a browser to surf to the webserver.
- Wait for the LED strip to turn red and calibrate the device with a filled bottle.
- Change the settings on the site to your liking.
- Stay hydrated : )
Thanks for reading! Feel free to ask any questions in the comments.