Wen-Liang Lin
Created February 28, 2019 © GPL3+

Follow me lighting

Use Bluetooth to control LED lighting. That you don't worry about forgetting where is the wall switch and if you close it when you leave the

BeginnerShowcase (no instructions)1 hour20

Things used in this project

Hardware components

Rapid IoT Prototyping Kit
NXP Rapid IoT Prototyping Kit
×1
LinkIt 7697
LinkIt 7697
×1
General Purpose Transistor NPN
General Purpose Transistor NPN
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Li-Ion Battery 1000mAh
Li-Ion Battery 1000mAh
×1
LED LAMP
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

connection

Code

led_central

Arduino
Linkit 7697
#include <LBLE.h>
#include <LBLECentral.h>

LBLEClient client;

int losecnt;
int led0 = 7;
int percnt;
int mathbuf;
int scanRSSI;
void setup() {
  //Initialize serial
  Serial.begin(115200);
  pinMode(led0, OUTPUT);#include <LBLE.h>
#include <LBLECentral.h>

LBLEClient client;

int losecnt;
int havedevice;
int led0 = 7;
int percnt;
int mathbuf;
int scanRSSI;
void setup() {
  //Initialize serial
  Serial.begin(115200);
  pinMode(led0, OUTPUT);
  // Initialize BLE subsystem
  Serial.println("BLE begin");
  LBLE.begin();
  while (!LBLE.ready()) {
    delay(10);
  }
  Serial.println("BLE ready");
}

void printDeviceInfo(int i) {
  Serial.print(i);
  Serial.print("\t");
  Serial.print(LBLECentral.getAddress(i));
  Serial.print("\t");
  Serial.print(LBLECentral.getAdvertisementFlag(i), HEX);
  Serial.print("\t");
  scanRSSI = LBLECentral.getRSSI(i);
  Serial.print(scanRSSI);
  Serial.print("\t");
  const String name = LBLECentral.getName(i);
  Serial.print(name);
  if(name=="PAF6D"&&scanRSSI>-80)
  {
    havedevice=1;
    digitalWrite(led0,HIGH);
  }
  
  if(name.length() == 0)
  {
    Serial.print("(Unknown)");
  }
  Serial.print(" by ");
  const String manu = LBLECentral.getManufacturer(i);
  Serial.print(manu);
  Serial.print(", service: ");
  
  if (!LBLECentral.getServiceUuid(i).isEmpty()) {
    Serial.print(LBLECentral.getServiceUuid(i));

  } else {
    Serial.print("(no service info)");
  }
  Serial.println();
}

void loop() {
  static LBLEAddress serverAddress;
      LBLECentral.scan();
      delay(1000);
      LBLECentral.stopScan();


      // enumerate advertisements found.
      Serial.print("Peripherals found = ");
      Serial.println(LBLECentral.getPeripheralCount());
      Serial.println("idx\taddress\t\t\tflag\tRSSI");
      percnt = LBLECentral.getPeripheralCount();

      if(percnt == 0)
      {

        losecnt++;
      }
      else
      {

        for (int i = 0; i < percnt; ++i) 
        {
          printDeviceInfo(i);
        }
        if(havedevice==1)
        {
          losecnt=0;
          havedevice=0;
        }
        else
        {
          losecnt++;
        }
      }
      Serial.print("LoseCnt:");
      Serial.print(losecnt);
      Serial.println();

      if(losecnt>5)
      {
        losecnt=0;
        digitalWrite(led0,LOW);
        Serial.print("Lose Device");
        Serial.println();
      }


}

Credits

Wen-Liang Lin

Wen-Liang Lin

14 projects • 20 followers
Hi, I am momososo

Comments