Cover image
    Activity

    Code a micro:bit as a Light Alarm

    Create a motion detecting alarm.

    Coding
    Get Started
    8-14+
    40:00
    micro:bit Coding Cards

    Code

    Light Alarm

    00:10

    Continuously turn off the RGB LED A and monitor the acceleration strength for motion detection. If it goes over 1200, turn on the RGB LED A for 4 seconds.

    basic.forever(function () {
        sb.setRgbLedColorRGB(sb.rgbLed(SBRgbLed.RgbLedA), 0, 0, 0)
        if (input.acceleration(Dimension.Strength) > 1100) {
            sb.setRgbLedColorRGB(sb.rgbLed(SBRgbLed.RgbLedA), 100, 0, 0)
            basic.pause(4000)
        }
    })

    If using micro:bit for the first time, follow this setup.