Maker.io main logo

DIY Posture Sensor

2016-04-13 | By Maker.io Staff

License: GNU Lesser General Public License Arduino

If you ever sit in a classroom or worked in an office environment then you will know all about the importance of good posture, but maintaining your back and shoulders can be a tough habit to form. With so many expensive devices out there on the market, I decided to create my own minder using a Adafruit Feather board and some sensors, which would deliver some haptic feedback in the form of a vibrating motor.

Posture Sensor

The posture device uses a 3-Axis accelerometer sensor to detect the angle in which it is positioned. When the sensor reaches past a certain angle i.e. poor posture, then the vibration motor will buzz twice to indicate that the user needs to sit up straight.

Back of the Sensor

I decided to use the Adafruit Feather32u4 board, mainly because it allowed me to use a rechargeable battery, which I could also charge up through the micro USB port on the board. The feather board also featured a nice prototyping area for the 3-axis sensor and the vibration motor. Combined with the small battery which I salvaged from an old micro drone, it all fits nice and snug within the pin headers.

Parts used:

  • Adafruit Feather32u4
  • Adafruit 3-Axis Accelerometer
  • 3V Vibration motor
  • Battery pack

The assembly was pretty straight forward, firstly I soldered the 3-Axis sensor to the reverse side of the Feather board, which made the overall project quite snug and compact. The sensor requires 4 pins to be connected to the Feather board:

  • VIN to 3V
  • GND to GND
  • SDA to SDA
  • SCL to SCL

As you can see, pretty straight forward, it was also easy to solder the power to the solder ads in the prototyping area rather than direct to the Feather pins.

The vibration motor was connected to pin 5 on the feather board and seated nicely on top using the sticky pad it comes with. Normally using a vibration motor I would use some sort of haptic controller for more feedback features but in this case I wanted to keep things simple without compromising on space.

The code was adapted from the Adafruit sensor library, so before you upload the code to your board you should download the following Adafruit libraries:

In the following sketch we use the Y axis to determine rotation. When the value reaches below 3500 (4000 Max) in both directions it will turn the vibration motor on for a short period and then wait a few seconds whilst you adjust your posture.

Copy Code
#include <Wire.h>
#include <Adafruit_MMA8451.h>
#include <Adafruit_Sensor.h>

int buzz = 5;

Adafruit_MMA8451 mma = Adafruit_MMA8451();

void setup(void) {
Serial.begin(9600);
pinMode(buzz, OUTPUT);


if (! mma.begin()) {
Serial.println("Couldnt start");
while (1);
}
Serial.println("MMA8451 found!");

mma.setRange(MMA8451_RANGE_2_G);

}

void loop() {

mma.read();
Serial.println("\tY:\t"); Serial.println(mma.y);

if (mma.y < 3500){
digitalWrite(buzz, HIGH);
delay(500);
digitalWrite(buzz, LOW);
delay(250);
digitalWrite(buzz, HIGH);
delay(500);
digitalWrite(buzz, LOW);
delay(1000);
}
sensors_event_t event;
mma.getEvent(&event);

delay(2000);

}

Taking it further

There are a couple of features which I think would add a better experience such as a potentiometer to fine tune the sensitivity of the sensor. This would avoid the need for re-programming the sensor with new updated values every time.

Secondly I would adapt the Adafruit example to determine the orientation of the device, I guess not every user will use the same orientation depending on where it will be affixed. This can be done using a simple switch case, you can then use a different axis for the trigger point.

制造商零件编号 2771
FEATHER 32U4 BASIC PROTO ATMEGA
Adafruit Industries LLC
¥162.39
Details
制造商零件编号 2019
MMA8451 3AXIS ACCEL BREAKOUT BRD
Adafruit Industries LLC
¥64.71
Details
制造商零件编号 316040004
VIBRATION ERM MTR 10000 RPM 3V
Seeed Technology Co., Ltd
¥10.11
Details
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum