Anela deLaveaga
Published © GPL3+

Connected Posture Q Sensor

This project creates the functionality of a portable meter for measuring good posture using the Arduino.

BeginnerFull instructions provided1 hour1,735
Connected Posture Q Sensor

Things used in this project

Hardware components

Breadware Inc Mega-B Development Kit
If you purchase the kit, disregard the other components as everything is included in the kit (plus extra modules not used in this tutorial)
×1
Breadware Inc Mega-B Bread™Board
×1
Breadware Inc Breadware Accelerometer
×1
Breadware Inc Breadware Button
×1
Breadware Inc Breadware LED
×1
Arduino Mega 2560
Arduino Mega 2560
×1

Software apps and online services

Breadware Inc BreadConnect
Breadware Inc Breadware IDE

Story

Read more

Code

Posture Q Code

C/C++
while(!PowerButton.is_pressed()); //wait for button press
while(PowerButton.is_pressed()); //wait for button to be released
//record posture until button is pressed again
while(!PowerButton.is_pressed()){
// create a motion variable to allow sensor to differentiate between tilting and motion
double motion =sqrt(TiltDetector.read_x()*TiltDetector.read_x()+TiltDetector.read_y()
*TiltDetector.read_y()+TiltDetector.read_z()*TiltDetector.read_z());
// read the pitch to detect bad posture
double pitch = atan2((- TiltDetector.read_x()) , sqrt(TiltDetector.read_y()
* TiltDetector.read_y() +TiltDetector.read_z() * TiltDetector.read_z())) * 57.3;
if(pitch > -50 && motion < 11 && motion > 8) {
PostureIndicator.setRGB(0,255,0);
}
Serial.println(pitch); //print the pitch to the serial monitor to see what it reads
delay(500);
PostureIndicator.off();
}
while(PowerButton.is_pressed()); // don't begin loop again until button is released

Untitled file

C/C++
This is the code to program your device to trigger the output (LED in this case) when your position exceed your calibrated values.
**Note** You might have to play around with the value in if(pitch < -50). I set the value as -50 based on trial and error. A lower number would allow you to lean further forward and backward before the PostureIndicator LED lights up. Also, if you don't put the accelerometer in the same position I did you will have to determine a value for yourself. To help determine what value to choose, the code prints the pitch values to the serial monitor.
while(!PowerButton.is_pressed()); //wait for button press
while(PowerButton.is_pressed()); //wait for button to be released
//record posture until button is pressed again
while(!PowerButton.is_pressed()){
// create a motion variable to allow sensor to differentiate between tilting and motion
double motion =sqrt(TiltDetector.read_x()*TiltDetector.read_x()+TiltDetector.read_y()
*TiltDetector.read_y()+TiltDetector.read_z()*TiltDetector.read_z());
// read the pitch to detect bad posture
double pitch = atan2((- TiltDetector.read_x()) , sqrt(TiltDetector.read_y()
* TiltDetector.read_y() +TiltDetector.read_z() * TiltDetector.read_z())) * 57.3;
if(pitch > -50 && motion < 11 && motion > 8) {
PostureIndicator.setRGB(0,255,0);
}
Serial.println(pitch); //print the pitch to the serial monitor to see what it reads
delay(500);
PostureIndicator.off();
}
while(PowerButton.is_pressed()); // don't begin loop again until button is released

Credits

Alex Byars

Posted by Anela deLaveaga

Comments

Please log in or sign up to comment.