close-circle
Close
0%
0%

IoT Sit Counter

Personal Lethargy Tracker

Similar projects worth following
Personal Lethargy Tracker

Once a luxury, sitting has now become an ailment. Have you yet wondered to just how many times in a day you sit or to what percentage of your day is consumed on bended knee? Making use of a resistance sensor and a NodeMCU ESP-12E, we are able to track our daily lethargy and display it in all of it's aggregated misery. Amend as needed.

ThingSpeak

https://thingspeak.com/channels/281292

Notations

Why not the buttock or thigh? A pressure sensor on those locations are constricted by clothing leading to false impressions. The knee is a more likely readable joint allowing for more variable situations. Is it flawless? C'mon, get real man!

Battery life was the greatest limitation to this personal tracking device which ideally in this cheese ball form, would require use over multiple days to gather enough data to gain a true perspective of your sitting abuses.

  • 1 × NodeMCU ESP-12E
  • 2 × LED (Red/Green)
  • 4 × 1K Resistor
  • 1 × Momentary Push Button
  • 1 × Slippity Slide Switch

View all 8 components

  • IoT-InG

    VijeMiller06/10/2017 at 22:56 0 comments

    1. Number of Times Sat

    2. Total Minutes Sat'ed

    3. Percentage of Run Time Spent Sat'ing

  • Butt On State

    VijeMiller06/10/2017 at 04:21 0 comments

    // IoT Sit Counter
    // Version 0.1
    // VijeMiller
    
    // NodeMCU ESP-12E 1.0
    #include <ESP8266WiFi.h>
    
    // WIFI Network Access
    const char* ssid = "XXXXXX";
    const char* password = "XXXXXXX";
    WiFiServer server(80);
    
    // ThingSpeak Access
    char thingSpeakAddress[] = "api.thingspeak.com";
    String APIKey = "XXXXXXXXXXX"; // API
    const int updateThingSpeakInterval = 10 * 1000; // Interval
    long lastConnectionTime = 0;
    boolean lastConnected = false;
    WiFiClient client;
    
    // LEDs
    int activeled = 13;
    int wifiled = 12;
    
    // Sensor
    int sensor = A0;
    int ssr = 0;
    int sensorstart = 0;
    int senres = 0;
    int sensorstate = 0;
    
    // Button
    int button = 14;
    int buttstate;
    
    // Stats
    int sitdown = 0;
    int pretime = 0;
    float dattime;
    float runpert;
    
    // States
    int mainstate = 0;
    
    void setup() {
      Serial.begin(9600);
    
      pinMode(button, INPUT);
      pinMode(activeled, OUTPUT);
      pinMode(wifiled, OUTPUT);
    
      digitalWrite(activeled, LOW);
      digitalWrite(wifiled, LOW);
    
      calibrate();
    }
    
    void loop() {
    
      digitalWrite(activeled, HIGH);
    
      // WIFI Button Pressed?
      buttstate = digitalRead(button);
    
      // WIFI Yes or No?
      if (buttstate == HIGH) {
        Serial.println("Connecting");
        digitalWrite(wifiled, HIGH);
    
        // Load WiFi
        while (WiFi.status() != WL_CONNECTED) {
          WiFi.begin(ssid, password);
          delay(10000);
        }
        Serial.println("Connected");
        server.begin();
    
        // Calculate Minutes Seated
        dattime = pretime / 60.0;
        // Truncate
        dattime = (int) dattime;
    
        // Calculate Percent Seated
        runpert = millis();
        // Convert to Seconds
        runpert = runpert / 1000.0;
        // Convert to Minutes
        runpert = runpert / 60.0;
        // Convert to Percent
        runpert = dattime / runpert;
        // Truncate
        runpert = (int) runpert;
    
        // Update ThingSpeak
        String sitfinal = String(sitdown, DEC);
        String timefinal = String(dattime, DEC);
        String runfinal = String(runpert, DEC);
        updateThingSpeak("field1=" + sitfinal + "&field2=" + timefinal + "&field3=" + runfinal);
        delay(3000);
    
        // Reset Data
        sitdown = 0;
        pretime = 0;
        dattime = 0;
        runpert = 0;
    
      } else {
    
        // No WIFI
        digitalWrite(wifiled, LOW);
    
        // Read Sensor
        sensorstate = analogRead(sensor);
    
        // Sitting?
        if (sensorstate > sensorstart) {
          // Delay For 5 Seconds To Confirm Sit
          if (mainstate == 0) {
            delay(5000);
            mainstate = 1;
            goto escape;
          } else if (mainstate == 1) {
            // Add A Sit
            sitdown = sitdown + 1;
            // Run While Sitting To Track Time
            // 1 Second Per Loop
            while (sensorstate > sensorstart) {
              sensorstate = analogRead(sensor);
              pretime = pretime + 1;
              delay(1000);
            }
            // Reset State
            mainstate = 0;
          }
        }
      }
    
      delay(1000);
      digitalWrite(activeled, LOW);
      delay(1000);
    escape:
    }
    
    // Calibrate While Standing
    void calibrate() {
      for (int x = 0; x < 10; x++) {
        ssr = analogRead(sensor);
        sensorstart = sensorstart + ssr;
        delay(100);
        digitalWrite(activeled, HIGH);
      }
      // sensorstart Equals Average Standing Value
      sensorstart = sensorstart / 10;
      // Add Leniency
      sensorstart = sensorstart + 200;
      digitalWrite(activeled, LOW);
    }
    
    // ThingSpeak
    void updateThingSpeak(String tsData) {
      if (client.connect(thingSpeakAddress, 80)) {
        client.print("POST /update HTTP/1.1\n");
        client.print("Host: api.thingspeak.com\n");
        client.print("Connection: close\n");
        client.print("X-THINGSPEAKAPIKEY: " + APIKey + "\n");
        client.print("Content-Type: application/x-www-form-urlencoded\n");
        client.print("Content-Length: ");
        client.print(tsData.length());
        client.print("\n\n");
        client.print(tsData);
        lastConnectionTime = millis();
      }
    }

  • Sniffin' Glue

    VijeMiller06/05/2017 at 22:36 0 comments

  • Pack er' In

    VijeMiller06/01/2017 at 23:43 0 comments

  • Hackcycling

    VijeMiller06/01/2017 at 03:11 0 comments

View all 5 project logs

  • 1
    Step 1

View all instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates