0Pricing
Arduino & IoT Academy · Aula

Controle um LED por um aplicativo de celular

Envie comandos por BLE para sua placa.

Controle um LED por um aplicativo de celular é uma aula grátis de Arduino & IoT Academy no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Arduino & IoT Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Arduino & IoT Academy inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

Your First BLE Control

Time to put it together: tap a button on your phone and watch an LED turn on. This is BLE control in action. 💡

The Plan

The phone writes a value to a characteristic, your board reads it, and your sketch switches the LED to match. Simple and powerful.

Prepare the LED Pin

In setup, declare the LED pin as an output so your board can drive it. This is the same pinMode you already know.

pinMode(2, OUTPUT);

Make It Writable

The control characteristic needs PROPERTY_WRITE so the phone is allowed to send commands to it. Read-only would block control.

svc->createCharacteristic(uuid,
  BLECharacteristic::PROPERTY_WRITE);

Listen for Writes

Attach a callback so your code runs the instant the phone writes. The onWrite method becomes your command handler.

Read the Command

Inside the callback, fetch what the phone sent with getValue. Maybe it is the text 1 for on or 0 for off.

std::string v = c->getValue();

Act on the Value

Compare the command, then drive the pin. A 1 turns the LED on, anything else turns it off. That is the whole logic.

digitalWrite(2, v == "1" ? HIGH : LOW);

Confirm Back

It helps to send the new state back so the app stays in sync. A short Serial print also confirms the command really arrived.

Serial.println("LED set");

Use a Generic App

No need to build an app yet. A tool like nRF Connect lets you connect and write values to test your control instantly.

Connect and Send

In the app, connect to your device, open the writable characteristic, and send 1. The onboard LED should light up right away.

From Here to a Real App

The same write idea powers a full custom app. Once this works, you can control motors, relays, or anything from your phone.

Quick Check

You want the phone to send an on or off command to your board.

Recap

A writable characteristic plus a callback turns phone taps into real-world action. You just built remote LED control over BLE. 🎉

Perguntas Frequentes

A aula “Controle um LED por um aplicativo de celular” é grátis?

Sim — o texto completo de “Controle um LED por um aplicativo de celular” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Arduino & IoT Academy, atualize para CoddyKit PRO. O curso de Arduino & IoT Academy inclui 4 aulas no total.

O que vou aprender em “Controle um LED por um aplicativo de celular”?

Envie comandos por BLE para sua placa. Você pratica Arduino & IoT Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Arduino & IoT Academy?

Nenhuma experiência prévia é necessária. Arduino & IoT Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “Controle um LED por um aplicativo de celular”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Arduino & IoT Academy?

Sim. Cada aula de Arduino & IoT Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Bluetooth clássico versus BLE
  2. Anuncie um serviço BLE
  3. Leia e grave características
  4. Controle um LED por um aplicativo de celular
← Voltar para Arduino & IoT Academy