Hydration Alert with CHARGE Power Pack
Introducing 💧Hydration Alert 🚨
Oftentimes we can forget to drink enough water throughout the day, which can lead to dehydration, tiredness and other health problems. We can combat this by setting ourselves a little reminder to take a drink every so often.
What you need:
With CHARGE for micro:bit
- micro:bit (V2)
- USB cable
- Chromebook, laptop, or desktop
- Access to MakeCode
- Water Bottle
- CHARGE w/ wrist strap
Without CHARGE
- micro:bit (V2)
- USB cable
- Chromebook, laptop, or desktop
- Access to MakeCode
- Water Bottle
- Power bank or battery pack
- Wrist strap, clips, tape, elastic bands
Code your Hydration Alert:
This project has a simple version and a complex version. The Level 1 Code creates a constant timer to go off every 10 minutes, while the Level 2 Code picks a random time between 10 to 15 minutes to send the alert.
Level 1 Code:
- Open makecode.microbit.org
- Delete “forever” codeblock
- Loops drawer: add “every 500 ms” to the workspace & change the number to 600,000 which is 10 minutes in milliseconds.
- Basic drawer: add “show icon” or “show leds” to “every timer ms,” either pick an icon you think fits best or draw one. Here’s one that looks like a water drop.
- Music drawer: add “play melody 🎵 at tempo 120 (bpm)” or “play tone Middle C for 1 beat until done” under the last block. Customize how you get alerted by making a little tune or just playing a note to get your attention.
- Basic drawer: add “clear screen” after “play melody”
- Plug in your micro:bit, pair, download your code and test!
Or experiment with the finished code here:
Level 2 Code:
- Open makecode.microbit.org
- Delete “forever” codeblock
- Variables drawer: “Make a Variable” and name it something like timer
- Variables drawer: add “set timer to 0” to “on start”
- Copy & paste “set timer to 0” below the first one. Change 0 to 600,000. (This is 600,000 ms which is equal to 10 minutes)
- Loops drawer: add “every 500 ms” to the workspace
- Variables drawer: grab the timer variable and drop it onto the “500 ms”, it should now say “every timer ms”
- Basic drawer: add “show icon” or “show leds” to “every timer ms,” either pick an icon you think fits best or draw one. Here’s one that looks like a water drop.
- Music drawer: add “play melody 🎵 at tempo 120 (bpm)” or “play tone Middle C for 1 beat until done” under the last block. Customize how you get alerted by making a little tune or just playing a note to get your attention.
- Variables drawer: add “set timer to 0” under the last block.
- Math drawer: grab “0 x 0” and drop it on the 0 in “set timer to 0”
- Math drawer: gran “pick random 0 to 10” and drop it on the first 0 in the multiplication function.
- Now change the numbers so that the function reads “pick random 60 to 90 x 10000”*
- Basic drawer: add “clear screen” after “set timer…”
- Plug in your micro:bit, pair, download your code and test!
Or experiment with the finished code here:
*60,000 milliseconds (ms) are in 1 minute. 600,000 ms is 10 minutes. This code picks a random time between 10 and 15 minutes to alert you to drink water. If you’d like to change how often the alert goes off, there’s a chart below with more conversions.
‘Pick Random’ numbers | Total ms | Duration |
3 | 30,000 | 30 seconds |
6 | 60,000 | 1 minute |
30 | 300,000 | 5 minutes |
60 | 600,000 | 10 minutes |
72 | 720,000 | 12 minutes |
90 | 900,000 | 15 minutes |
108 | 1,080,000 | 18 minutes |
120 | 1,200,000 | 20 minutes |
150 | 1,500,000 | 25 minutes |
180 | 1,800,000 | 30 minutes |
270 | 2,700,000 | 45 minutes |
360 | 3,600,000 | 1 hour |
Use the Hydration Alert:
Now attach the micro:bit to your water bottle and wait! It should now chime at you every 10 to 15 minutes, depending on your code, to remind you to drink your water.
Make it better:
Are you someone who snoozes alarms? Consider adding code to repeat the tone or melody until you’ve tilted the micro:bit enough from taking a drink! If you only used a tone, maybe try your hand at making a melody. What other ways could you use a timer like this?