kozlowaa
Published © GPL3+

Sitting Sensor

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

BeginnerFull instructions provided4,512
Sitting Sensor

Things used in this project

Hardware components

Arduino LilyPad USB
Arduino LilyPad USB
×1
Battery, 3.7 V
Battery, 3.7 V
×1
Sewable Conductive Thread
Sewable Conductive Thread
×1
Non-Conductive Thread
×1
Non-Conductive Fabric
×1
Pocket Clip
Find at local Michael's or Joann Fabrics
×1
Alligator Clips
Alligator Clips
For testing purposes.
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Sewing Needle

Story

Read more

Schematics

Schematic

Code

Sitting Sensor

Arduino
/*
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);
}

Credits

kozlowaa
0 projects • 1 follower

Comments