How to Build a Sitting Time Tracker
by Alex_chu in Circuits > Sensors
1582 Views, 2 Favorites, 0 Comments
How to Build a Sitting Time Tracker
This project will be utilising the Zio Qwiic Ultrasonic Distance Sensor to detect and track a person. The device will be strategically placed on top of a screen/monitor facing the person sitting down, in front of his/her computer.
The project will track how long they have been sitting down for in hours/mins. After the maximum ‘sitting’ time is reached, it will alert them to stand up and walk around.
Schematic
Setup
You will need the following modules to build this project:
Daisy Chain All the Modules Together
Configuration & Code
Download and install the following libraries to your Arduino IDE:
Upload the Full Project Code to your board. Plug your Uno to a computer. Download and Flash the code to your Uno using the Arduino IDE.
Alternatively, you can download the code from our Github page.
Code Explanation
From the start, the sensor will detect a human’s presence sitting within the distance of 75cm. At this time, all counters will be initialized to zero.
uint16_t time_sit1 = 0;
uint16_t time_sit2 = 0;
uint16_t time_leave1 = 0;
uint16_t time_leave2 = 0;
uint16_t lim = 75; //Distance range from sensor to the seat
uint16_t maxsit_time = 7200000; //Set the maximum sitting time in ms
Inside the loop function, the sensor will first detect for human presence. If no object is within the detection range, a ‘leave counter’ will start to track the time when nobody is present.
if(distance*0.1 < lim){// detects if a person is within the detection range
distance_H = Wire.read();
distance_L = Wire.read();
distance = (uint16_t)distance_H<<8;
distance = distance|distance_L;
sit();
time_leave1++; //tracks the time nobody is around
calculatetime();
If he/she has been sitting for more than 2 hours, the code will display a message for the person to take a break.
if(time_sit2 > maxsit_time){
maxsit();
time_leave1 = millis()/1000;
time_leave1++;
calculatetime();
If the person decides to take a break, the code will check again if there is human presence. If no presence is detected, the sitting counter will reset to zero and the leave counter will start. The sensor will track the time that the person has left their workspace to take a break.
else if (distance*0.1 > lim){//detects if a person is out of range
calculatetime();
Serial.print("Time sit : ");
Serial.print(time_sit2/1000);
Serial.println(" sec");
time_sit1 = millis()/1000;
Serial.println("Nobody");
time_sit1++;
delay(1000);
Demo
Place the Zio Qwiic Ultrasonic Distance Sensor on top of your computer monitor.
Note: It is better to put it above the computer to avoid any objects being detected by the sensor which could distort the results.
You can view the sitting time results on the OLED display attached to the device.
How It Works
The Ultrasonic Distance sensor will track and detect a sitting person if he/she is sitting within the range of 75cm (the distance from the monitor to the seat) from the sensor.
It will track the number of hours that the person sat and the distance from the sensor.
If he/she is not within the specified 75cm range, the sensor will assume that the person left his/her sitting area. The OLED screen will display the time a person left after sitting down.
If the sensor has tracked and detected that a person has been sitting for more than 2 hours straight, the screen will display a message to let him/her take a break.