0Pricing
Arduino & IoT Academy · Lesson

Control an LED from a Phone App

Send commands over BLE to your board.

Control an LED from a Phone App is a free Arduino & IoT Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Arduino & IoT Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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

Frequently asked questions

Is the “Control an LED from a Phone App” lesson free?

Yes — the full text of “Control an LED from a Phone App” is free to read here on the web, and the Arduino & IoT Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Arduino & IoT Academy course, upgrade to CoddyKit PRO.

What will I learn in “Control an LED from a Phone App”?

Send commands over BLE to your board. You practise Arduino & IoT Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Arduino & IoT Academy?

No prior experience is required. Arduino & IoT Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Control an LED from a Phone App” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Arduino & IoT Academy lesson?

Yes. Every Arduino & IoT Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Classic Bluetooth vs BLE
  2. Advertise a BLE Service
  3. Read & Write Characteristics
  4. Control an LED from a Phone App
← Back to Arduino & IoT Academy