Project tutorial
A Posture Detector Sending Bluetooth Data to a Cordova App

A Posture Detector Sending Bluetooth Data to a Cordova App

Prevent back pain by detecting bad posture and correct it immediately!

  • 30 respects

Components and supplies

Apps and online services

About this project

Back pain affects a large amount of people around the world, impacting the health of the spine and leading to many health problems (negative impacts on the quality of life, sleep disorders, respiratory problems...)

Half of back pains are caused by improper posture and could therefore been prevented and cured by correcting the posture. The only requirement is to actually detect a bad posture.

The focus of this project is to answer this problem: build a wearable device that's capable of detecting bad posture and providing instant feedback to allow the wearer to correct his posture immediately. Real-time posture data will also be transmitted by Bluetooth on a mobile app made with Cordova.

For this prototype, I used LEDs to give an indication of the posture but the final product will be equiped with a vibrating module to give haptic feedback.

Step 1: Wiring

Assemble the components by following this circuit diagram:

Step 2: Programming the Arduino board

The program sets the reference position by reading the momentary switch when pressed by the user and does all the calulcations and values conversion from the accelerometer.

See the code below or on codebender here : or on GitHub here :

This project uses the iShield library made by Victor Carreño to send the posture data to the app.

Step 3: Building the mobile application

The application displays the BLE device and allows to connect to it.

Once connected, the angle is received and displayed on the app, and a line indicating the direction of the bending is drawn at the same time.

If the position begins to be considered as bad (yellow led on), the app indicates "warning"; If the position is considered bad (red led on), the app indicates "wrong". You can see that behavior in the photos section below.

There is also a textbox on the app to communicate with the device in bluetooth (useless for this project), you can see those messages on the serial monitor.

See source code on GitHub: and follow the instructions.

Install the app on iOS:

Clone the repo

git clone

Then type the following commands :Navigate to the directory

cd CordovaPostureDetector_BLE/

Install the dependencies

npm install

Add the ios platform (not tested on Android)

cordova platform add ios


cordova build ios


cordova build ios --buildFlag='-UseModernBuildSystem=0'

Open the project in XCode and deploy on your device.

The plugin used to communicate in BLE:



Arduino codeC/C++
This code connects to BLE, calculate the back posture and send posture data.
#include <math.h>
#include "Boards.h"
#include <SPI.h>
#include <Nordic_nRF8001.h>
#include <RBL_nRF8001.h>
#include "iShield.h"

iShield myiShield;

// momentary switch
const int buttonPin = 2;

int LED1 = 3; // Red
int LED2 = 4; // Green
int LED3 = 5; // Yellow

int buttonState = 0; 

// Position set when the momentary witch is pressed
int currentBackPos;

// Value set as the "normal position" (= flat value on my accelerometer as mine is not solder so the angle is already "forward")
int refPos = 15;

//vibration motor digital pin
//int vibePin = 9;

void setup()
  // Init. and start BLE library.
  //pinMode(buzzerPin, OUTPUT);
  pinMode(LED1, OUTPUT); // Red
  pinMode(LED2, OUTPUT); // Green
  pinMode(LED3, OUTPUT); // Yellow
  digitalWrite(LED1,LOW); // Red
  digitalWrite(LED2,LOW); // Green
  digitalWrite(LED3,LOW); // Yellow

  pinMode(2, INPUT); // SwitchButton (to set "normal" position)

void loop()
  //start reading the button state
  buttonState = digitalRead(buttonPin);

  // if msg is sent by bluetooth from the app, write it on the console (not used in that project)
  String message = myiShield.incomingData();
  // Start reading and calculating angles
  float VREF = 5.0;
  // To get those values, play with your accelerometer and put the min and max you find on every x,y,z position
  int xMinVal = 265; int yMinVal = 259;int zMinVal = 281;
  int xMaxVal = 398; int yMaxVal = 393;int zMaxVal = 413;

  int xRead=0, yRead=0, zRead=0;
  int xAng=0, yAng=0, zAng=0;
  double x=0, y=0, z=0;
  int ave = 10;

  // read raw values
  for(int i=0; i<ave ; i++)
    xRead += analogRead(A0);
    yRead += analogRead(A1);
    zRead += analogRead(A2);

  xRead = xRead/ave;
  yRead = yRead/ave;
  zRead = zRead/ave;

  // convert to angles
  xAng = map(xRead, xMinVal, xMaxVal, -90, 90);
  yAng = map(yRead, yMinVal, yMaxVal, -90, 90);
  zAng = map(zRead, zMinVal, zMaxVal, -90, 90);
  x = 57.2957795 * (atan2(-yAng, -zAng) + 3.14159265359);
  y = 57.2957795 * (atan2(-xAng, -zAng) + 3.14159265359);
  z = 57.2957795 * (atan2(-yAng, -xAng) + 3.14159265359);

  char xTempString[10];  //  Hold The Convert Data
  // convert position in string to display it
  dtostrf(x,3,2,xTempString); // dtostrf( [doubleVar] , [sizeBeforePoint] , [sizeAfterPoint] , [WhereToStoreIt] )
  String xString = String(xTempString);  // cast it to string from char 
  // wrtie value that will be read on the mobile device
  currentBackPos = x;

  //if the button is pressed set the value of base position to the current back position 
  // this sets a "normal" state that the code will then measure a difference from. 
  if (buttonState == HIGH) {  
    myiShield.writeConsole("button pressed"); 
    refPos = currentBackPos; 
    char bkpTempString[10];  //  Hold The Convert Data
    dtostrf(currentBackPos,3,2,bkpTempString); // dtostrf( [doubleVar] , [sizeBeforePoint] , [sizeAfterPoint] , [WhereToStoreIt] )
    String bkpString = String(bkpTempString);  // cast it to string from char 
    myiShield.writeConsole("currentBackPos :");
    char bpTempString[10];  //  Hold The Convert Data
    dtostrf(refPos,3,2,bpTempString); // dtostrf( [doubleVar] , [sizeBeforePoint] , [sizeAfterPoint] , [WhereToStoreIt] )
    String bpString = String(bpTempString);  // cast it to string from char 
    myiShield.writeConsole("refPos :");
  //if backPos is in a bad postion
  if(currentBackPos > refPos + 20){
    digitalWrite(LED1, HIGH);
    digitalWrite(LED2, LOW);
    digitalWrite(LED3, LOW);
  else {
    if(currentBackPos > refPos + 10){
      digitalWrite(LED1, LOW);
      digitalWrite(LED2, LOW);
      digitalWrite(LED3, HIGH);
      digitalWrite(LED2, HIGH);
      digitalWrite(LED1, LOW);
      digitalWrite(LED3, LOW);

Mobile Application code
SImple Cordova application to receive and display data sent by the posture detector


Arduino schema
Connect the accelerometer on the 3.3V for the power
Posturedetector withoutbuzz sketch bb dbr8mq2w1h


Similar projects you might like

Smart Door with Face Unlock

Project tutorial by Divins Mathew

  • 41 respects

Small COVID medi-kit (SPO2 + Heart Rate + ECG) with MATLAB

Project tutorial by Ninety99

  • 17 respects

Sound Sensor Activated LEDs with LCD for Sound Level Data!

Project tutorial by HeathenHacks

  • 29 respects

Android App-Based Home Automation System Using IOT

Project tutorial by Team Autoshack

  • 184 respects

Bluetooth control led with lcd led status display real time.

Project tutorial by Youssef Sabaa

  • 62 respects

Bluetooth Home Automation

Project tutorial by Team TATCO

  • 21 respects
Add projectSign up / Login