Zigbee: Light bulb

Note

Zigbee R22 is currently in maintenance mode, and it is not recommended to use it for new Zigbee designs. While critical bug fixes and security updates will be provided as necessary, it will not receive any enhancements or new features. The Zigbee R23 add-on represents Nordic’s primary solution for future Zigbee developments, offering improvements, support for new features, and support for the nRF52840 SoC and new platforms such as the nRF54L series.

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 the Zigbee Light switch to set up a basic Zigbee network.

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Board target

nRF52840 DK

PCA10056

nrf52840dk

nrf52840dk/nrf52840

nRF52833 DK

PCA10100

nrf52833dk

nrf52833dk/nrf52833

nRF5340 DK

PCA10095

nrf5340dk

nrf5340dk/nrf5340/cpuapp
nrf5340dk/nrf5340/cpuapp/ns

nRF21540 DK

PCA10112

nrf21540dk

nrf21540dk/nrf52840

You can use one or more of the development kits listed above and mix different development kits.

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.

FEM support

You can add support for the nRF21540 front-end module to this sample by using one of the following options, depending on your hardware:

  • Build the sample for one board that contains the nRF21540 FEM, such as nrf21540dk/nrf52840.

  • Manually create a devicetree overlay file that describes how the nRF21540 FEM is connected to the SoC. See Configuring devicetree for different ways of adding the overlay file.

  • Provide nRF21540 FEM capabilities by using a shield, for example the nRF21540 EK shield that is available in the nRF Connect SDK. In this case, build the project for a board connected to the shield you are using with an appropriate variable included in the build command, for example -DSHIELD=nrf21540ek. This variable instructs the build system to append the appropriate devicetree overlay file.

    To build the sample in the nRF Connect for VS Code extension for an nRF52840 DK with the nRF21540 EK attached, add the shield variable in the build configuration’s Extra CMake arguments and rebuild the build configuration. For example: -DSHIELD=nrf21540ek.

    See How to work with build configurations in the nRF Connect for VS Code extension documentation for more information.

    See Building and programming with nRF21540 EK in the nRF Connect SDK documentation for information about how to program when you are using a board with a network core, for example nRF5340 DK.

Each of these options adds the description of the nRF21540 FEM to the devicetree. See Developing with Front-End Modules in the nRF Connect SDK documentation for more information about FEM in the nRF Connect SDK.

To add support for other front-end modules, add the respective devicetree file entries to the board devicetree file or the devicetree overlay file.

User interface

LED 1:

Blinks to indicate that the main application thread is running.

LED 3:

Turns on when the light bulb joins the network.

LED 4:

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.

Button 4:

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 R22 add-on for more information.

This sample can be found under samples/light_bulb in the Zigbee R22 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 R22 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 3 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 3 turns on, the light bulb has become a Router inside the network.

    Note

    If LED 3 does not turn on, press Button 1 on the Coordinator to reopen the network.

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

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

  4. Wait until LED 4 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 4.

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.

Dependencies

This sample uses the following nRF Connect SDK libraries:

It uses the following sdk-nrfxlib libraries:

In addition, it uses the following Zephyr libraries: