First IoT Project with Zephyr: Blinking an LED

🚀 Introduction
If you’re diving into the world of IoT development, you’ve probably heard about Zephyr RTOS. It’s an open-source, lightweight, and scalable real-time operating system designed for connected, resource-constrained devices.
The classic “Blink LED” project is the “Hello World” of embedded systems. By the end of this tutorial, you’ll understand how to:
Set up your development environment for Zephyr.
Write your first Zephyr application.
Build and flash the firmware.
Blink an LED on your development board.
Let’s get started!
🛠️ What You’ll Need
Before starting, make sure you have the following:
Hardware
A Zephyr-supported development board (e.g., ST Nucleo, Nordic nRF52 DK, or ESP32).
A USB cable to connect the board.
Software
West (Zephyr’s meta-tool) – used to fetch, build, and flash projects.
CMake and Python installed.
Zephyr SDK (toolchains and utilities).
A text editor or IDE (e.g., VS Code).
🔧 Step 1: Install Zephyr Development Environment
1. Clone Zephyr’s Source Code
Open a terminal and run:
west init ~/zephyrproject cd ~/zephyrproject west update
2. Install Zephyr Tools
pip install west pip install -r zephyr/scripts/requirements.txt
3. Export Zephyr Environment
source zephyr/zephyr-env.sh
Now your environment is ready!
💡 Step 2: Create the LED Blinky Application
Inside zephyrproject/zephyr/samples, create a new folder my_blinky.
Application Code (main.c):
#include <zephyr/kernel.h> #include <zephyr/drivers/gpio.h> #define LED_NODE DT_ALIAS(led0) static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED_NODE, gpios); void main(void) { if (!device_is_ready(led.port)) { return; } gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE); while (1) { gpio_pin_toggle_dt(&led); k_msleep(1000); // 1 second delay } }
⚙️ Step 3: Configure the Board
Zephyr uses device tree overlays and board definitions. Most supported boards already define led0. If your board has no alias, you can add one in an overlay file:
boards/your_board.overlay
/ { aliases { led0 = &gpio0; }; };
🏗️ Step 4: Build the Application
From the project directory, run:
west build -b <your_board_name> my_blinky
Example for Nucleo-L433RC-P:
west build -b nucleo_l433rc_p my_blinky
🔥 Step 5: Flash and Run
Flash your board with:
west flash
If everything went well, your board’s LED will start blinking 🎉
🧪 Step 6: Debugging (Optional)
If you don’t see the LED blinking:
Check your board’s device tree for the correct LED pin.
Verify drivers are enabled in prj.conf:
CONFIG_GPIO=y
📊 Why This Project Matters
Foundation for IoT apps: LED control is the first step toward sensors, actuators, and networking.
Understanding Zephyr basics: You now know how to set up, configure, and run applications.
Reusable workflow: The same process applies to more complex IoT projects like smart lighting, wearables, or connected sensors.
🌟 Next Steps
Once you’ve mastered the LED blink, try:
Changing the blink speed (e.g., 200ms instead of 1000ms).
Adding a button to toggle LED behavior.
Expanding to IoT – send LED status to the cloud via Bluetooth, Wi-Fi, or MQTT.
✅ Conclusion
You just built your first IoT project with Zephyr RTOS – blinking an LED! 🎉 This simple project is the starting point for creating powerful embedded and IoT applications. From here, you can explore sensors, communication protocols, and real-time features that make Zephyr the future of embedded development.