Project in progress

Arduino 101 BLE App © GPL3+

I want to show you how to make an application and connect it with the Arduino 101 platform for Internet of Things applications.

  • 4,981 views
  • 24 comments
  • 36 respects

Components and supplies

Apps and online services

About this project

Android App for Arduino

I've looked many times on the internet, for examples and tutorials to make an Android application for my Arduino 101. I did not find much information about it and so I started to investigate, and here I have a functional demonstration.

I use MIT App Inventor and my application, it has 2 buttons that control the status of 2 LEDs on my breadboard and I can also control them by voice, and lastly the application shows the temperature of a DHT22 sensor. It's an all in one to start doing domotics projects.

I call it the hello world of domotics!

Comments

Any questions or comments, I will be very grateful to respond.

*Soon I will record a video showing the operation, since I need to use my smart phone to test the application and I do not have another camera. *

Schematics

Simple
Untitled sketch bb xh9hopiwcz

Code

Arduino 101 code Arduino
My code
/*Made by Alexis Santiago Allende Last Update 17/03/17*/
#include <CurieBLE.h>
BLEPeripheral blePeripheral;//BLE Peripheral Device (Arduino Device)
BLEService demo111("19b10010-e8f2-537e-4f6c-d104768a1214"); // BLE demo111 Service

// BLE demo111 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 and things
#include "DHT.h"
#define DHTPIN 7
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

long previousMillis = 0;  // last time the sensor was checked, in ms
const int green = 13; // pin to use for the green light
const int red = 11;// pin to use for the red light
boolean a = LOW, b = LOW; //Control variables


void setup() {
  Serial.begin(9600);
  dht.begin();//sensor begin
  pinMode(green, OUTPUT);
  pinMode(red, OUTPUT);
  // set advertised local name and service UUID:
  blePeripheral.setLocalName("Demo111");
  blePeripheral.setAdvertisedServiceUuid(demo111.uuid());
  // add service and characteristic:
  blePeripheral.addAttribute(demo111);//service 
  blePeripheral.addAttribute(buttons);// add the buttons characteristic
  blePeripheral.addAttribute(sensors); // add the sensor characteristic
  // set the initial value for the characeristic:
  buttons.setValue(1);
  // begin advertising BLE Light service:
  blePeripheral.begin();
  Serial.println("Demo111 service begin!");
}

void loop() {
  // listen for BLE peripherals to connect:
  BLECentral central = blePeripheral.central();
  digitalWrite(green, LOW);
  digitalWrite(red, LOW);
  // if a central is connected to peripheral:
  if (central) {
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());

    // while the central is still connected to peripheral:
    while (central.connected()) {
      // if the remote device wrote to the characteristic,
      // use the value to control the leds:
      if (buttons.written()) {
        if (buttons.value() == '1' && a == LOW) { // 1 in ASCII

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

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

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

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

          digitalWrite(red, LOW);          // will turn the LED off
          b = LOW;
        }
      }

      long currentMillis = millis();
      // if 10s have passed, check the sensor:
      if (currentMillis - previousMillis >= 10000) {
        previousMillis = currentMillis;
        updateSensor();
      }
      //finish
    }
    // when the central disconnects, print it out:
    Serial.print(F("Disconnected from central: "));
    Serial.println(central.address());
  }
  else
  {
    digitalWrite(green, LOW);
    digitalWrite(red, LOW);

  }
}

void updateSensor() {
  int temp=dht.readTemperature();//read temperature 
  sensors.setValue(temp);//send temperature value
  Serial.println(temp);//if you want check temperature i serial monitor
}
Demo111.aiaArduino
App Inventor Code, if you want try make, you can download
No preview (download only).

Comments

Similar projects you might like

Pac-Man LED Pixel Panel Costume

Project tutorial by Ben Muller

  • 4,381 views
  • 3 comments
  • 78 respects

LoRa Gateway for DeviceHive

Project tutorial by DeviceHive IoT team

  • 1,110 views
  • 2 comments
  • 16 respects

IoT Bird Feeder with Sigfox and Tweeter

Project showcase by Gaël Porté

  • 326 views
  • 0 comments
  • 7 respects

Raspberry Pi and Arduino Laptop

Project tutorial by Dante Roumega

  • 17,563 views
  • 6 comments
  • 44 respects

SmartWay

Project tutorial by Universum

  • 173 views
  • 0 comments
  • 4 respects

Arduino-Based Automatic Guitar Tuner

Project tutorial by Ben Overzat

  • 3,016 views
  • 0 comments
  • 10 respects
Add projectSign up / Login