Bluetooth Mesh Motion-sensed Lights With Multiway Switches

About the project

Bluetooth Mesh Connected and Motion Detected Lighting Solution for better Mobility & Accessibility

Project info

Difficulty: Moderate

Platforms: CypressSparkFun

Estimated time: 2 days

License: GNU General Public License, version 3 or later (GPL3+)

Items used in this project

Hardware components

Resistor 1K Ohm 1/4 Watt PTH - 20 pk Resistor 1K Ohm 1/4 Watt PTH - 20 pk x 4
Raspberry Pi 3 Model B Raspberry Pi 3 Model B x 4
Transistor NPN (2N3904) Transistor NPN (2N3904) x 4
Jumper Wire Kit - 140pcs Jumper Wire Kit - 140pcs x 4

Software apps and online services

Cypress ModusToolBox Cypress ModusToolBox

Hand tools and fabrication machines

Soldering iron (generic) Soldering iron (generic) x 1



Bluetooth mesh enables larger network of wirelessly connected devices to solve the problems of fixed positioned lights/switches. Depending on the network configuration and firmware, multiple wireless switches can control multiple lights at once. Can't locate wireless switch points in the dark ? No worries, motion sensor can light up the nearest light for you !

Long hallway or corridor with lots of light ? Not a problem in mesh connected wireless lamps, push one switch at the entry point to turn on all the lights and another switch to at the exit point to turn off all at once.

In this project, I am going to present interconnected multiway mesh lighting and switching system with following features :

  • Multiway Wireless On/Off Switches
  • Motion Sensed Timer Lighting
  • Scalable for additional Lights/Switches/Sensors
  • Reconfigurable Bluetooth Mesh Network


Following video shows both motion sensed and multiway mesh switches to control all the lights.

  • Motion sensed only turns on local light for 15 seconds and then turns off.
  • Multiway switches turns all lights until turned off
  • Multiway switched on lights ignore motion sense and stays on
  • Blue status LED means motion sensed, 15 sec timer for light
  • Green status LED means local/remote switch toggled
  • Cyan status LED means motion timer ignored, light always on

Mesh Lighting


I am going to use 4 CYBT-213043-Mesh development boards to demonstrate this solution.

CYBT-213043 Mesh board with CYW20819 Dual-Mode Bluetooth MCU and sensors

CYBT-213043 Mesh board with CYW20819  Dual-Mode Bluetooth MCU and sensors

CYBT-213043 Mesh board with CYW20819 Dual-Mode Bluetooth MCU and sensors

These kits are prefect for wireless mesh connected lighting and switching because all the necessary hardware like motion sensor, ambient light sensor, switch and GPIO pins are available to control external LED lamp or electromagnetic relay for mains load.

3 white LED boards will be used for the lights. These external LEDs will be controlled over GPIO P12, which will drive the base of S8050 NPN transistor (through 1 k resistor) to switch power to these LEDs

White LED

White LED

White LED

As for powering each set of hardware, 2 AA will provide power through CR2032 power traces.

Powering with 2x AA

Powering with 2x AA

Powering with 2x AA

Practical consideration

Above hardware setup is suitable for testing range and stability of the lighting network. But it is just a prototype setup, actual product will use AC to DC power supply for the Bluetooth Hardware and Sensors. For the lights, relay or AC LED driver circuits may be necessary

Bluetooth Mesh Basics

Bluetooth Mesh is many to many communication network of large number of devices (nodes), where each device can play different kind of roles. Here is a very brief introduction to Bluetooth Mesh :-

  • StandardNode: Every node in a mesh network with the ability to both send and receive mesh messages
  • RelayNode: Receive mesh messages and re-transmit for network range extension. To avoid re-transmission of same message, relay node caches messages to prevent looping
  • Low Power Node: Battery powered and usually sleeps/stays in low power mode most of the time, then wakes periodically, sends message (e.g. sensor data) and goes back to sleep again. Low power nodes must have a friend node with in it's range to do other stuffs.
  • Friend Node: Friend nodes are necessary for Low Power Nodes (LPN) to receive messages while sleeping. A Friend node can keep messages for their adjacent LPNs, when LPN wakes up, it asks its friend node to provide messages addressed toward it.
  • GATT Proxy Node: BLE and Bluetooth Classic devices can not directly interact with Bluetooth Mesh Nodes. Since, most phones and laptops are BLE devices, there is no direct way to interact with a mesh network. This is where GATT Proxy comes in, it allows BLE devices to talk with other mesh nodes through GATT Proxy node. A node can act as GATT proxy (dual band BT) translating BLE to MESH communication.

Nodes (devices) in Bluetooth Mesh Network

Nodes (devices) in Bluetooth Mesh Network

Nodes (devices) in Bluetooth Mesh Network

In the sersor_motion.c file following code makes every node used in this project a combination of Relay, Friend and GATT proxy


Client, Server and Control Models

  • Server: Sends/Changes data based on Clients GET/SET requests.
  • Clients: Send GET/SET requests to Server
  • Control: Acts both as a Client and a Server.

1 / 2mesh model

mesh model

mesh model



This project is a control model, because every light is a switch to itself and other lights in the network.


Advertising and Provisioning

Mesh device(node) that is not part of any network, will keep advertising it's name, UUID, device type icon like a BLE Beacon.

A provisioning device running a provisioning app will scan and make a BLE GATT connection to provision the rouge device(node) with the network information.

The provisioning process assigns the netkey and the unicast/group address of the primary element.

Once the device is provisioned it will be able to receive and decode BLE Mesh packets. Then the provisioning application will to send the rest of the configuration information like group subscriptions, application keys. Now the device will become a part of that mesh network

Once multiple devices are provisioned to the same mesh network, each node can communicate with other nodes through mesh messaging.

Programming, Flashing Firmware & Provisioning

Bluetooth Mesh development with ModusToolbox is highly abstracted away, so the low level hardware details are not exposed. Using APIs and Element Models with the help of example codes, firmware development can be done relatively easily.

Following video shows how to add drivers, snip codes and example project for CYBT213043 Mesh kit :

Programming in Modustoolbox

Programming Steps (above video)

  • Install and Run ModusToolbox 2.0
  • Name a new Workspace and chose folder location
  • Click New Application > CYBT213043-MESH >Next
  • Now select wiced_btsdk first ( this order is important) >Next >Finish
  • Then select Mesh-Snip-213043MESH > Next > Finish (optional)
  • Finally select Mesh-Demo-213043MESH >Next > Finish
  • In the project explorer (left corner) all the examples will be available

This project is a combination of following 3 example projects and some of my own code :




Open MESH_sensor_motion and MESH_low_power_led,

copy "led_control.c" & "led_control.h" files into the MESH_sensor_motion folder as shown in the video.

Now copy the codes attached below this page (code section) and replace the original example codes with my modified codes.

Copy codes from modified "led_control.c" into original "led_control.c"

Copy codes from modified "led_control.h" into original "led_control.h"

Copy codes of modified "sensor_motion.c" into original "sensor_motion.c"

Flash/Upload same code to all the kits one by one

The next video shows how compile+flashing and then provisioning is done:

Programming, Flashing Firmware & Provisioning

Provisioning Steps

Mesh_Client.exe is a Windows application that comes with ModusToolbox, which is used to provision mesh devices to a network. It can be found in this location:-

  • Run Mesh_Client.exe in Windows 10 machine
  • Type a Network name (1st time) and click create network
  • Click "Open" (wait till 'done' msg on Trace window [below])
  • Click "Scan Unprovisioned" and wait
  • Click "Stop Scan" when unprovision devices UUID shows with names
  • Click " Provision and Configure"
  • wait till 'done' msg on Trace window
  • Click "Close" to save network configuration to saved inside device

note:Clicking randomly on mesh client app might hang the app, be patient, provisioning takes nearly a minute or so !

External References

Bluetooth 1 to 5 : Classic, Low Power and Mesh

Bluetooth Mesh Fundamentals

Mesh Specifications in Details

Multiway Switching

Note: I was suppose to submit a project for Cypress MESH contest, but during the contest, I didn't receive these kits on my hand. These kits came to me after 2 months after the contest was over. So, I will make up for that with this submission.

Schematics, diagrams and documents

Light Interfacing with Board

CYBT 213043 Board Sch

By Cypress Semiconductor



Provisioner App (Windows Android).zip

Provisioning App & Light Control App By Cypress Semiconductor



Controls LED lamp and status LEDs


All Bluetooth mesh staffs and more .............


Leave your feedback...