SmartLamp project demonstrates how easy can be to create the prototype of an LED lamp that you can control with gestures or using a mobile phone.
The project is based on STM32 microcontroller, which is used together with a proximity sensor to control LED lights with gestures: switch on/off LED and modulate light intensity just by approaching hand or fingers.
The integration of Bluetooth connectivity gives the possibility to set the LED color (Red, Green, Blue, White) using a mobile application.
The embedded application was developed using ARM mbed development environment.
Step 1: Hardware Setup and BOM
The Hardware boards are part of a prototyping development environment available by STMicroelectronics.
The boards used in this project are the following:
- Main microcontroller board powered by a 32bit MCU : STM32 Nucleo
- Bluetooth connectivity chip integrated into an expansion board : X-NUCLEO-IDB04A1
- Proximity sensor integrated into an expansion board : X-NUCLEO-6180XA1
Expansion boards can be easily plugged on top of STM32 Nucleo by using Arduino connectors. Simply take care of letting the proximity sensor on top (i.e. the order of the boards should be STM32 Nucleo, X-NUCLEO-IDB04A1, X-NUCLEO-6180XA1).
Verify that X-NUCLEO-6180XA1 board is configured to be used as proximity sensor (Red switch on-board set to "Range", see details in User Manual).
The rest of the Hardware BOM is what is needed to connect the Nucleo board with an LED strip light:
- 3x 100ohm resistors
- 3x TIP122 NPN transistors
- 1x power jack
- 1x RGB LED Light Strip (AglaiaLT-S2)
- Spare cables
See the connections in the schematic. More details on strip LED wiring can be found in this Instructable.
Step 2: Import the Mbed Project
Create a free developer account in ARM mbed.
Go to https://developer.mbed.org/users/EmbeddedIoT/code... and import the project into your online compiler.
In your online compiler, verify to have the right platform selected (NUCLEO-F401RE, see picture).
Step 3: Compile the Project and Flash the Board
Click on compile button in your mbed online compiler. When build is finished, the resulting binary is automatically downloaded.
When you connect your Nucleo board to a PC, the board is recognised as a mass storage device; you can flash the firmware simply by copying and pasting the binary file into it (see picture).
Step 4: Mbed Application
The firmware of the project is based on this mbed test application for X-NUCLEO-6180XA1.
The main application is composed by two parts:
- After reset the firmware initialises the Bluetooth board and waits to receive commands to set LED color; commands can be received from a mobile app (see next step). If no message is received in 45sec., the firmware continues using white as selected color. Timeout can also be skipped by pressing the blue USER button of the Nucleo board
- The proximity sensor on-board X-NUCLEO-6180XA1 has a range from 0 to 20cm (see specs). The range returned by the sensor is converted into a percentage and used to modulated the intensity of the LED colors (below 10% the LED is switched off, above 90% the LED color is set to 255).
It is not possible to change the color via Bluetooth while the proximity sensor is active; application need to be restarted in that case by pressing the Nucleo RESET button.
Step 5: Run the Application
I didn't develop a specific mobile application for this project; rather, I used this Bluetooth scanner app, in order to connect with the board and set LED color.
As described in previous section, it is only possible to change LED color after RESET of the board; you can use the BLE scanner app to connect with the board (it is advertised as SmartLamp, see picture), and type in a number to change color ('0' for white, '1' for red, '2' for blue, '3' for green; see picture).
Once the color is set, or after a timeout of 45 seconds, the application starts to measure proximity range and changes LED light intensity based that value; range measured is also displayed in the LCD mounted in the X-NUCLEO-6180XA1 expansion board. You can approach your hand to the proximity sensor in order to modulate LED lights or switch it on/off. See video in the following step.
Step 6: Your Smart Table Lamp Is Ready.
See in the video below how quickly you can create a prototype of a LED table lamp that you can control with gestures and a mobile app