0Pricing
Arduino & IoT Academy · Lección

Controlar un LED desde una aplicación móvil

Envíe comandos por BLE a su placa.

Controlar un LED desde una aplicación móvil es una lección gratuita de Arduino & IoT Academy en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Arduino & IoT Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Arduino & IoT Academy incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en 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. 🎉

Preguntas frecuentes

¿La lección «Controlar un LED desde una aplicación móvil» es gratis?

Sí — el texto completo de «Controlar un LED desde una aplicación móvil» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Arduino & IoT Academy, actualiza a CoddyKit PRO. El curso de Arduino & IoT Academy incluye 4 lecciones en total.

¿Qué aprenderé en «Controlar un LED desde una aplicación móvil»?

Envíe comandos por BLE a su placa. Practicas Arduino & IoT Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Arduino & IoT Academy?

No se requiere experiencia previa. Arduino & IoT Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.

¿Cuánto tiempo toma la lección «Controlar un LED desde una aplicación móvil»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Arduino & IoT Academy?

Sí. Cada lección de Arduino & IoT Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Bluetooth clásico frente a BLE
  2. Anunciar un servicio BLE
  3. Leer y escribir características
  4. Controlar un LED desde una aplicación móvil
← Volver a Arduino & IoT Academy