Bluetooth Night Light

From Microduino Wiki
Jump to: navigation, search
Language: English  • 中文


When it gets dark, the night light starts to work. You can control the color and brightness of the light through Bluetooth.

Ble night light.jpg


With the Light sensor to detect light intensity, so system can tell the light status. If the surrounding light is too strong, the Color LED light will turn off. You can use phone Bluetooth to control the color of the light.

Ble night light-sch.jpg


Module Number Function
Microduino-CoreUSB 1 Core board
Microduino-Sensorhub 1 Sensor pinboard
Microduino-BT 1 Bluetooth module
Microduino-Light 1 Light-sensitive sensor
Microduino-Color LED 1 Colored LED light
Microduino-BM 1 Battery management


  • Setup 1: Use a USB cable to connect the CoreUSB and PC/Mac, then open Arduino IDE.
CoreUSB Ble pc.jpg
  • Setup 2: Click file >examples > mCookie > _201_CowardlyNightLight_BLE, and download the program.
Light indicator-ino.jpg
  • Setup 3: Load the code, choose the right board and COM port for program download after compiling.
Light indicator-com.jpg

Program Description

"ble()" function is for Bluetooth data receiving and light control.

  • Define Bluetooth Communication serial port.
#define my_Serial Serial1
  • Define the pin of sensors as well as the number of lights connected.
#define PIXEL_PIN    6    // Digital IO pin connected to the NeoPixels.
#define PIXEL_COUNT  2

#define lightSensorPin  A0
  • Surrounding light pre-set value: Change the value and you can change the brightness.
#define lightSwitch  700
  • Read brightness function
sensorValue = analogRead(lightSensorPin);
  • Judge whether the surround light parameter is lower than the pre-set value or not. If yes, the light will be turned on and can be controlled through Bluetooth. Otherwise, the light will be turned off.
  if(sensorValue>lightSwitch) {
    strip.setPixelColor(0, strip.Color(0, 0, 0));
    strip.setPixelColor(1, strip.Color(0, 0, 0));;
  } else {
      if (!color_en) {
        for (int i = 0; i < 1; i++)

Code Debugging

  • Connect the CoreUSB with a computer, download the program and open the serial monitor. Inside the monitor, you can see light value change received by the Light sensor.
CoreUSB light ino1.jpg

The current setting value is 700. You can try to change the value in the program according to the previously detected data and download the program to see what happens.

Hardware Buildup

  • Setup 1: Connect the Color LED to the Sensorhub D6 and the Light sensor to A0.
Night colorled ble.jpg

For the connection of LED, please refer to the picture below. Please be noted of the connection order, which is from LED's IN interface e to OUT. Here you can control two LED lights at most.

CoreUSB Ble steup11.jpg
  • Setup 2: Connect the activated battery box with the BM module.
CoreUSB Ble steup2.jpg
  • Setup 3: Stack all modules together without a fixed order. Congratulations! You've finished the circuit buildup.
CoreUSB night led steup3.jpg

APP Debugging

  • Setup 1: Scan the two-dimensional code on the left, download Bluetooth Light APP.
App Ble steup1.jpg
  • Setup 2: Open the APP after the download and installation. The system will remind you to choose to open Bluetooth if it is disconnected.
App Ble steup2.jpg
  • Setup 3: Click Scan and the phone will start searching Bluetooth devices, which are displayed below. Here you can select Microduino device.
App Ble steup3.jpg
  • Setup 4: After the connection, you can use your phone to control the light.
App Ble steup4.jpg


Cover the light sensor, or go into the dark environment, the LED light will shine. Then you can use the Bluetooth to control the color of the light. You can also build a beautiful look through Lego since mCookie can be freely stacked LEGO boards.

Legao night led.jpg