The Cat Defense Device

The Cat Defense Device


Make a simple device to get your cat away from it.

I’d love to put this device in my box containing lots of bricks to get my cat away from it as it always carries them in its mouth or plays inside the box, I hope to scare the cat away with the sound and LED bricks.


micro:bit x 1

Nezha expansion board x 1

Rainbow Led x 1

Sensor x 1

PConnection Diagram

Connect the PIR to J1 port and Led to J2 port on Nehzha expansion board.

Build a device as the picture shows:

Hardware Connections

Step 1

Click “Advanced” to see more choices in the MakeCode drawer.

We need to add a package for programming. Click "Extensions" in the bottom of the drawer and search with "PlanetX" in the dialogue box to download it.

Note: If you met a tip indicating that the codebase will be deleted due to incompatibility, you may continue as the tips say or build a new project in the menu.

Step 2

Code as below

Initialize the rainbow LED to connect the Nonpixel at pin J1 in the on start brick.

While the PIR sensor detects the movement, set to play the music “nyan”, and set the rainbow led to flash in blue and red for 5 times on and on, at last it stops playing the music and the led lights off.

Complete Code:



If the PIR Sensor detects the movement, the Nezha board alarms and the rainbow led flashes for 5 seconds.