Zigbee: Light bulb

This sample demonstrates a simple light bulb whose brightness can be adjusted by another device.

You can use this sample with the Zigbee Network coordinator and Zigbee Light switch samples to set up a basic Zigbee network.

Requirements

The sample supports the following development kit:

Hardware platforms

PCA

Board name

Board target

nRF52840 DK

PCA10056

nrf52840dk

nrf52840dk/nrf52840

nRF5340 DK

PCA10095

nrf5340dk

nrf5340dk/nrf5340/cpuapp

nRF54L10 emulation on the nRF54L15 DK

PCA10156

nrf54l15dk

nrf54l15dk/nrf54l10/cpuapp

nRF54L15 DK

PCA10156

nrf54l15dk

nrf54l15dk/nrf54l15/cpuapp

nRF54LM20 DK

PCA10184

nrf54lm20dk

nrf54lm20dk/nrf54lm20a/cpuapp
nrf54lm20dk/nrf54lm20b/cpuapp

To test this sample, you also need to program the following samples:

Overview

The Zigbee light bulb sample takes the Zigbee Router role and implements the Dimmable Light device specification, as defined in the Zigbee Home Automation public application profile. This profile allows changing the brightness level of the light bulb’s LED.

Configuration

See Configuring and building in the nRF Connect SDK documentation for information about how to permanently or temporarily change the configuration.

Source file setup

This sample is split into the following source files:

  • The main file is the application entry point only.

  • The app_task_zigbee file manages the application task flow, user input handling, and Zigbee-specific startup and control logic. It also implements the dimmable light device behavior, including cluster handling and PWM-based brightness control.

Configuration files for sample extensions

The sample provides predefined configuration files for optional extensions. You can find the configuration files in the samples/light_bulb directory.

Activating optional extensions

To activate the Zigbee FOTA, use the prj_fota.conf configuration file together with the zigbee_fota_ext_flash snippet. The snippet provides external-flash partition layouts, sysbuild MCUboot settings, and the matching MCUboot configuration (through zigbee_fota_mcuboot_ext_flash). For example, when building from the command line, use the following command:

west build samples/light_bulb -b board_target -- -DFILE_SUFFIX=fota -DSNIPPET=zigbee_fota_ext_flash

The FOTA variant enables MCUboot image compression. The generated Zigbee update file contains a compressed MCUboot image, and MCUboot decompresses it while applying the update. This setting reduces the size of the update image. However, it requires MCUboot to run in overwrite-only mode, which means the device cannot revert to the previous image after an update is applied.

Alternatively, you can configure Zigbee FOTA manually.

Note

The decompression support increases the size of the MCUboot image. When adapting this FOTA configuration to a custom board or application, make sure that the MCUboot partition is large enough for the generated bootloader image. The FOTA variant uses devicetree-based partitioning with Partition Manager disabled; see Upgrading Zigbee application for the partition layout requirements.

Device firmware upgrade over Bluetooth SMP

To additionally enable Device Firmware Upgrade (DFU) over Bluetooth LE using the Simple Management Protocol (SMP), add CONFIG_ZIGBEE_BT_DFU=y to the FOTA build command:

west build samples/light_bulb -b board_target -- -DFILE_SUFFIX=fota -DSNIPPET=zigbee_fota_ext_flash -DCONFIG_ZIGBEE_BT_DFU=y

This option enables the MCUmgr SMP server over Bluetooth LE alongside Zigbee FOTA.

See Testing Zigbee FOTA DFU over Bluetooth SMP for step-by-step testing instructions.

User interface

LED 0:

Blinks to indicate that the main application thread is running.

LED 1:

Indicates the dimmable light option, that is changes to the light bulb brightness. It can be controlled by another Zigbee device in the network, for example a light switch. Blinks when the light bulb is in Identify mode.

LED 2:

Turns on when the light bulb joins the network.

Button 3:

Depending on how long the button is pressed:

  • If pressed for less than five seconds, it starts or cancels the Identify mode.

  • If pressed for five seconds, it initiates the factory reset of the device. The length of the button press can be edited using the CONFIG_FACTORY_RESET_PRESS_TIME_SECONDS Kconfig option from Zigbee application utilities. Releasing the button within this time does not trigger the factory reset procedure.

Building and running

Make sure to configure the Zigbee stack before building and testing this sample. See Configuring Zigbee R23 add-on for more information.

This sample can be found under samples/light_bulb in the Zigbee R23 add-on folder structure.

To build the sample, follow the instructions in Building an application in the nRF Connect SDK documentation for your preferred building environment. See also Programming an application for programming steps and Testing and optimization for general information about testing and debugging in the nRF Connect SDK.

Note

When building repository applications in the Zigbee R23 add-on which is an SDK repository, building with sysbuild is enabled by default. If you work with out-of-tree freestanding applications, you need to manually pass the --sysbuild parameter to every build command or configure west to always use it.

Testing

After programming the sample to your development kits, complete the following steps to test it:

  1. Turn on the development kit that runs the Network coordinator sample.

    When LED 2 turns on, this development kit has become the Coordinator of the Zigbee network and the network is established.

  2. Turn on the development kit that runs the Light bulb sample.

    When LED 2 turns on, the light bulb has become a Router inside the network.

    Note

    If LED 2 does not turn on, press Button 0 on the Coordinator to reopen the network.

  3. Turn on the development kit that runs the Light switch sample.

    When LED 2 turns on, the light switch has become an End Device, connected directly to the Coordinator.

  4. Wait until LED 3 on the development kit that runs the Light switch sample turns on.

    This LED indicates that the switch found a light bulb to control.

  5. Use the buttons on the development kit that runs the Zigbee: Light switch sample to control the light bulb.

    The result of using the buttons is reflected on the light bulb’s LED 1.

You can now use buttons on the light switch to control the light bulb, as described in the User interface section of the Light switch sample page.

Testing Zigbee FOTA DFU over Bluetooth SMP

To test DFU over Bluetooth SMP in a Zigbee-only build, complete the following steps:

  1. Build and flash the sample with the CONFIG_ZIGBEE_BT_DFU=y Kconfig option (see Configuration files for sample extensions).

  2. Wait for the device to boot.

    After booting, the device automatically starts Bluetooth LE connectable advertising for the SMP server. The advertised device name is Zigbee_Bulb, set by CONFIG_BT_DEVICE_NAME when CONFIG_ZIGBEE_BT_DFU is enabled.

  3. Perform the update using one of the following methods:

    1. Install nRF Connect Device Manager.

    2. Use the dfu_application.zip file from the build directory.

    For detailed instructions, see FOTA updates on nRF54L Series devices (nRF54L15 and nRF54LM20 DKs) or FOTA updates with nRF5340 DK (nRF5340 DK).

After the update completes, MCUboot applies the new image on the next reboot.

Note

Zigbee OTA and SMP DFU are independent transports, and SMP is not part of the Zigbee specification. You can use either mcumgr or nRF Connect Device Manager to perform the update over Bluetooth LE.

Dependencies

This sample uses the following nRF Connect SDK libraries:

It uses the ZBOSS stack:

In addition, it uses the following Zephyr libraries: