after we discussed the Block code in the Basic section which can be read here https://wisatailmu.com/2025/01/22/basic-full-list-of-code-blocks-inside-microbit/,
now we will discuss the code block in the input section.
2. Input
Blocks for handling physical inputs from micro:bit devices.
On Button A Pressed

Runs the block when button A is pressed.
- Function: To capture the button action.
On Button B Pressed

Same as button A, but for button B.
- Function: To capture the button action.
On Button A+B Pressed

Runs a block when buttons A and B are pressed together.
- Function: To capture the button action.
On Shake

Runs the block when the micro:bit is shaken.
- Function: Captures input from the accelerometer.
- in this section there are several options such as Shake, Logo Up, Logo Down and many more, please do a test to see the results.

On Pin p0 Press

“on pin P0 press” is an event handler used on the Micro:bit to detect interaction with a specific pin (in this case, P0) when that pin is connected to ground (GND). This feature allows the Micro:bit to respond to an external touch or button connected to one of the input/output pins.
- Micro:bit has three main pins that can be used for input/output: P0, P1, and P2.
- These pins are usually used to connect sensors, buttons, or other external devices.

Button A is Pressed

In Micro:bit, “button A is pressed” is one of the event handlers that detects when button A on the Micro:bit device is pressed. Micro:bit has two built-in buttons, A and B, which are often used for simple interactions such as input control.
- “Pressed” means that the event occurs only once when the button is pressed.
- Button A (as well as B) is directly connected to the Micro:bit microcontroller, so no additional circuitry is required.

Acceleration (mg)

Reads the acceleration value on a specific axis (x, y, or z).
- Function: Monitors device motion.
Pin P0 is Pressed

“Pin P0 is pressed” is an event handler on the Micro:bit that detects interaction with pin P0 when it is grounded (GND) or touched directly. This is one way to add external inputs, such as buttons, sensors, or even hand touches.
- Pin P0 is one of the I/O (input/output) pins on the Micro:bit. Besides P0, the Micro:bit also has similar pins such as P1 and P2.
- Pressed in this context means that the Micro:bit detects that the circuit between pin P0 and GND is closed, for example by:
- Pressing the button connected to P0 and GND.
- Directly touching the P0 pin (because the human body is conductive).
Light Level

Reads the ambient light level.
- Function: Used for light intensity-based control.
Compass Heading![]() On Micro:bit, “Compass Heading” is a feature to detect heading using the built-in compass sensor (magnetometer). This compass provides a heading value in degrees (0° to 359°) based on the Micro:bit’s orientation relative to magnetic north. How Compass Heading Works Heading value: – 0°: Heading north. – 90°: Heading east. – 180°: Points south. – 270°: Points west. The compass on the Micro:bit needs to be calibrated before use to ensure accurate readings. |
Temperature![]() On the Micro:bit, the temperature feature allows the device to measure the temperature of the surrounding environment. The Micro:bit’s built-in temperature sensor is actually a sensor contained within the microcontroller, so its measurements reflect the temperature of the Micro:bit board rather than the air temperature directly. However, it is still useful for various experiments. Explanation How it works: 1. The temperature sensor measures the temperature of the microcontroller (IC). 2. Its value is calibrated to provide an estimate of the ambient temperature in degrees Celsius (°C). Limitations: 1. This sensor is not as accurate as an environmental thermometer as it is affected by the heat generated by the device itself. 2. It is not suitable for temperature measurements that require high accuracy. |
Sound Level![]() On Micro:bit, “Sound Level” is used to detect the ambient noise level using the built-in microphone. This feature provides a sound level value as a number, which represents the intensity of the noise. Sound Level Explanation The sound level value is in the range of 0 to 255. – 0: No sound (silent). – 255: Very loud sound. The integrated microphone detects noise from the Micro:bit’s surrounding environment. This data can be used for various applications, such as sound reactive lamps or noise measuring devices. |
Calibrate Compass![]() Compass calibration on the Micro:bit is essential to ensure accurate compass direction (heading) readings. The Micro:bit’s built-in compass sensor needs to be calibrated to correctly recognize the local magnetic field, especially if it is used in a new environment. How Compass Calibration Works – The Micro:bit will prompt you for calibration if the compass has not been calibrated or if the compass readings are inaccurate. – Calibration involves physically moving the Micro:bit in a specific pattern to help the sensor read the ambient magnetic field. Auto Calibration in MakeCode – Use the calibrate compass block in the Input category. – When the program starts, the Micro:bit will display an animated pattern (usually dots forming a circle). – Move the Micro:bit until all the dots on the screen light up, indicating the calibration process is complete. |
Magnetic Force![]() On the Micro:bit, “Magnetic Force” is used to measure the strength of the surrounding magnetic field using the built-in magnetometer. This sensor can read the magnetic field in all three axes (x, y, z) and generate data in units of microtesla (µT). This data can be used to detect magnetic objects or understand the direction of the magnetic field. |