Hydration Alert with CHARGE Power Pack

Introducing đ§Hydration Alert đš
We often forget to drink enough water throughout the day, leading 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! Depending on your code, it should now chime at you every 10 to 15 minutes 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 making a melody. What other ways could you use a timer like this?