Morse Code

Send secret messages to one another!


  • 2 x micro:bit
  • 4 x Crocodile clips

Looking for parts to make this?


We want to send signals from Pin 1 of the first micro:Bit to Pin 2 of the second micro:Bit (and vice versa). To do so, connect:
(a) GND to GND
(b) 3V to 3V
(c) Pin 1 to Pin 2
(d) Pin 2 to Pin 1


  • 2 x micro:bit
  • 4 x Crocodile clips


Code for sender - Button A

(a) We want a dot signal to be sent when the A button is pressed.
(b) Open up MakeCode and name this file “Sender”.
(c) The show led block in the then section displays the “dot” on the sender screen when button A is pressed.
(d) Setting the digital write pin block to 1 will turn the signal at p1 (where we attached the clip) “on”.
(e) Then, it will pause for 230 ms, turn off with the digital write pin block set to 0, and pause for another 50 ms.


  • 1 x Micro:bit (sender)


Sender: Button B
We want a “dash” signal to be sent when the B button is pressed.

(a) Add an else if block to the if-then-else block from earlier.

(b) Repeat the steps as with Step 2, except
- Use button B is pressed
- Display a “dash” in the LED
- Pause for 470 ms
- For the else statement, add a clear screen block from Basic block, or an icon.


  • 1 x micro:bit (sender)


We want to record the duration of time between whenever the signal is received and when it stops. We will be using the running time (ms) block for this.

(a) Create another project on MakeCode called “Receiver”.

(b) The digital read pin = 1 block indicates when a signal is detected. Make sure to change it to P2, where we attached the crocodile clip.

(c) From the Variables drawer, create a new variable ‘keyDownTime’. Get ‘running time (ms)’ from the Input > more drawer and attach it to keyDownTime.


1 x micro:bit (receiver)


Now, we want to display the correct signal on the screen.

(a) The set duration block only runs if a signal has been detected with the keyDownTime variable.

(b) The duration variable tells us the amount of time between when the program started running and signal detection. We used 250 ms as the “dot” takes 230 ms.

(c) The “dash” threshold will be set to 500, since the “dash” takes 470 ms.

(d) After the first if-then block, set keyDownTime to 0 so that it works every time you send a new signal


1 x micro:bit (receiver)



(a) Make sure to flash the code to both micro:bits and test it out! It should display the same signal on both screens when you press a button. Hold the button on the sending micro:bit down for as long as you want the send the message for.

(b) For an added challenge, try to translate the morse code on the second micro:bit.

Made this activity? Good Job! Now spread the word. Share a photo of your creation on social media with #letsgethacking #MorseCode