Make an AI Light Switch with micro:bit + CreateAI

In this project, students explore artificial intelligence by creating an AI-powered light switch system using the micro:bit and the CreateAI platform. Students train a machine learning (ML) model to recognize different movements—typically clapping (turn on) and waving (turn off)—by collecting motion data using the micro:bit’s accelerometer. Note: this project uses two micro:bits

Grade Levels: 3 - 12
Subject Matter: Algorithms, Artificial Intelligence (AI), Physical Computing, Programming
Concepts: Programs and Algorithms, Computing Devices and Systems, Data and Information
Standards: 3-5.PA.2, 6-8.CD.1, 6-8.CD.3, K-2.PA.1, K-2.PA.2, K-2.PA.3, K-2.PA.4, 3-5.PA.1, 6-8.CD.2, 3-5.PA.3, 6-8.PA.1, 6-8.PA.2, 3-5.DI.1, 6-8.DI.1, 6-8.DI.2, 3-5.CD.2, 3-5.CD.1, K-2.CD.2, 3-5.CD.3
  • Average Rating: 0.0 (0 ratings)

Materials

Activity Instructions

  1. Introduce the Activity
    • What if you could train a computer to turn lights on without touching a switch?
    • Where might that be useful?
    • How could a computer recognize your actions?
    • Today, you’re building a touchless, micro:bit and AI-powered light switch.
  2. Introduce AI & Machine Learning
    • Machine learning means teaching a computer using examples instead of step-by-step instructions.
    • Explain simply:
      • You give examples (dataset)
      • The computer finds patterns in the data
      • It predicts what new inputs are
    • We’re going to teach it to recognize movements
  3. Collect Training Data
    • Guide students in CreateAI
      • Create movement classes:
        • Clapping
        • Waving
        • Still
    • Connect your micro:bit to CreateAI
    • Record multiple samples for each class
    • The more good examples you give, the better your AI will work.
  4. Train & Test the Model
    • Train model once you have recorded enough data, and see what your AI learned.
    • Students:
      • Click Train model
      • Test movements
    • Discuss:
      • Does it recognize movement correctly?
      • Where does it make mistakes?
  5. Improve the Model (Iteration)
    • AI gets better with better data. Are there any classes that need more data to help improve the accuracy of detecting the movements correctly?
    • Students:
      • Add more sample data to the classes
      • Remove incorrect ones
      • Retrain and test
  6.  Connect AI to micro:bit Code
    • Students:
      • Open project in MakeCode
      • Download to both micro:bits
    • Explain roles:
      • Sender micro:bit → detects movement
      • Receiver micro:bit → controls “light”
  7. Program the Light Switch Logic in MakeCode
    • Walk students through creating the code or use the completed code link (provided within MakeCode) to share the completed code with students.
    • Discuss the behavior within the code:
      • Clap → send “lightsOn”
      • Wave → send “lightsOff”
      • Receiver:
        • “lightsOn” → LEDs ON
        • “lightsOff” → LEDs OFF
  8. Test the System 
    •  Try your micro:bit AI light switch!”
    • Students:
      • Wear or hold sender micro:bit
      • Perform the three actions
    • Discuss:
      • Does the second micro:bit respond correctly?
  9. Real-World Connection
    • Discuss:
      • What is this functionality similar to in the real world?
    • Options:
      • Smart home devices
      • Motion-controlled lighting
      • Touchless interfaces
      • Accessibility technolog

Tips for Running Activity

  • Expect:
    • Model inaccuracies (valuable learning moment)
    • Need for multiple training attempts
  • Emphasize:
    • AI is only as good as its data
    • Systems connect multiple devices
    • Students can design intelligent systems not just code

Assessment Opportunities

Reflection / Exit Ticket Ideas:

  • How did your AI learn to recognize movements?
  • What made your model more accurate?
  • What happened when it made mistakes?
  • How is this different from traditional coding?

Extension Opportunities

Students can:

  • Add a third action (dim lights)
  • Control multiple micro:bits at once
  • Add sound or external LEDs
  • Build a smart room prototype
  • Explore accessibility applications

Elements of this resource were created by BBC micro:bit, then curated by the team at Nextech.

Learn More