Sunday, June 7, 2015

Intro to Bluetooth Low Energy (BLE) and the BLE Micro

In this video we will take a look at Bluetooth Low Energy or Bluetooth Smart and compare it to classic Bluetooth. From there we will look at how to get started with the BLE Micro module and look at how to communicate with it from an iOS device and another BLE Micro Module.




************************Arduino Code****************************************
/*
  This sketch is part of a video tutorial on the ForceTronics YouTube Channel for using the BLE Micro module which uses Bluetooth low energy. 
  The bluetooth module is connected to an Arduino and the Arduino is connected to an LED. 

  This code is in the public domain.
 */

// Pin 7 has a LED connected to it
int led = 7;

// the setup routine runs once when you press reset:
void setup() {
  
  Serial.begin(115200);
  // initialize the digital pin as an output and set it low initially
  pinMode(led, OUTPUT);
  digitalWrite(led, LOW);
}

// the loop routine runs over and over again forever:
void loop() {
  delay(30);
  String t; //create an empty string to store messages from Android
  while(Serial.available()) { //keep reading bytes while they are still more in the buffer
    t += (char)Serial.read(); //read byte, convert to char, and append it to string
  }
  
  if(t.length()) { //if string is not empty do the following
    if(t == "on") { //if the string is equal to "on" then turn LED on
      digitalWrite(led, HIGH); //Set digital pin to high to turn LED on
      Serial.write("LED is on"); //Tell the Android app that the LED was turned on
    }
    else if (t == "off") { 
      digitalWrite(led, LOW);  
      Serial.write("LED is off");
    } // turn the LED off by making the voltage LOW
  }
}

No comments:

Post a Comment