Commander une LED depuis une application mobile
Envoyez des commandes à votre carte via BLE.
Commander une LED depuis une application mobile est une leçon Arduino & IoT Academy gratuite sur CoddyKit. Ceci est la leçon 4 sur 4. Tu peux lire la leçon complète ci-dessous gratuitement — puis la pratiquer en direct dans le navigateur avec un éditeur de code intégré et un tuteur IA 24/7. Elle fait partie du parcours d'apprentissage Arduino & IoT Academy, et ta progression se synchronise sur le web et l'application CoddyKit. Le cours Arduino & IoT Academy comprend 4 leçons au total.
Certaines parties de cette leçon n'ont pas encore été traduites et s'affichent en anglais.
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. 🎉
Questions Fréquemment Posées
La leçon « Commander une LED depuis une application mobile » est-elle gratuite ?
Oui — le texte complet de « Commander une LED depuis une application mobile » est gratuit à lire ici sur le web. Pour la pratiquer de manière interactive (un éditeur de code intégré et un tuteur IA 24/7) et déverrouiller le reste du cours Arduino & IoT Academy, passe à CoddyKit PRO. Le cours Arduino & IoT Academy comprend 4 leçons au total.
Qu'est-ce que j'apprendrai dans « Commander une LED depuis une application mobile » ?
Envoyez des commandes à votre carte via BLE. Tu pratiques Arduino & IoT Academy avec du code pratique que tu exécutes directement dans le navigateur, et un tuteur IA 24/7 répond à tes questions au fur et à mesure que tu avances dans la leçon.
Dois-je avoir de l'expérience pour commencer Arduino & IoT Academy ?
Aucune expérience préalable n'est requise. Arduino & IoT Academy sur CoddyKit est structuré pour les débutants jusqu'aux apprenants avancés, donc tu peux commencer ici ou depuis le début et avancer à ton rythme. Ceci est la leçon 4 sur 4.
Combien de temps prend la leçon « Commander une LED depuis une application mobile » ?
La plupart des leçons CoddyKit prennent environ 5–10 minutes. Chacune est courte et interactive, tu progresses régulièrement et tu repiques exactement où tu t'es arrêté sur le web et l'app.
Peux-tu écrire et exécuter du code dans cette leçon Arduino & IoT Academy ?
Oui. Chaque leçon Arduino & IoT Academy inclut un éditeur de code intégré, tu écris et exécutes du vrai code directement dans ton navigateur et tu reçois des retours IA instantanés — aucune configuration locale requise.
Toutes les leçons de ce cours
- Bluetooth classique ou BLE
- Annoncer un service BLE
- Lire et écrire des caractéristiques
- Commander une LED depuis une application mobile