KalbeAbbas
Published © MIT

Build a Bicycle Theft Detector Using XinaBox and Ubidots

Learn how to build bicycle theft detector that sends email alerts to the owner when motion in bicycle is detected using Xinabox xChip SI01.

IntermediateFull instructions provided30 minutes1,306
Build a Bicycle Theft Detector Using XinaBox and Ubidots

Things used in this project

Hardware components

CW01
XinaBox CW01
×1
IP02
XinaBox IP02
×1
SI01
XinaBox SI01
×1
XC10
XinaBox XC10
×1
PB04
XinaBox PB04
×1

Software apps and online services

Arduino IDE
Arduino IDE
Ubidots
Ubidots

Story

Read more

Code

code

Arduino
/* Bicycle theft detection using xChip SI01
*/
 
#include "UbidotsMicroESP8266.h"
#include "xSI01.h"
 
#define DEVICE  "biketheft"  // Leave it as is
#define VARIABLE  "button"  // Leave it as is
#define TOKEN  ""  // Put here your Ubidots TOKEN
#define WIFISSID "" // Put here your Wi-Fi SSID
#define PASSWORD "" // Put here your Wi-Fi password
 
Ubidots client(TOKEN);
xSI01 SI01; //Declare SI01 Object
float alert; //Variable to indicate alert
static unsigned long tick;
static unsigned long timer;
 
void setup() {
  
    #ifdef ESP8266
      Wire.pins(2,14);
      Wire.setClockStretchLimit(15000);
    #endif
 
    Wire.begin();
 
    SI01.begin();  //Begin SI01 sensor
  
    Serial.begin(115200);
    client.wifiConnection(WIFISSID, PASSWORD);  //Connect to the specified Wi-Fi AP
    client.setDataSourceLabel(DEVICE);
    alert=0.0;
    tick=millis();
    timer=millis();
    //client.setDebug(true); // Uncomment this line to set DEBUG on
}
 
void loop() {
 
    SI01.poll();  //poll SI01 sensor
    
    float value = client.getValueWithDevice(DEVICE, VARIABLE);  //Get Ubidots Button state (Enable/Disable)
    float bikeVib = abs(sqrt(sq(SI01.getAX())+sq(SI01.getAY())+sq(SI01.getAZ()))-1.0);  //Detect movements in bicycle
    
    if(value==1.0)  //Enable alert if Ubidots IoT button is enabled
    {
      if(bikeVib>=0.05)   //Trigger alert if bikeVib exceeds threshold value 0.05
      {
        alert=1.0;
        timer=millis();
      }else{
        if(timer + 5000 < millis())
        {
          alert=0.0;
        }
      }
      
    }else if(value==0.0){   //Disable alarm if Ubidots IoT button is disabled
      alert=0.0;
    }
 
    if(tick + 1000 < millis())
    {
      client.add("alert",alert);
      client.sendAll(true); //Send alert values to ubidots
      tick=millis();
    }
}

Credits

KalbeAbbas

KalbeAbbas

25 projects • 20 followers
An enthusiastic and dedicated Electronic engineer graduated from SSUET Karachi, Pakistan. Loves to discover Embedded electronics projects.

Comments