Project tutorial
Arduino 101 Home BLE System

Arduino 101 Home BLE System © GPL3+

My project presents a domotic box with several features that can be controlled with an app, using Bluetooth low energy

  • 11 respects

Components and supplies

Apps and online services

About this project

The home automation box.

The home automation has been improving over the years to offer a more robust and easy to handle control experience for the final consumer. In this project I want this prototype that is a domotic box for personal use that offers the advantages of being simple to handle for the user, has a android app that offers operating facilities. To make this project i use the arduino 101 that has integrated the bluetooth of low energy that is the one that we used to communicate with the smartphone and the application was made with app inventor 2.

The idea

I want to automate my house, but I am a student and as a student, I live in a house shared by several students and each has a room. And I think the best way to automate the house is through independent modules, since each person has different needs and each person wants their own privacy. And using my knowledge, arduino, and its components, would be an economic task.


To participate in the contest I needed to use Arduino 101, so that aspect was essential, the next aspect is the application and I decided to do it through App Inventor 2 since it is easy to implement a bluetooth communication between arduino and my android device.

The code

The part that was important and difficult for me was the use of the services and features offered by bluetooth 4.0. All that includes the bookstore CuriBLE and on the other side of the screen I show as my bluetooth service and then use 2 features, one to send data to Arduino and another to receive the data from the sensors.

Use a 16X2 LCD to display data related to the system and on the bottom the pins that were used are shown.

The DHT22 sensor uses pin 8.

The ultrasonic sensor uses pins 6 and 7.

In the image below you can see how they used the rest of the pins of the Arduino 101

Now I will explain the operation of the system, the code can review it, is properly commented.

My system

When the box lights up you can see actually time thanks for RTC integrated in Arduino 101 and the status LED in red which means it is not connected and on your screen the following message.

But so the system has activated the ambient light sensor that turns on or off an output depending on whether there is light or not. In this example you will be connected to a light bulb. This is commonly used for exterior lights. Also in this mode, the ultrasonic sensor is activated, if someone approaches within 30cm of the box, it will emit an alarm. It is useful for intruders.

The system changes state when a bluetooth device is paired with it. And then the status LED changes to blue and the message on the lcd screen changes. The "App connected" message is now displayed on the first line and the second shows the temperature and humidity sensor (DHT22)

In this, the intruder sensor and the light sensor, which can be re-enabled from the application, are disabled here, the application already has complete control over the system.

The app inventor code

The screen of my application is shown below.

I made it simple and with large control buttons because I have my fingers wide and in any application, I am usually clumsy and the buttons do not fit with me.

When opening the application, start looking for a device with bluetooth, if it finds it, the button appears with the legend "Select Device" and pressing the button, the nearby devices exit.

My application is called Pandhoit and I choose it.

And then in the lower part you can see the legend "connected" and the values of the temperature and humidity can be seen and are being updated every 10 seconds. The control buttons are gray, meaning they are disabled, if pressed change color and that means that they light something. The buttons on show below.

The first 4 (bulb icons )are the ones that control the outputs of the relay module and can turn on or off things like light bulbs, waffle machines, fans, appliances, etc. The button with the name Ultra, is the one that activates or deactivates the ultrasonic sensor so that when detecting someone less than 30cm then emits an alarm. The next button (alarm) is to test the alarm, check its correct operation.

The next button is to activate or deactivate the light sensor, if the sensor is activated then the button 4 (bulb) is deactivated and the output 4 will light according to the value of the sensor. The last button is that of the temperature sensor, if it is activated, then when the temperature reaches 25 degrees, it will emit the alarm and alert the user, when the temperature drops to 24 or less, then the alarm will stop, this option can be Use for air conditioning or just a fan instead of the alarm.

All of these buttons can be manually activated by means of the application, but also have the voice command service, the button with the microphone icon when pressed, access to the Google voice recognition service and with it Activate all the above mentioned modes just saying the name of each button.

My box

Below you can see how the boxes are made, the front part is where the status LED is, and the LCD, on the right side is the ultrasonic sensor and on the back is the temperature and humidity sensor, also the buzzer and the connections of the arduino 101, on the left side are the outputs of the relay module and on the top is the ambient light sensor.

My demostration


It was a first project difficult, but in the end it does a good job, I think I make a good contribution, since the objective is met and now my friends try to make their box and so we can all have an own experience of the domotics in our places, Easily and economically.

If anyone is interested, attach the .aia file so they can use my project and the corresponding arduino code. Thanks for reading my project.

APK file

.aia file


/*Made by Alexis Santiago Allende Last Update 25/03/17 Pandhoit system version 1.0*/
#include <CurieBLE.h>
BLEPeripheral blePeripheral;//BLE Peripheral Device (Arduino Device)
BLEService pandhoit("19b10010-e8f2-537e-4f6c-d104768a1214"); // BLE pandhoit Service
//include the CurieTime Library
#include <CurieTime.h>
// BLE pandhoit buttons Characteristic - custom 128-bit UUID, read and writable by central
BLEUnsignedCharCharacteristic buttons("19b10011-e8f2-537e-4f6c-d104768a1214", BLERead | BLEWrite);
// BLE sensor rate Characteristic"
BLEUnsignedIntCharacteristic sensors("19b10012-e8f2-537e-4f6c-d104768a1214", BLERead | BLENotify);
//DHT 22 library 
#include "DHT.h"
#define DHTPIN 8
#define DHTTYPE DHT22
//LCD library
#include <LiquidCrystal.h>
LiquidCrystal lcd(15, 14, 19, 18, 17, 16);

long ts;// pin to use for time of ultasensor
long ds;// pin to use for distance
long previousMillis = 0;  // last time the sensor was checked, in ms
long previoustime = 0;  // last time the sensor was checked, in ms
const int c1 = 2; // pin to use for the light state
const int c2 = 3;// pin to use for the light state
const int c3 = 4; // pin to use for buzzer (alarm)
const int c4 = 5;// pin to use for light sensor
const int d1 = 13; // pin to use for the out control
const int d2 = 12;// pin to use for  the out control
const int d3 = 11; // pin to use for the out control
const int d4 = 10;// pin to use for the out control
const int d5 = 9; // pin to use for the out control (light sensor)
int send_data, datachoice; //  reading from sensor
int tempe=0,humedad=0;//variables for read temperature and humidity
//boolean variables for use to (a)button 1,(b)button 2,(c)button 3,(d)button 4,(e,g)button 5
//(f,g)button 7, (g) lighsensor,
boolean a = LOW, b = LOW,c=LOW,d=LOW,e=LOW,f=LOW,g=LOW,h=LOW,i=LOW,j=LOW,k=LOW,l=LOW,m=LOW,n=LOW,o=LOW,p=LOW,q=LOW; //Control variables
const int Trigger = 6;   //Pin digital 2 para el Trigger del sensor
const int Echo = 7;   //Pin digital 3 para el Echo del sensor

void setup() {
  lcd.begin(16, 2);  // LCD starts
  //set cursor to column 0, row 0
  dht.begin();//sensor begin
  //set time to 1:35:24 on April 4th, 2016. Can you change to your time / date
  setTime(16, 56, 24, 3, 07, 2017);
  pinMode(c1, OUTPUT);//light state
  pinMode(c2, OUTPUT);//light state
  pinMode(c3, OUTPUT);//alarm(buzzer)
  pinMode(c4, INPUT); //light sensor
  pinMode(d1, OUTPUT);//relay module output 1
  pinMode(d2, OUTPUT);//relay module output 2
  pinMode(d3, OUTPUT);//relay module output 3
  pinMode(d4, OUTPUT);//relay module output 4 (light sensor control)
  pinMode(d5, OUTPUT);
  pinMode(Trigger, OUTPUT); 
  pinMode(Echo, INPUT); 
  digitalWrite(Trigger, LOW);
  // set advertised local name and service UUID:
  // add service and characteristic:
  blePeripheral.addAttribute(buttons);// add the buttons characteristic
  blePeripheral.addAttribute(sensors); // add the sensor characteristic
  // set the initial value for the characeristic:
  // begin advertising BLE Light service:
  digitalWrite(c1, HIGH);//Turn on the red indicator light
  lcd.print("No connected!");     // print a simple message
  //set cursor to column 0, row 1
  lcd.print("Time:");     // print a message


void loop() {
  //digitalWrite(c3, LOW);//alarm turn off
  lightsens();//When the system is deactivated, the light sensor is activated for light control
  ultra();//When the system is deactivated, the distance sensor is activated for intruder alarm control
   //create a character array of 8 characters for the time
 char clockTime[8];
 //use sprintf to create a time string of the hour, minte and seconds
 sprintf(clockTime, "%2d:%2d:%2d", hour(), minute(), second());
  //set cursor to column 6, row 1
 lcd.setCursor(6, 1);
 //print the time string over lcd
  // listen for BLE peripherals to connect:
  BLECentral central = blePeripheral.central();
  // if a central is connected to peripheral:
  if (central) {
    digitalWrite(c1, LOW);//Turn off the red indicator light
    digitalWrite(c2, HIGH);//Turn on the blue indicator light
    // while the central is still connected to peripheral:
    while (central.connected()) {
      lcd.clear();//clear lcd display
      lcd.print("App connected!");     // print a message
      lcd.print("Temp:");     // print a message
      lcd.print("C");     // print a message
      lcd.print("Hum:");     // print a message
      lcd.print("%");     // print a message

      // if the remote device wrote to the characteristic,
      // use the value to control the leds:
      if (buttons.written()) {
        change();// If in the app, I press a button then something happens
       if (g==HIGH) {//if botton of light sensor was pressed then this sensor is activate to control d4 output
        if (i==HIGH) {//if botton of temp sensor was pressed then this sensor is activate to control c3 alarm
       if (l==HIGH) {//if botton of ultrasonic sensor was pressed then this sensor is activate to control c3 alarm
      long currentMillis = millis();
      // if 10s have passed, check the sensor:
      if (currentMillis - previousMillis >= 10000) {
        previousMillis = currentMillis;
    // when the central disconnects, print it out:
    Serial.print(F("Disconnected from central: "));
    digitalWrite(c1, HIGH);//Turn on the red indicator light
    digitalWrite(c2, LOW);////Turn off the blue indicator light
    lcd.print("No connected!");     // print a message
    lcd.print("Time:");     // print a message
    digitalWrite(c1, HIGH);//Turn on the red indicator light
    digitalWrite(c2, LOW);////Turn off the blue indicator light


void updateSensor() { //function to read and send temperature and humidity
  humedad =dht.readHumidity();
  int humedad1 =100+humedad;

if (datachoice == 0)
        send_data = tempe;//send temperature
        datachoice = 1;
        lcd.print(tempe);     // print a message
      else if(datachoice == 1)
        send_data = humedad1; //send humidity
        datachoice = 0;  
        lcd.print(humedad);     // print a message


void lightsens()//function to able and disabled lightsensor
    digitalWrite(d4, LOW);
    digitalWrite(d4, HIGH);

void change()//function to read values obtained in the app
       if (buttons.value() == '1' && a == LOW) { // 1 in ASCII

          digitalWrite(d1, HIGH);         // will turn the LED on
          a = HIGH;
        } else if (buttons.value() == '1' && a == HIGH)  {  //when 1 was read again (second time)          

          digitalWrite(d1, LOW);          // will turn the LED off
          a = LOW;

        if (buttons.value() == '2' && b == LOW) { // 2 in ASCII

          digitalWrite(d2, HIGH);         // will turn the LED on
          b = HIGH;
        } else if (buttons.value() == '2' && b == HIGH)  { //when 2 was read again (second time)  

          digitalWrite(d2, LOW);          // will turn the LED off
          b = LOW;
        if (buttons.value() == '3' && c == LOW) { // 3 in ASCII

          digitalWrite(d3, HIGH);         // will turn the LED on
          c = HIGH;
        } else if (buttons.value() == '3' && c == HIGH)  { //when 3 was read again (second time)  

          digitalWrite(d3, LOW);          // will turn the LED off
          c = LOW;

        if (buttons.value() == '4' && e == LOW&& g==LOW) { // 4 in ASCII

          digitalWrite(d4, HIGH);         // will turn the LED off
          e = HIGH;
        } else if (buttons.value() == '4' && e == HIGH && g==LOW)  { //when 4 was read again (second time)  

          digitalWrite(d4, LOW);          // will turn the LED off
          e = LOW;

        if (buttons.value() == '5' && d == LOW) { // 5 in ASCII
          l = HIGH;//able ultrasonic sensor
        } else if (buttons.value() == '5'&& d==HIGH)  { //when 5 was read again (second time)  

          l = LOW;//disable ultrasonic sensor
         if (buttons.value() == '6' && h == LOW && i==LOW) { // 6 in ASCII

          digitalWrite(c3, HIGH);         // will turn the alarm(buzzer) on
          h = HIGH;
        } else if (buttons.value() == '6' && h == HIGH && i==LOW)  { //when 6 was read again (second time)  

          digitalWrite(c3, LOW);          // will turn the alarm(buzzer) off
          h = LOW;
        if (buttons.value() == '7' && f == LOW) { // 7 in ASCII

          g = HIGH;//able light sensor
        } else if (buttons.value() == '7'&&f==HIGH)  { //when 7 was read again (second time)  

          g = LOW;//disable light sensor
          if (buttons.value() == '8' && j == LOW) { // 8 in ASCII
          i = HIGH;//able temperature sensor
        } else if (buttons.value() == '8'&& j==HIGH)  { //when 8 was read again (second time)  

          i = LOW;//disable temperature sensor

void ultra(){//function to read and control ultrasonic sensor
  digitalWrite(Trigger, HIGH);
  delayMicroseconds(10);          //Send a pulse of 10us
  digitalWrite(Trigger, LOW);
  ts = pulseIn(Echo, HIGH); //obtain width of pulse
  ds = ts/59;             //change value to centimeters
  && m==LOW){//if distance is lower than 5 centimeter then able  alarm
  else if(ds>=30&&n==LOW)//if distance is upper than 5 centimeter then disable  alarm

void tempalert()//function to control temperature between 24 and 25 degrees 
     if(tempe>=25 && p==LOW)//if temperature above of 25 degrees
      digitalWrite(c3,HIGH);//turn on alarm
    else if(tempe<=24&&q==LOW)//if temperature is under 24 degrees
      digitalWrite(c3,LOW);//turn off alarm
App inventor project code
No preview (download only).


Pandhoit bb waxamiohcg


Similar projects you might like

Arduino 101 BLE App

Project in progress by Alexis Santiago Allende

  • 51 respects

Smart Garbage Monitoring System Using Arduino 101

Project tutorial by Technovation

  • 36 respects

Arduino 101 BLE RGB Lamp

Project tutorial by Gustavo Reynaga

  • 10 respects

SMS alerts for arduino 101 BLE

Project tutorial by Alexis Santiago Allende

  • 8 respects

My First Arduino 101 Car Controlled by BLE

Project tutorial by Alexis Santiago Allende

  • 9 respects
Add projectSign up / Login