Visualizing Vibrations in Real-Time with XinaBox and Ubidots

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 visualise in real-time.

XinaBox produces a range of 80+ modular xChips, which include cores/CPUs, sensors, power, communication, output, and storage, using a connectivity standard without wires, soldering, breadboards or hardware knowledge

The xChip CW01 (ESP82666 Core) is a microprocessor and Wi-Fi module, that enables users to send/receive data from XinaBox's modular xChips to/from the cloud.

xChip SI01 (LSM9DS1) is an IMU 9DoF module that comprises of 3 sensors, an accelerometer that measures acceleration of the X, Y and Z axes, a magnetometer that computes orientation to magnetic north, on the X, Y and Z axes, therefore we can calculate which direction we are facing as well as the angle at which we are leaning. The last sensor is the gyroscope that measures our orientation to the center of the earth.

Vibration sensors are used in a variety of applications, such as in industrial machines to detect faults. The xChip SI01’s accelerometer detects static and dynamic acceleration in three axes. Using the acceleration values, we can determine the vibrations and visualize them on a graph.

By the end of this guide you will be able to build your own vibration sensor using XinaBox xChips and Ubidots that will display a real time graphical plot on the Ubidots dashboard.

Requirements

Step-by-Step

  1. Hardware Setup
  2. Installing Arduino Libraries
  3. Code
  4. Result
  5. Summary

1. Hardware Setup

1. Connect xChips CW01, SI01 and IP01/IP02 together using the XC10 xBus connectors. You may connect it as shown in the image below. Please see this guide on how to assemble xChips generally.

2. Then connect IP01/IP02 to the USB port of PC.

3. Select “XinaBox CW01” Board in Arduino IDE for uploading code, after installing required Arduino cores/libraries.

2. Installing Arduino Libraries

1. Install Arduino IDE 1.8.8

2. Install these cores/libraries into Arduino IDE:

NOTE: If you are not familiar with how to install libraries, please refer to the links: Installing Arduino libraries and Installing cores.

3. 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);
}

4. Result

For demonstration, I have used my mobile phone as a vibrator. Notice that the graph is a straight line until I turn on vibrations.

5. Summary

In this project we have shown how to make a vibration sensor using XinaBox xChips CW01 and SI01. The project plots real time vibration values on the Ubidots dashboard to visualize. The project is useful in detecting faulty conditions of machines. The project is simple to build and requires little or no hardware knowledge.

Previous article Build a Weather Station using XinaBox xChips and Azure IoT
Next article Build a Weather Station with XinaBox and Okdo IoT Cloud