Monday, February 17, 2014

A very simple Posture Sensor

If you are reading this you are most likely sitting in front of a computer of some sort, maybe even slouching into the chair. Often we don’t care about our posture which can result in back pain and worse. If someone tells you to sit upright this is easy to do, but it won’t hold on for more than a few minutes. Now wouldn’t it be great to have a device that can remind you to improve your posture?


There already are some very intelligent approaches on this topic. One of the best known should be lumoback or lumolift as the new version is called. As far as I understand, they use an accelerometer for a sensor to measure the angle at a certain point of the spine. While these sensors should be relatively accurate, they also need tiny electronics and clever power management to be wearable. Something that is really difficult to achieve with simple electronics and tools.

What is left is making a chair-mounted device. One solution would be using a few pressure sensors on the chair that measure the weight distribution. The downside is that a lot of those sensors are needed for a reliable result. And pressure sensors are not too cheap.

Something that changes significantly between good and poor posture is the position of the head. So what I finally came up with is a device that simply measures the distance to the head.


The simplest distance sensors are ultrasonic or infrared sensors. I went with a SR-HC04 because it is cheap and sufficiently precise. There are no special requirements to the controller so I am using an Attiny85. A small piezo speaker provides acoustic feedback to the user. The only thing left is the power supply for which 5V are needed because of the ultrasonic sensor. You could easily use an USB port but I did not want to rely on a computer, 3 button cells deliver around 4,5V and should work for a few days.

Soldering everything together is very easy, the circuit does not need a single resistor although the piezo speaker could use one when longer used. The components are soldered onto a piece of prototyping PCB and some pin headers to connect to the sensor and power supply.

The whole device is not mounted directly onto the chair, but is connected to a piece of fabric that hides the battery and can be laid over the chair’s rest.


The attiny85 is programmed using Arduino and luckily there is no difference in using the hc-sr04.  There are basically 3 modes: The configuration-mode waits until the user holds his head still and saves the distance of a comfortable position. After this the watch-mode starts, what compares the current distance to the saved distance. If your head is too far away it will sound an alarm. If you get your head back the alarm will stop immediately. If not the device beeps a few times and then mutes. After some time it enters standby-mode. This is meant for leaving the device alone, the sensor reads the distance only every few seconds during this to save energy. If you get back to your chair the configuration-mode starts again.

Programming this was not too difficult but there still are some strange bugs I cannot get rid of.


Apart from the minor software issues, the project was successful. This sensor can easily be built for less than 10$. 
But keep in mind: This is simply meant as a reminder to sit upright, not as a medical application.


  1. Nice project,
    I know you said pressure sensors are expensive, but using a pressure sensor the turn the device on/off would be pretty handy and save battery.
    Also I work in an office with multiple colleges, we would be drawn crazy from the buzzer if everyone had one. If I build one, I would replace the buzzer for a vibrating motor.

  2. I was thinking about using a vibrating motor, too, but since the device is not directly attached to the body it would be difficult to notice. But you are right, the piezo speaker is way too loud, with full 5V it sounds like a fire alarm, I had to turn down the volume to make it usable.

  3. I am a physical therapist, I will pay somebody labor and materials to build a few of these to sell in my clinic. Contact

    1. Hello, My name is Michael, if you are still interested, I could easily build a few of these devices.
      Please email:

  4. This looks very interesting... will research to know more. Can anyone suggest good source/stores for the parts? Thanks!

  5. Did you post the source code for this somewhere?

    1. I do not want to publish the source code right now. You would need to make a lot of adjustments anyway depending on the sensor and controller you are using.

  6. Good idea, I am looking for a chair sensor that can output the sensor data(pressure data, seat or not etc) by Bluetooth or other(WIFI). Could you give me some such information please?

  7. can you please upload the code? i need to know attiny's function to do sounds at random intervals :(

    1. that's my code, it works on arduino but not on attiny, i think that's much similiar to your code, can you help me to convert in attiny language?

      long randNumber;
      long randNumber1;
      long randFreq;
      #define trigPin 11
      #define echoPin 12

      void setup ()
      pinMode(trigPin, OUTPUT);
      pinMode(echoPin, INPUT);
      void loop ()
      randFreq = random(250, 5000);
      randNumber = random(50, 100);
      long duration, distance;
      digitalWrite(trigPin, LOW); // Added this line
      delayMicroseconds(2); // Added this line
      digitalWrite(trigPin, HIGH);
      delayMicroseconds(10); // Added this line
      digitalWrite(trigPin, LOW);
      duration = pulseIn(echoPin, HIGH);
      distance = (duration/2) / 29.1;
      if (distance < 10) {
      tone(13, randFreq);
      randNumber1 = random(10, 1000);
      else {

    2. i have a speaker, hcsr04 and arduino connected, if distance < 10 speaker makes random sounds in frequency and delay

    3. You will have to replace the tone library which does not work on the Attiny85.
      Have a look at this:
      or this:
      Anyway you can test if everything else works by just turning the speaker on and off instead of playing a tone.

    4. thank you! i used tinytone and worked, but the volume is incredibly low, i can't hear nothing :( i think that the hc-sr uses much of the arduino current..

    5. ok, solved .. i switched pin and now it works :) i think that attiny give different priority to some pins..