Create a Doorbell with micro:bit

Difficulty
Easy
Steps
11

While the micro:bit has its own on-board pushbuttons, to play any sound you will need an external speaker or buzzer.

In this guide, we will create a simple doorbell using an external pushbutton and a buzzer module. We will also use a second micro:bit as a handheld device that will notify you when someone has pressed the doorbell. 

Learn the basics and go on to customise your own build! 

Parts Used in This Guide

Buy

Step 1  Connect module to breadboard

Step 2  Connect P1 to S

Step 3  Connect middle pin to +

Step 4  Connect GND to -

Step 5  Connect + to VCC (Buzzer module)

Step 6  Connect P0 to I/O

Step 7  Connect GND to GND

Step 8  Connect 3.3V to +

Step 9  The MakeCode!

  • Here, we introduced a start loop, with the code in it running only once on start up. If you pressed the reset button, the code in here will run again.
  • From 'Basic' tab, grab a 'show leds' block and change it as shown.
  • Now when the micro:bit starts up, the LED display will show two brackets. To do so, click on the 5x5 squares in the block.
  • From Input tab, grab a 'on pin P0 pressed' block. Drag it into the editor and change it from P0 to P1.
  • From 'Basic' tab, grab another 'show leds' block and change it as shown
  • Next, when the button is pressed, we want it to play a tone. A Middle D# followed by B tone will play through the buzzer module, to make it sound like a doorbell.
    • From 'Music' tab, grab a 'Play ... tone for ... beat ' block
    • Change its value to 'middle D#' and '1'.
    • Grab another 'Play... tone for... beat' block
    • This time change it to Low B for 1 beat
  • Finally, we want the LED display to show two brackets again. 
    • Get another 'show leds' block and get it to display two brackets.

Step 10  Create a handheld notifier !

What if you've missed the sound of the door bell or are away from your room or house or wherever you have installed the doorbell system? Wouldn't it be handy to have the micro:bit send you a message on a handheld device?

If you have a second micro:bit lying around, you can add this extra step! Otherwise, please move to the final step and upload the previous code.

  • The new code that comes after "play tone Low B for 1 beat" sends a message by radio to any nearby micro:bit devices. 
  • When the pushbutton is pressed, a string of "Let me in!" is now sent to the second micro:bit device. 
    • To create this, under 'Radio' tab, grab a 'on radio send string ...' block and change its value to 'Let me in!'. 
    • Create a new variable and name it 'receivedString'.
    • Grab another block under 'Radio' tab, called 'on radio received ... ' 
    • Place a 'show string' block (found under 'Basic tab') in it, change its value to 'receivedString'
    • Change the value in 'on radio received' block to 'receivedString'

Step 11  Upload the code

  1. Connect the micro:bit to your computer via a microUSB cable
  2. Click on the Download button over in the MakeCode editor
  3. Find the hex file in the Downloads folder 
  4.  Open up Finder on the MacOS or Explorer on Windows, and drag the hex file into MICROBIT under 'Devices' on the macOS.
  5. Watch the micro:bit flash for a few seconds as the code is uploaded. 
  6. Test your micro:bit doorbell by pressing the button.

Congratulations, you've created a simple doorbell using the micro:bit and a few little modules!