A water bottle with a CHARGE power pack and micro:bit attached to it sits on a table beside a laptop.

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:
  1. Open makecode.microbit.org
  2. Delete “forever” codeblock
  3. Loops drawer: add “every 500 ms” to the workspace & change the number to 600,000 which is 10 minutes in milliseconds. 
  4. 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. 
  5. 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.
  6. Basic drawer: add “clear screen” after “play melody”  
  7. Plug in your micro:bit, pair, download your code and test!

Or experiment with the finished code here:

Level 2 Code:
  1. Open makecode.microbit.org
  2. Delete “forever” codeblock
  3. Variables drawer: “Make a Variable” and name it something like timer
  4. Variables drawer: add “set timer to 0” to “on start” 
  5. 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)
  6. Loops drawer: add “every 500 ms” to the workspace
  7. Variables drawer: grab the timer variable and drop it onto the “500 ms”, it should now say “every timer ms”
  8. 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. 
  9. 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.
  10. Variables drawer: add “set timer to 0” under the last block. 
  11. Math drawer: grab “0 x 0” and drop it on the 0 in “set timer to 0” 
  12. Math drawer: gran “pick random 0 to 10” and drop it on the first 0 in the multiplication function.
  13. Now change the numbers so that the function reads “pick random 60 to 90 x 10000”*
  14. Basic drawer: add “clear screen” after “set timer…”  
  15. 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’ numbersTotal msDuration
330,00030 seconds
660,0001 minute
30300,0005 minutes
60600,00010 minutes
72720,00012 minutes
90900,00015 minutes
1081,080,00018 minutes
1201,200,00020 minutes
1501,500,00025 minutes
1801,800,00030 minutes
2702,700,00045 minutes
3603,600,0001 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?