Skip to content

활동

AI light switch

중급 | MakeCode | LED, 가속도 센서, 라디오 | AI 이해하기, 머신 러닝, 입력/출력

Make an AI light switch with micro:bit CreateAI that makes a light turn on when you clap and turn off when you wave.

프로젝트 단계별 가이드

1단계: 이해하기

How does it work?

In this project, you’ll train a machine learning (ML) model to recognise when you’re clapping and waving.

You’ll combine that model with a MakeCode program that sends a ‘lightsOn’ radio signal to another micro:bit whenever you clap, and a ‘lightsOff’ radio signal whenever you wave.

When the receiver micro:bit receives the ‘lightsOn’ signal, all its LEDs light up. When it receives the ‘lightsOff’ signal, it clears its LED display.

기계 학습이란?

기계 학습(ML)은 컴퓨터가 데이터 기반으로 학습하고 판단하는 일종의 인공지능(AI)입니다.

예를 들어, ML 모델은 사용자가 micro:bit를 다양한 방식으로 움직일 때 다양한 '행동'을 인식하도록 결정하는 도움을 주기 위해 학습됩니다.

제작 방법

AI 시스템은 사용자가 설계, 구축, 테스트, 사용합니다. You'll collect data to train an ML model, test it, improve it, and combine it with computer code to make a smart device that uses AI. 이를 위해 사용자는 micro:bit와 micro:bit CreateAI 웹사이트를 사용합니다.

2단계: 만들기

준비물

데이터 샘플 수집

When you open the project in micro:bit CreateAI, you’ll see we’ve given you some data samples for ‘waving’, 'clapping’ and ‘still’ actions:

You can add your own movement samples using the micro:bit's movement sensor or accelerometer.

micro:bit CreateAI에서 '연결(Connect)' 버튼을 클릭하여 데이터 수집 micro:bit를 연결하고 지시를 따릅니다.

Photo of micro:bit with cross icon on its display, attached to someone's wrist.

Attach the micro:bit to your wrist. Click on the first action, ‘waving’, and click 'Record'. 실수한 경우 원하지 않는 샘플은 삭제할 수 있습니다. micro:bit의 B 버튼을 눌러 기록을 시작할 수도 있습니다.

If you would like to record continuously for 10 seconds to get 10 samples, click on the three dots next to the record button and select that option.

Now record your own data samples for the ‘clapping’ and 'still' actions, making sure for 'still' that you collect samples in different positions, such as facing up and down.

모델 훈련 및 테스트

Click the ‘Train model’ button to train the model. Try clapping, waving and keeping still to see if those actions are estimated. Give your micro:bit to someone else to wear (making sure they put it on the same wrist and in the same orientation) and see if it works as well for them.

모델 개선

대부분의 모델은 데이터가 많을수록 더 개선될 수 있습니다. If the model needs improving, click on ‘← Edit data samples’.

You can delete any data samples which you think don’t fit or add more samples.

모델을 한 번 더 훈련하고 다시 테스트합니다.

모델과 코드를 micro:bit에 넣습니다.

micro:bit CreateAI의 ‘MakeCode에서 편집(Edit in MakeCode)’을 클릭하면 MakeCode 편집기에서 프로젝트 코드를 볼 수 있습니다.

You can modify the code or just try it out as it is. Attach the first micro:bit using a USB cable, click on the ‘Download’ button in the MakeCode screen, and follow the instructions to transfer your AI model and the code blocks to it. Afterwards, download again onto another micro:bit.

Attach a battery pack to the sender micro:bit. You can keep the receiver micro:bit plugged into the computer or attach it to battery pack. Now wear the sender micro:bit and test it out.

코드 블록 작동 방식

When the program starts, the radio group is set to 52. Radio groups are like channels, so any micro:bit using the same group will get the message. 0-255 범위에서 원하는 번호를 골라 그룹 번호로 사용할 수 있습니다. If you are using this project in a class or coding club, you might like to encourage each pair or group of students to use a different radio group from others in the class.

The 'on ML... start' blocks are triggered when the sender micro:bit’s ML model decides you have started waving, clapping or being still.

If you are clapping, the ‘on ML clapping start’ block causes a tick icon to appear on the LED display of the sender micro:bit and the radio message ‘lightsOn’ to be sent to the receiver micro:bit. If you are waving, the ‘on ML waving start block’ causes a cross icon to appear on the LED display of the sender micro:bit and the radio message ‘lightsOff’ to be sent to the receiver micro:bit.

If you are still or the sender micro:bit can’t recognise your movements, the LED display is cleared and no radio message is sent.

The ’on radio received’ blocks turn on all the LEDs on the receiver micro:bit if a message is received saying ‘lightsOn’ and clear the screen if a message is received saying ‘lightsOff’.

The ‘on radio received lightsOn / lightsOff’ blocks are from a MakeCode extension called ‘Radio broadcast’. If you want to code this project yourself, you can find the blocks by clicking on ‘Extensions’ then choosing ‘Radio broadcast’.

평가

How accurate is the light switch in turning on and off in response to your movements? How could you improve it, if needed?

How useful would this device be in real life? How does it compare to a regular light switch?

3단계: 확장하기

  • You could light up a room by putting the same code on multiple micro:bits. Keep the other micro:bits still while someone moves another to turn them all on or off.
  • Add a fourth action which causes the receiver micro:bit to show dimmed lights. Use the ‘set brightness’ block, found in the LED section under ‘More’.