Skip to content

Atividade

Interruptor de luz IA

Intermediário | MakeCode | Acelerômetro, Rádio, Visor LED | Aprendizagem de máquina, Entendendo IA, Entrada/saída

Faça um interruptor de luz IA com micro:bit CreateAI que ligue a luz quando você bater palco e desligar quando você acena.

Guia do projeto passo a passo

Passo 1: Entender

Como funciona?

Neste projeto, você vai treinar um modelo de aprendizado de máquina (ML ou Machine Learning) para reconhecer quando você está aplaudindo e acenando.

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.

Quando o receptor micro:bit receber o sinal ‘lighttsOn’, todos os seus LEDs acendem. Quando recebe o sinal 'lightsOff', limpa sua tela de LED.

O que é aprendizado de máquina?

Aprendizado de máquina (ML ou Machine Learning) é um tipo de inteligência artificial (IA) onde os computadores podem aprender e tomar decisões com base em dados.

Os modelos de ML são treinados por humanos para ajudá-los a tomar essas decisões, por exemplo, reconhecer diferentes 'ações' quando você move seu micro:bit de maneiras diferentes.

O que eu precisarei fazer?

Os sistemas de IA precisam de humanos para projetá-los, construí-los, testá-los e usá-los. Você vai coletar dados para treinar um modelo ML, testá-lo, melhorar, e combiná-lo com o código do computador para criar um dispositivo inteligente que usa I.A. Você usará um micro:bit e o site micro:bit CreateAI para fazer isso.

Passo 2: Criação

Itens necessários:

Colete amostras de dados

Quando você abrir o projeto no micro:bit CreateAI, verá que fornecemos algumas amostras de dados para as ações de ‘acenar’, ‘aplaudir’ e ‘ficar parado’

Você pode adicionar suas próprias amostras de movimento no micro:bit  através do sensor de movimento ou do acelerômetro.

No micro:bit CreateAI, clique no botão 'Conectar' para conectar seu micro:bit de coleta de dados e siga as instruções.

Foto do micro:bit com ícone cruzado em sua tela, anexada ao pulso de alguém.

Anexe o micro:bit ao seu pulso. Clique na primeira ação, "acenando" e clique em "Gravar". Caso cometa um erro, você pode excluir as amostras que não desejar. Também é possível pressionar o botão B no micro:bit para começar a gravar.

Se você quiser gravar continuamente por 10 segundos para obter 10 amostras, clique nos três pontos ao lado do botão de registro e selecione essa opção.

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.

Treine e teste o modelo

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.

Aprimore seu modelo

A maioria dos modelos pode ser aprimorada com mais dados. 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.

Treine o modelo novamente e teste-o de novo.

Coloque o modelo e o código no seu micro:bit

No micro:bit CreateAI, clique em "Editar no MakeCode" para ver o código do projeto no editor 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.

Como funcionam os blocos de código

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. É possível escolher qualquer número de grupo entre 0 e 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’.

Avaliação

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?

Passo 3: Melhorias

  • 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’.