Difference between revisions of "Bluetooth Night Light"

From Microduino Wiki
Jump to: navigation, search
(Created page with "{{Language| Bluetooth Night Light }} {| style="width: 800px;" |- | ==Purpose== When ambient light becomes dark, the night light turns on automatically. Using Bluetooth to acce...")
 
Line 3: Line 3:
 
|-
 
|-
 
|
 
|
==Purpose==
+
==Objective==
When ambient light becomes dark, the night light turns on automatically. Using Bluetooth to access the light, you can control the color.  
+
When it gets dark, the night light starts to work. You can control the color and brightness of the light through Bluetooth.
 +
[[File:ble_night_light.jpg|600px|center]]
  
 
==Principle==
 
==Principle==
 +
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.
 +
[[File:ble_night_light-sch.jpg|600px|center]]
  
 
==Equipment==
 
==Equipment==
Line 15: Line 18:
 
|[[Microduino-CoreUSB]]||1||Core board  
 
|[[Microduino-CoreUSB]]||1||Core board  
 
|-
 
|-
|[[Microduino-Sensorhub]]||1||Sensor pinboard  
+
|[[Microduino-Sensorhub]]||1||Sensor pinboard
 
|-
 
|-
|[[Microduino-BT]]||1||Bluetooth module
+
|[[Microduino-BT]]||1||Bluetooth module  
 
|-
 
|-
| [[Microduino-Light]]||1||Photosensitive sensor  
+
| [[Microduino-Light]]||1||Light-sensitive sensor  
 
|-
 
|-
| [[Microduino-Lantern]]||1||Colored light  
+
| [[Microduino-Color LED]]||1||Colored LED light  
 
|-
 
|-
 
| [[Microduino-BM]]||1||Battery management   
 
| [[Microduino-BM]]||1||Battery management   
 
|}
 
|}
  [[File:ble_lamp_light.jpg|600px|center|thumb]]
+
  [[File:ble_night_light-moduino.jpg|600px|center]]
  
==Document==
+
==Preparation==
Android Clinet:  
+
*Setup 1:Use a USB cable to connect the CoreUSB and PC/Mac, then open Arduino IDE.
Note: The new 4.0 version BT needs to be supported by Android version 4.3 and higher. Here we offer Android APP.   
+
[[File:CoreUSB_Ble_pc.jpg|600px|center]]
 +
*Setup 2:Click file >examples > mCookie > _201_CowardlyNightLight_BLE, and download the program. 
 +
[[File: light_indicator-ino.jpg|600px|center]]
 +
* Setup 3:Load the code, choose the right board and COM port for program download after compiling.
 +
[[File: light_indicator-com.jpg|600px|center]]
 +
==Program Description==
 +
“ble()”function is for Bluetooth data receiving and light control. 
 +
*Define Bluetooth Communication serial port.
 +
<source lang="cpp">
 +
#define my_Serial Serial1
 +
</source>
 +
*Define the pin of sensors as well as the number of lights connected.  
 +
<source lang="cpp">
 +
#define PIXEL_PIN    6    // Digital IO pin connected to the NeoPixels.
 +
#define PIXEL_COUNT 2
  
APP download:'''[[File:Microduino-LAMP-APP.zip]]''
+
#define lightSensorPin  A0
 
+
</source>
==Hardware Buildup==
 
*Setup 1:Stack CoreUSB, BT and Sensorhub.
 
[[File:CoreUSB_Ble_Sensorhub.jpg|600px|center|thumb]]
 
*Setup 2:Connect the lantern to Sensorhub’s D6 pin and photosensitive sensor to A0.
 
[[file:mCookie-sensorhub_rule.JPG|thumb|800px|center]]
 
[[File:light_colorled_ble.jpg|600px|center|thumb]]
 
 
 
==Software Debugging==
 
*Setup 1:Build IDE, connect CoreUSB to your PC and download program code.
 
[https://github.com/Microduino/Microduino_Tutorials/blob/master/MCookie_Tutorial/ble_led_light/ble_led_light.ino ble_led_light]
 
*Setup 2:Download Android client, and then decompress, install and open it. It will remind you to open Bluetooth device if you don’t open Bluetooth. 
 
[[File:Microduino_BT_Serial_1.png||300px|center|thumb]]
 
*Setup 3:Click SCAN on top right, select Microduino and connect.
 
[[File:Microduino_BT_Serial_2.png||300px|center|thumb]]
 
*Setup 4:You’ll see Serial Present on top right in default and when it turns to Seerial Ready, you can have normal communication. 
 
[[File:Microduino_BT_Serial_3.png||300px|center|thumb]]
 
 
 
*APP description:
 
**If you have multiple colored lights, you can switch to Multi Color mode to adjust. You can connect six lights to the most. For Single Color mode, no matter how many lights you connect, it shows the same color.
 
**You can adjust the brightness via the circular ring.
 
**and control the light via the bottom switch.
 
[[File:Microduino_BT_Serial_5.png||300px|center|thumb]]
 
  
Code description:
+
*Surrounding light pre-set value: Change the value and you can change the brightness.  
*Choose to adopt Bluetooth control when it is connected.
 
The use of BT serial port needs to be choosed accoding to wire jumpers oon the board. The default serial port is 0:Serial.
 
“ble()”function is for Bluetooth recieving data and lantern controlling.
 
*Ambient light pre-set value—by changing the light value, you can choose under which brightness can turn on the light.  
 
 
<source lang="cpp">
 
<source lang="cpp">
#define Light    100
+
#define lightSwitch  700
 
</source>
 
</source>
 
*Read brightness function   
 
*Read brightness function   
 
<source lang="cpp">
 
<source lang="cpp">
ightValue = analogRead(Light_PIN);
+
sensorValue = analogRead(lightSensorPin);
 
</source>
 
</source>
*Under the circumstance of no Bluetooth connection, the lantern will turn on when the ambient light brightness is less than the pre-set value otherwise it will turn off.   
+
*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.   
 
<source lang="cpp">
 
<source lang="cpp">
if (!color_en && lightValue < Light)
+
  if(sensorValue>lightSwitch) {
  {
+
     Serial.println(sensorValue);
     rainbowCycle(10, 255, 0, 0, 0);
+
     strip.setPixelColor(0, strip.Color(0, 0, 0));
     rainbowCycle(10, 255, 0, 0, 1);
+
     strip.setPixelColor(1, strip.Color(0, 0, 0));
 
+
     strip.show();
    rainbowCycle(10, 0, 255, 0, 0);
+
  } else {
     rainbowCycle(10, 0, 255, 0, 1);
+
      ble();
 
+
      if (!color_en) {
    rainbowCycle(10, 0, 0, 255, 0);
+
        for (int i = 0; i < 1; i++)
     rainbowCycle(10, 0, 0, 255, 1);
+
          rainbow(10);
 
+
      }
    rainbowCycle(10, 255, 0, 225, 0);
+
  }
    rainbowCycle(10, 255, 0, 225, 1);
+
</source>
 
+
==Code Debugging==
    rainbowCycle(10, 247, 139, 5, 0);
+
*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.
    rainbowCycle(10, 247, 139, 5, 1);
+
[[File:CoreUSB_light_ino1.jpg|600px|center]]
 
+
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. 
    rainbowCycle(10, 255, 255, 0, 0);
 
    rainbowCycle(10, 255, 255, 0, 1);
 
  
    rainbowCycle(10, 0, 255, 255, 0);
+
==Hardware Buildup ==
    rainbowCycle(10, 0, 255, 255, 1);
+
*Setup 1:Connect the Color LED to the Sensorhub D6 and the Light sensor to A0.
 +
[[File:night_colorled_ble.jpg|600px|center]]
 +
For the connection of LED, please refer to the picture below. Please be noted of the connection order, which is from LED's IN interfa e to OUT. Here you can control two LED lights at most. 
 +
[[File:CoreUSB_Ble_steup11.jpg|600px|center]]
 +
*Setup 2:Connect the activated battery box with the BM module.
 +
[[File:CoreUSB_Ble_steup2.jpg|600px|center]]
 +
*Setup 3:Stack all modules together without a fixed order. Congratulations! You've finished the circuit buildup.
 +
[[File:CoreUSB_night led_steup3.jpg|600px|center]]
  
    for (int i = 0; i < 3; i++)
+
==APP Debugging==
      rainbow(30);
+
*Setup 1:Scan the two-dimensional code on the left, download Bluetooth Light APP.
  }
+
[[File:app_Ble_steup1.jpg|600px|center]]
  else if (!color_en)
+
*Setup 2:Open the APP after the download and installation. The system will remind you to choose to open Bluetooth if it is disconnected. 
    colorSet(strip.Color(0, 0, 0));</source>
+
[[File:app_Ble_steup2.jpg|600px|center]]
 +
*Setup 3:Click Scan and the phone will start searching Bluetooth devices, which are displayed below. Here you can select Microduino device.
 +
[[File:app_Ble_steup3.jpg|600px|center]]
 +
*Setup 4:After the connection, you can use your phone to control the light.
 +
[[File:app_Ble_steup4.jpg|600px|center]]
  
 
==Result==
 
==Result==
When there is Bluetooth connection, the lantern is controlled via the Bluetooth. While no Bluetooth connection, the lantern will go on when the ambient light brightness is less than the pre-set light value otherwise, it will go off. You can use LEGO to stack with our mCookie sensor to build a beautiful frame.  
+
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.  
 +
[[File:legao_night_led.jpg|600px|center]]
 
==Video==
 
==Video==
  
 
|}
 
|}

Revision as of 10:26, 6 November 2015

Language: English  • 中文

Objective

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

Principle

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

Equipment

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

Preparation

  • 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) {
    Serial.println(sensorValue);
    strip.setPixelColor(0, strip.Color(0, 0, 0));
    strip.setPixelColor(1, strip.Color(0, 0, 0));
    strip.show();
  } else {
      ble();
      if (!color_en) {
        for (int i = 0; i < 1; i++)
          rainbow(10);
      }
  }

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 interfa 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

Result

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

Video