Good for detecting boxes, drawers or doors being opened and much more.
The black lead goes on GND, the red lead goes on 3v and the other lead goes on 0, 1, or 2.
This item is somewhat polarity sensitive, the red & black leads need to be on the correct connections for a pin to register 1 when the microswitch is pressed. There is no harm caused by swapping the red & black connections but you will short circuit the micro:bit if the other lead is put on either 3v or GND
Use the digital input block to read the sensor value:
You can use any one of the three pins 0, 1 or 2.
When the microswitch is off (not depressed), it will read 0. When the microswitch is on (depressed), it will read 1. It is good engineering practise to wire a switch so that it definitely changes between one value or another, but if you only need to sense when the switch is activated, you can omit the GND lead from the connections. If the cables are being extended a fair distance (more than 5m or so), then using both 3V and GND is appropriate. If the cable run is more than 20m then using an analog input may be required as the voltage drop may be sufficient such the micro:bit doesn’t register the on state.