Most of us spend hours infront of laptops sitting on ordinary chairs and we don't care how we are sitting. Are we sitting in a good way? I think the answer is no, because after all theses hours of working while we are sitting, we feel the pain, backache, neck-ache and etc. What if we transformed our ordinary chair to a chair that gives us alerts when we are sitting in a wrong way? Let's jump to the steps to see how we will do this.
Step 1: Components neededWhite LED is for detecting that the upper piezoelectric sensor (which will be mounted on chair's seat) is sending data to Arduino - Yellow LED is for detecting that the lower piezoelectric sensor (which will be mounted on chair's back) is sending data to Arduino - the upper piezoelectric sensor detects that you sat on the chair. While the lower one detects that you are leaning your back on the chair (having healthy sitting).
Step 3: Arduino codeWhat the project actually does, it detects if you are leaning your back or not, if you are not leaning your back Buzzer shield on your Mobile goes ON. When you lean back the Buzzer goes OFF and data logger shield saves how many unhealthy sittings you had and at which time in a CSV file. As you can see in the pictures, this is the same CSV but I took three screenshots for it just to show you the time saved, you can notice that they differ in seconds as I sat 6 successive unhealthy sittings. Illustrated Arduino code in the attached file.
/* Hi, My Name is Mona, I'm going to illustrate the code
and here is my e-mail: monamohamed816@gmail.com
feel free to contact if you have any
question */
#define CUSTOM_SETTINGS // to activate only the libraries that we want to use
#define INCLUDE_DATA_LOGGER_SHIELD // includes data logger shield
#define INCLUDE_BUZZER_SHIELD // includes Buzzer shield
#include <OneSheeld.h> //includes 1sheeld library
int LEDY=8; // Name of yellow LED connected to pin 8
int LEDW=9; // Name of white LED connected to pin 9
int P1=A0; // first piezoelectric sensor
int P2=A1; // second piezoelectric sensor
int counter =1; //Counter that counts how many unhealthy sittings you had
bool flag = false ; //when this flag is true this means that you are not leaning your back on the back of the chair (unhealthy sitting)
// when it is false then you are leaning your back ( healthy sitting)
String keyname = "No. of Unhealthy sittings" ; //name of column in the CSV file in which the no. of unhealthy sitting is saved
String fileName = "unHealthy sitting" ; // Name of the created file ( this file is created on your mobile in google sheets app.)
void setup()
{ OneSheeld.begin(); // starts communication
pinMode(LEDY , OUTPUT ) ; //set LEDY as output
pinMode(LEDW , OUTPUT ) ; // set LEDW as output
pinMode(P1, INPUT) ; // set first piezoelectric sensor as input
pinMode(P2 , INPUT) ; // set second piezoelectric sensor as input
Logger.stop(); // stops logging and saves last data logged
}
void loop() {
digitalWrite(LEDW,LOW); //white LED is LOW at the beginning of the program
digitalWrite(LEDY ,LOW); //yellow LED is LOW at the beginning of the program
P1= analogRead(A0) ; // saves the readings coming from pin A0 in P1
delay(5);
P2= analogRead (A1) ; // saves the readings coming from pin A1 in P2
delay (5);
if (P1<100 &&P2 <100) // 2 piezoelectronic sensors are not sending readings(nothing touched them)
{ digitalWrite( LEDY,LOW);
digitalWrite(LEDW,LOW);
Buzzer.buzzOff(); // Buzzer is off
}
else if ( P1 > 100 && P2 < 100 ) /* sensor on the seat detected that you sat down,while sensor on the back did't send reading ( which means
that you are not leaning your back) */
{ Logger.stop();
delay(500);
Logger.start ("Unhealthy sitting" ); // starts logging in a new CSV file called unhealthy sitting
digitalWrite ( LEDW ,HIGH); // when P1 is sending readings white LED is HIGH
digitalWrite (LEDY ,LOW); // When P2 is not sending readings yellow LED is LOW
Buzzer.buzzOn(); //Buzzer is ON
flag = true ;
}
if(flag)
{
Logger.add ( "No. of unhealthy sittings" , counter ); // add values in the column in the CSV file
Logger.log (); // log the row in the file
delay(500);
counter++; //add 1 to the counter value
}
else if ( P1>100 && P2 > 100) // both piezoelectric sensors are sending readings ( which means you are sitting and leaning your back)
{ digitalWrite (LEDW ,HIGH );
digitalWrite (LEDY ,HIGH );
Buzzer.buzzOff() ;
}
else if (P1<100 && P2 > 100) // first piezoelectric is not sending readings but you are leaning your back on the chair
//as second piezoelectric sensor is sending readings
{ digitalWrite (LEDY,HIGH ) ;
digitalWrite (LEDW,LOW ) ;
Buzzer.buzzOff () ;
}
else if (P1<100 && P2 <100 ) // both of them are not reading, which means you are not sitting on the chair
{
digitalWrite (LEDY,LOW ) ;
digitalWrite (LEDW,LOW ) ;
Buzzer.buzzOff () ;
}
else if (P2>100) // the sensor on the back of the chair is reading
{ digitalWrite (LEDY,HIGH ) ;
digitalWrite (LEDW,LOW ) ;
Buzzer.buzzOff () ;
}
}
Comments