Project tutorial
Sitting Sensor

Sitting Sensor © GPL3+

A pocket worn device that alerts you after staying sedentary for too long!

  • 1,224 views
  • 0 comments
  • 5 respects

Components and supplies

Ard lilusb
Arduino LilyPad USB
×1
98y9917 40
Battery, 3.7 V
×1
Adafruit industries ada640 image 75px
Sewable Conductive Thread
×1
Non-Conductive Thread
×1
Non-Conductive Fabric
×1
Pocket Clip
Find at local Michael's or Joann Fabrics
×1
Adafruit industries ada1008 image 75px
Alligator Clips
For testing purposes.
×1

Necessary tools and machines

Sewing Needle

Apps and online services

About this project

Intro:

This project was created using the Lilypad USB Protosnap Plus as an introductory exploration into wearables and the capacities of the Lilypad board. I wanted to create something simple, but that could still have a beneficial function for a user. Because of trying to maintain simplicity, all of the parts used in this device are included in the original board, with no need to purchase other outside components.

The device is pocket worn, so the main board component goes inside the pocket, while the light sensor and LED(optional) sit on a flap on the outside of the pocket. When a user sits down, the light sensor is covered and will alert the user if they have not moved in a given period of time. The current code is set to 10 seconds, but this is just for testing purposes as it can easily be adjusted to 10-15 minutes or however long is desired. The benefits of a pocket worn device rather than incorporating the tech into one specific pocket is the versatility it allows and the fact that it can be worn on any pair of pants that has back pockets.

How To:

<{} >
  • Coding the board.
  • <{} >
  • Constructing the wearable.
  • Coding the Board

    The first step is properly coding the board before splitting it apart to make the wearable. The LED used in the code is mostly for testing purposes and gives you pretty clear feedback that the device is working properly, though it would work just fine if the lines regarding the LED are taken out or changed to a different LED.

    <{} >Important Notes: The code uses a time based check point (millis())so that the Lilypad board can multitask, rather than just relying on the delay() function. To learn more about millis() check out the Arduino reference page.<{} >Code Overview: The code itself starts by defining all of the integers. A few of the integers used can be changed for preference, including: the tone of the alarm note, the LED used, and the length of the sitPeriod time. <{} >After noting the inputs and outputs in the setup() the first chunk of code is meant to set up the Serial Monitor to read both the light sensor value and the currentTime, this helps with troubleshooting later in the process. <{} >In order for the code to work and recognize when to start counting time, a boolean was created to register if the user was sitting down. When the light sensor is reading a value of less than 80, the board understands the user to be sitting down and will appropriately change the boolean. To ensure that the sensor is working, when the light sensor value is greater than 80 the LED will be dimly lit giving clear feedback that the board is working.<{} >When the light sensor registers a value below 80, not only is the boolean sittingDown changed to true, but the current time is remembered as the SitPeriodStart to reference later in the code to know how long a user has been sitting. When a user has been sitting for longer than the assigned sit period designated in the beginning, an alarm() will sound (shown as the last function in the code). This alarm could be altered to any song or alert noise that can be created by the Lilypad buzzer.

    The if loops allow for the board to continually check if the user is sitting or not and maintain a track of how long they have been sitting for. This accounts for if a user stands up before the given sit period has gone by.

    Below is an example of the board working:

    Constructing the Wearable

    After the board has been properly coded, it's time to integrate it into a wearable. The example shown was just created with scrap fabric I had; I used denim for the pocket insert because it was stiff and sturdy providing a good base for the Lilypad board.

    The first step was to attach the main hub to the fabric using non-conductive thread. I used four small tacks to ensure it was secure on the fabric.

    After the hub was attached, I went through using conductive thread and sewed the LED, light sensor, and buzzer to the fabric connecting them to the appropriate ports and following the circuit schematics. It’s important to make sure none of the threads cross each other, otherwise the device will short circuit, make sure to plan out where each part will sit so there are no intersecting paths.

    Before closing the wearable, the battery was inserted to check if it was working and charged.

    This step is optional, but once everything was sewn, I added a back panel to enclose all of the tech and ensure the wires would intersect each other when the device was bent over the pocket.

    Here you can see the LED turning on an off as the light sensor is covered as well as how the alarm goes off when it has been covered a given period of time.

    The device can pretty simply be worn over the pocket as shown, so when choosing fabric, be sure to take into account which fabric will be visible outside of the pocket.

    <{} >

    Code

    Sitting SensorArduino
    /*
    This code is meant to send a buzzing alert if there hasn't been light for a given period of time;
    if there is light shining in the sensor, the alert will not go off.
    
    The intention is for someone who is sitting down to get alerts to move every so often.
    
    ******************************************************************************/
    const int buzzer = A3;             //assigning buzzer pin
    const int lightSensor = A2;       //assigning light sensor pin
    int NOTE = 5000;                  //creating alarm buzzer tone
    const int sitPeriod = 10000;       //defining period allowed sitting before alert
    boolean sittingDown = false;      //setting up boolean to check sitting down condition
    
    unsigned long SitPeriodStart;  //creating value for start of sitting period
    unsigned long currentTime;
    
    void setup() {
      pinMode(lightSensor, INPUT);
      pinMode(buzzer, OUTPUT);
      pinMode(A7, OUTPUT);            //LED is used to check conditions and that code is working
    
      Serial.begin(9600);
    }
    
    void loop() {
    
      int sensorValue;
      sensorValue = analogRead(lightSensor);      //defining and reading Light Sensor
    
      Serial.print("sensor value: ");             //setting up Serial Monitor to check light sensor value
      Serial.println(sensorValue);
    
      currentTime = millis();       //starting time
      Serial.println(currentTime);
    
        if (sensorValue<80 && !sittingDown)
      {
        sittingDown = true;
        SitPeriodStart = currentTime;
        digitalWrite(A7, LOW);
      }
        else if (sensorValue>=80)
      {
        sittingDown = false;
        analogWrite(A7, 1);
      }
    
        if (sittingDown && (currentTime - SitPeriodStart >= sitPeriod))
      {
        alarm();
        alarm();
        alarm();
        sittingDown = false;
      }
    }
    
    void alarm() {
        tone(buzzer, NOTE);
        delay(150);
        noTone(buzzer);
        delay(250);
        tone(buzzer, NOTE);
        delay(150);
        noTone(buzzer);
        delay(250);
    }
    

    Schematics

    Schematic
    Screen shot 2019 10 21 at 11 gwhs9cpygu

    Comments

    Similar projects you might like

    Touch Sensor and Sound Sensor Controlling AC/DC Lights

    Project showcase by Anbumachi

    • 3,247 views
    • 2 comments
    • 7 respects

    HEARTBEAT SENSOR project

    Project tutorial by SURYATEJA

    • 5,247 views
    • 0 comments
    • 0 respects

    Visualising 3D Motion of IMU sensor

    Project tutorial by Aritro Mukherjee

    • 34,730 views
    • 7 comments
    • 44 respects

    Using the MAX30100 wearable pulse sensor with Arduino

    Project tutorial by Team Protocentral

    • 31,194 views
    • 6 comments
    • 20 respects

    Arduino And MQ2 Gas Sensor

    Project showcase by Mahamudul Karim Khondaker

    • 13,151 views
    • 9 comments
    • 19 respects
    Add projectSign up / Login