Mask Detection
5 Minutes · Projects
Learn mask detection coding for kids by building a Scratch project with a Teachable Machine model. A Tamil technology lesson.
- Setting up Scratch blocks to display messages for mask detection
- Testing visual alerts by clicking the green flag
- Recording and attaching voice instructions for the sprite
What this lesson teachesRead the lesson as text
A mask detection program in Scratch uses a trained machine learning model to identify whether a person is wearing a mask and trigger automatic actions. By connecting the classification model to programming blocks, the software can display text alerts and speak recorded voice instructions based on what the camera detects.
Connecting the model
A pre-trained model URL for mask on and mask off detection is pasted into the Scratch programming tool. A tick mark appears in the interface once the model has uploaded properly and is ready to use. From the machine learning blocks, the block named when model detects mask on is placed in the workspace. Duplicating this block and selecting mask off allows the project to give specific instructions for both situations.
Displaying text alerts
To show visual guidance, a say block from the looks category is attached below each detection block and set to run for two seconds. The message under the mask on block is edited to read good to go, while the mask off block is edited to say please wear your mask. A when flag clicked block from the events category is added so the program can be tested. Clicking the green flag runs the script, causing the on-screen character to display the appropriate text depending on whether a mask is detected on the face.
Recording voice alerts
Under the sound menu, the start sound block is placed into both sections of the code. Instead of using the default pop sound, the built-in recorder is used to capture spoken instructions. The phrases you are good to go and please wear your mask are recorded into separate audio tracks. Unwanted parts of the audio can be trimmed before each recording is saved and renamed.
Testing the completed project
After the audio clips are saved, the coding tab is opened again to select the newly recorded sounds inside the start sound blocks. Clicking the green flag activates the project, making the character speak the right audio instruction whenever a mask is worn or missing. The sprite can also be moved to the side so the camera view stays clear. The stop button ends the program once testing is finished.
Part of the course
A.I. with Teachable Machine