Hi there, i am trying to satisffy for each scenarios by using "if" statments. But it keeps on overlapping.
#include <SoftwareSerial.h>
SoftwareSerial MyBlue(10, 11); // RX | TX
int flag = 0;
int ForceSens1 = A0; // S1
int ForceSens2 = A1; // S2
int ForceSens4 = A2; // S4
int buzzer = 13;
int timeLimit;
const int motor= 3;
void setup()
{
MyBlue.begin(9600);
pinMode (buzzer, OUTPUT);
pinMode (ForceSens1, INPUT);
pinMode (ForceSens2, INPUT);
pinMode (ForceSens4, INPUT);
pinMode (motor, OUTPUT);
Serial.begin(115200);
Serial.println("Ready to connect\nDefualt password is 1234 or 0000");
Serial.println("How long will you sit for?");
while (!Serial.available());
pinMode(motor, OUTPUT);
timeLimit = Serial.parseInt();
}
void loop(){
int forceSensReading1 = analogRead(ForceSens1);
int forceSensReading2 = analogRead(ForceSens2);
int forceSensReading4 = analogRead(ForceSens4);
static int timer = millis();
if ((millis()- timer) > timeLimit){
digitalWrite(motor, HIGH);
delay(4000);
digitalWrite(motor, LOW);
delay(5000);
timer = millis();
}
{
if (forceSensReading1>1000&&forceSensReading2>1000&&forceSensReading4>1000)//Optimal (perfect posture) // intended neither
Serial.println("Optimal Seating");
}
{
if ( forceSensReading1>1000&&forceSensReading2>1000&&forceSensReading4<1000)//too left (FS 4 (S4) will decrease from optimal) FS 1 might increase more than optimal
buzzerOn();
Serial.println("too left");
}
{
if ( forceSensReading1>1000&&forceSensReading2<1000&&forceSensReading4>1000)//too right (FS 1 (S2) will decrease from optimal) FS 4 might increase more than optimal
buzzerOn();
Serial.println("too right");
}
//{
// if ( forceSensReading1>820&&forceSensReading2>400&&forceSensReading4>1020&&forceSensReading5>550&&forceSensReading6>550)//Edge of chair(FS 2,5,6 (S1,B1,B2) will in decrease lower than optimal)
//buzzerOn();
//Serial.println("User is seating at the edge of chair");
//}
{
if ( forceSensReading1<1000&&forceSensReading2<1000&&forceSensReading4<1000)// If all values lower than optimal, nobody seating ayy
Serial.println("User not present");
}
return;
}
void buzzerOn()
{
digitalWrite(3, HIGH);
tone (buzzer, 450);
delay(500);
noTone (buzzer);
delay (500);
}
Here is the outcome on serial monitor
