Self-lock switch is a kind of common button switch. When we press the button for the first time, the switch is connected and remains that status, which is called “self-lock”. When we press the button for the second time, the switch is disconnected. At the same time, the button will bounce back to its initial place. In this experiment, we are going to use self-lock switch to control LED light.

Component List


**Tips: If you want all components above, you may need Elecfreaks micro:bit Starter Kit.**

Major Components Introduction

Self-lock Switch

Self-lock switch normally means switch with built-in mechanical lock function. Press down the switch and then release, it will not fully bounce up because it is locked. You have to press it again, then it will be unlocked and fully bounce up. This is the so-called Self-lock Switch. It is widely used to earlier televisions and monitors with function of directly completely power off.

Note: This kind of self-lock switch contains two groups of double-throw switch. In this experiment, we use a group only. So we cut down the common footer of a group.

Experimental Procedure

Hardware Connection

Connect them as the picture shows:

After connection, you will see:


Please open makecode.microbit.org(https://makecode.microbit.org/) and write your code in the edit area.

Add Package

Program as the picture shows:

Details for the code:


Links: https://makecode.microbit.org/_Dhy5i9KVeLAK

You can also download the links directly:


Press down self-lock switch, LED lights on; press again, LED lights off.


Usually stair light uses double-throw switch to realize this function. We can turn on the light upstairs and turn off it downstairs. Vice versa. Suppose if we want to use 2 self-lock switch to realize stair light function, then how to design circuit and program?