KalbeAbbasRachel Janse van Rensburg
Published © MIT

Visualizing Vibrations in Real-Time with XinaBox and Ubidots

Learn how to make a vibration sensor that sends its vibration values to Ubidots IoT platform to visualize in real-time.

BeginnerFull instructions provided6 minutes783
Visualizing Vibrations in Real-Time with 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

Software apps and online services

Arduino IDE
Arduino IDE
Ubidots
Ubidots

Story

Read more

Code

Vibrations Sensor

C/C++
Enter your WiFi SSID and password, Ubidots TOKEN where required.
/*************************************************************
  This is an examples for getting all critical data from SI01

  You can buy one on our store!
  -----> https://xinabox.cc/products/SI01

  Supported on the all ☒CHIPs
  
  The sensor communicates over the I2C Bus.
  
*************************************************************/

#include <xCore.h>
#include <xSI01.h>

#include "UbidotsMicroESP8266.h"

#define TOKEN  " "  // Put here your Ubidots TOKEN
#define WIFISSID " " // Put here your Wi-Fi SSID
#define PASSWORD " " // Put here your Wi-Fi password

xSI01 SI01;
Ubidots client(TOKEN);

#define PRINT_SPEED 250
static unsigned long lastPrint = 0;

void setup() {
  // Start the Serial Monitor at 115200 BAUD
  Serial.begin(115200);
  client.wifiConnection(WIFISSID, PASSWORD);
  
  // Set the I2C Pins for CW01
  #ifdef ESP8266
    Wire.pins(2, 14);
    Wire.setClockStretchLimit(15000);
  #endif

  Wire.begin();
    
  if (!SI01.begin()) {
    Serial.println("Failed to communicate with SI01.");
    Serial.println("Check the Connector");
  } else {
    Serial.println("start successful");
  }
  millis();
}

void loop() {
  // Read and calculate data from SL01 sensor
  SI01.poll();
  float vib=(sqrt(sq(SI01.getAX())+sq(SI01.getAY())+sq(SI01.getAZ()))-1)*10.0;

  if ( (lastPrint + PRINT_SPEED) < millis()) {
    printAccel(); // Print "A: ax, ay, az"
    Serial.println();
    client.add("vibrations", vib);
    client.sendAll(true);
    lastPrint = millis(); // Update lastPrint time
  }
}

void printAccel(void) {
  /*Serial.print("A: ");
  Serial.print(SI01.getAX(), 2);
  Serial.print(", ");
  Serial.print(SI01.getAY(), 2);
  Serial.print(", ");
  Serial.println(SI01.getAZ(), 2);

  Serial.print("Vibration");*/
  Serial.println((sqrt(sq(SI01.getAX())+sq(SI01.getAY())+sq(SI01.getAZ()))-1)*10.0);
}

Credits

KalbeAbbas

KalbeAbbas

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

Rachel Janse van Rensburg

8 projects • 5 followers
Thanks to XinaBox.

Comments