Skip to main content

Case 14: Door and Window Alarm

Introduction

By collecting and training the gyroscope data of a door or window being opened, when it detects that the door or window is opened, it sends a message to another micro:bit board, which triggers an alarm upon receiving the message.


Purpose of the Case

Learn the method of collecting data for Create AI custom gestures.

Required Materials

ItemImageQuantity
smart coding kit1
micro:bit2
USB Cable1
Personal Computer1

Step 1: Create a New Project

  1. Use the Chrome or Edge web browser to visit https://createai.microbit.org/ as shown in the figure below, and click "Get Started".

  1. Click "New Session" and name the project.


Step 2: Connect the micro:bit Board

  1. Connect your micro:bit board to the computer using a data cable, and click "Connect".

  1. Prepare the corresponding materials and equipment, and click "Next".

(If your personal computer has Bluetooth connectivity, only one micro:bit board is needed. If your personal computer does not support Bluetooth connection, click "Use micro:bit Wireless Connection" and follow the tutorial to complete the connection.)

  1. Please connect your micro:bit board to the computer using a data cable, then click "Next" and follow the tutorial to complete the program download.

  2. Wait for the program to be downloaded and installed on the micro:bit board.

  1. Disconnect the USB cable and turn on the power of the Watch Kit Pro, then click "Next".

  1. Click "Next" and follow the tutorial to complete the Bluetooth connection authentication process.

  1. Select "micro:bit Board" and click "Pair", wait until the connection is successful.

  1. If the connection is successful, the "X", "Y", "Z" lines in the "Real-time Data Area" will change accordingly as you shake the watch.


Step 3: Data Collection

  1. Name the action "Action One" in the "Action Name" input box. Click the "triangle" icon to select the corresponding pattern displayed on the micro:bit for this action.

  1. Please install the watch kit on the door or window, ensuring that the micro:bit button A is facing up.
  1. Click "Record" to start collecting data samples of opening the door or window. A 3, 2, 1 countdown will be displayed on the screen. When the word "GO" appears, push the door or window open. Repeat this process the corresponding number of times according to the required number of data samples to collect

    Note: When collecting action data, you can open the window or door with different

    forces, which helps to obtain higher-quality useful data.

Explanation of Collection Principle. Create AI collects the "X", "Y", "Z" axis data of the micro:bit board's gyroscope, draws these data in the form of line graphs, and extracts the "X", "Y", "Z" axis data within a specific time period to form a set of data samples.

  1. After completing the data collection for Action One, click "Add Action" to create a new action dataset, then name it "Static" and start collecting action data. Note: When collecting data, you can collect static states from multiple angles as data samples.


Step 4: Model Training and Data Model Recognition Calibration

  1. Click "Train Model" and wait for the model training to complete.

  1. The accuracy rate of the action data model detection exceeds 80%. If all items reach this accuracy rate, the data collection is completed. If the accuracy rate of a certain action data model is lower than 80%, return to the data collection page, re-collect data and train until the accuracy rate of this action data model reaches or exceeds 80%.


Step 5: Program Writing and Download

  1. Click "Edit in MakeCode".

  1. Please complete the program writing as shown in the figure below, connect the micro:bit board to the personal computer using a data cable, and download the program.

  1. Click "Next" If the download location is the micro:bit board used for data collection, select "Same micro:bit"; if the download is to another micro:bit board, select "Different micro:bit".


Step 6: Program Writing for the Receiver

  1. Use the Chrome or Edge web browser to visit https://makecode.microbit.org/ as shown in the figure below, write the corresponding program, and download the program.

  1. Please refer to the program link https://makecode.microbit.org/_27DPTdLpfUX6

  2. You can also download the program directly through the following webpage.


Result

When a door or window is detected to be opened, an alarm is triggered.

Common Problems