0Pricing
Arduino & IoT Academy · Lezione

Controllare un LED da un'app del telefono

Invii comandi alla scheda tramite BLE.

Controllare un LED da un'app del telefono è una lezione Arduino & IoT Academy gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Arduino & IoT Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Arduino & IoT Academy include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

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. 🎉

Domande Frequenti

La lezione «Controllare un LED da un'app del telefono» è gratuita?

Sì — il testo completo di «Controllare un LED da un'app del telefono» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Arduino & IoT Academy, passa a CoddyKit PRO. Il corso Arduino & IoT Academy include 4 lezioni in totale.

Cosa imparerò in «Controllare un LED da un'app del telefono»?

Invii comandi alla scheda tramite BLE. Eserciti Arduino & IoT Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Arduino & IoT Academy?

Non è richiesta alcuna esperienza precedente. Arduino & IoT Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.

Quanto tempo richiede la lezione «Controllare un LED da un'app del telefono»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Arduino & IoT Academy?

Sì. Ogni lezione Arduino & IoT Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Bluetooth classico contro BLE
  2. Pubblicizzare un servizio BLE
  3. Leggere e scrivere le caratteristiche
  4. Controllare un LED da un'app del telefono
← Torna a Arduino & IoT Academy