#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <stdbool.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int flexs = A0; //flex sensor is connected with pin A0 of the arduino
const int flexs1 = A3; // flex sensor is connected with pin A2 of the arduino
const int flexs2 = A5; // flex sensor is connected with pin A5 of the arduino
int flexdata = 0;
int flexdata1 = 0;
int flexdata2 = 0;
int angle;
int angle1;
int angle2;
const int speakerPin = 9;
const int ledPin = 13;
const int dataSize=100;
int DS1[dataSize];
int DS2[dataSize];
int DS3[dataSize];
int index = 0;
void setup() {
Serial.begin(9600);
pinMode(flexs, INPUT);
pinMode(flexs1, INPUT);
pinMode(flexs2, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(speakerPin, OUTPUT);
lcd.begin(16,2);
lcd.backlight();
lcd.setCursor(0,0);
}
void RadialFlexsion() {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Hold arm straight, palm facing down");
delay(750);
lcd.print("Now,gently bend wrist left around 30 degrees");
delay(1500);
lcd.print("Now hold for 20 seconds");
if(angle1<30){
lcd.print("Remember, bend until around 30 degrees, 20 more seconds");
delay(20000);
}
delay(20000);
lcd.print("return your hand back to normal");
if(angle>30){
lcd.print("please return your hand back to normal");
}
delay(2000);
//Number 2
lcd.print("Now,gently bend wrist left around 30 degrees");
delay(1500);
lcd.print("Now hold for 20 seconds");
if(angle1<30){
lcd.print("Remember, bend until around 30 degrees, 20 more seconds");
delay(20000);
}
delay(20000);
lcd.print("return your hand back to normal");
if(angle>30){
lcd.print("please return your hand back to normal");
}
delay(2000);
//Number 3
lcd.print("Now,gently bend wrist left around 30 degrees");
delay(1500);
lcd.print("Now hold for 20 seconds");
if(angle1<30){
lcd.print("Remember, bend until around 30 degrees, 20 more seconds");
delay(20000);
}
delay(20000);
lcd.print("return your hand back to normal");
if(angle>30){
lcd.print("please return your hand back to normal");
}
delay(2000);
}
void UlnarFlexsion() {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Hold arm straight, palm facing down");
delay(750);
lcd.print("Now,gently bend wrist right around 30 degrees");
delay(1500);
lcd.print("Now hold for 20 seconds");
if(angle1<30){
lcd.print("Remember, bend until around 30 degrees, 20 more seconds");
delay(20000);
}
delay(20000);
lcd.print("return your hand back to normal");
if(angle2>30){
lcd.print("please return your hand back to normal");
}
delay(2000);
//Number 2
lcd.print("Now,gently bend wrist right around 30 degrees");
delay(1500);
lcd.print("Now hold for 20 seconds");
if(angle1<30){
lcd.print("Remember, bend until around 30 degrees, 20 more seconds");
delay(20000);
}
delay(20000);
lcd.print("return your hand back to normal");
if(angle>30){
lcd.print("please return your hand back to normal");
}
delay(2000);
//Number 3
lcd.print("Now,gently bend wrist right around 30 degrees");
delay(1500);
lcd.print("Now hold for 20 seconds");
if(angle1<30){
lcd.print("Remember, bend until around 30 degrees, 20 more seconds");
delay(20000);
}
delay(20000);
lcd.print("return your hand back to normal");
if(angle>30){
lcd.print("please return your hand back to normal");
}
delay(2000);
}
void WristFlexsion() {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Hold arm straight, palm facing down");
delay(750);
lcd.print("Now,gently bend wrist down until around 80 degrees");
delay(1500);
lcd.print("Now hold for 20 seconds");
if(angle1<80){
lcd.print("Remember, bend until around 80 degrees, 20 more seconds");
delay(20000);
}
delay(20000);
lcd.print("return your hand back to normal");
if(angle>30){
lcd.print("please return your hand back to normal");
}
delay(2000);
//Number 2
lcd.print("Now,gently bend wrist down until around 80 degrees");
delay(1500);
lcd.print("Now hold for 20 seconds");
if(angle1<80){
lcd.print("Remember, bend until around 80 degrees, 20 more seconds");
delay(20000);
}
delay(20000);
lcd.print("return your hand back to normal");
if(angle>30){
lcd.print("please return your hand back to normal");
}
//Number 3
lcd.print("Now,gently bend wrist down until around 80 degrees");
delay(1500);
lcd.print("Now hold for 20 seconds");
if(angle1<80){
lcd.print("Remember, bend until around 80 degrees, 20 more seconds");
delay(20000);
}
delay(20000);
lcd.print("return your hand back to normal");
if(angle>30){
lcd.print("please return your hand back to normal");
}
}
void WristExtension() {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Hold arm straight, palm facing down");
delay(750);
lcd.print("Now,gently bend wrist upward until around 70 degrees");
delay(1500);
lcd.print("Now hold for 20 seconds");
if(angle1<70){
lcd.print("Remember, bend until around 70 degrees, 20 more seconds");
delay(20000);
}
delay(20000);
lcd.print("return your hand back to normal");
if(angle>30){
lcd.print("please return your hand back to normal");
}
delay(2000);
//Number 2
lcd.print("Now,gently bend wrist upward until around 70 degrees");
delay(1500);
lcd.print("Now hold for 20 seconds");
if(angle1<70){
lcd.print("Remember, bend until around 70 degrees, 20 more seconds");
delay(20000);
}
delay(20000);
lcd.print("return your hand back to normal");
if(angle>30){
lcd.print("please return your hand back to normal");
}
delay(2000);
//NUmber 3
lcd.print("Now,gently bend wrist upward until around 70 degrees");
delay(1500);
lcd.print("Now hold for 20 seconds");
if(angle1<70){
lcd.print("Remember, bend until around 70 degrees, 20 more seconds");
delay(20000);
}
delay(20000);
lcd.print("return your hand back to normal");
if(angle>30){
lcd.print("please return your hand back to normal");
}
delay(2000);
}
//Prayer Test
bool allValueSimilar(int arr[], int size, float tolerance){
for (int i = 1; i < size; i++) {
if (abs(arr[i]-arr[0])>tolerance) {
return false; // Found a different element
}
}
}
bool Hold1=allValueSimilar(DS1,100,0.2);
bool Hold2=allValueSimilar(DS2,100,2.0);
bool Hold3=allValueSimilar(DS3,100,2.0);
void loop() {
flexdata = analogRead(flexs);
Serial.flush();
angle=constrain(map(flexdata, 135, 525, 60, 30),0,90);
Serial.print("flex value sensor 1;");
Serial.print(flexdata);
Serial.print(",");
Serial.print(angle);
Serial.println("");
Serial.flush();
delay(250);
if(angle>30){
digitalWrite(ledPin, HIGH);
}else{
digitalWrite(ledPin, LOW);
}
flexdata1 = analogRead(flexs1);
angle1=constrain(map(flexdata1, 135, 650, 60, 30), 0,90);
Serial.print("flex value sensor2;");
Serial.print(flexdata1);
Serial.print(",");
Serial.print(angle1);
Serial.println("");
Serial.flush();
delay(250);
if(angle1>30){
digitalWrite(ledPin, HIGH);
}else{
digitalWrite(ledPin, LOW);
}
flexdata2 = analogRead(flexs2);
Serial.flush();
angle2=constrain(map(flexdata2, 310, 550, 45, 30),0,90);
Serial.print("flex value sensor3;");
Serial.print(flexdata2);
Serial.print(",");
Serial.print(angle2);
Serial.println("");
Serial.flush();
delay(250);
if(angle2>30){
digitalWrite(ledPin, HIGH);
}else{
digitalWrite(ledPin, LOW);
}
int value=angle;
DS1[index]=value;
int value1=angle1;
DS2[index]=value1;
int value2=angle2;
DS3[index]=value2;
index++;
if (index>=dataSize){
index=0;
}
return true; // All elements are the same
if(Hold1==true || Hold2==true || Hold3==true){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Wrist Therapy");
lcd.setCursor(0, 1);
lcd.print("Starting...");
delay(3000);
RadialFlexsion();
UlnarFlexsion();
WristExtension();
WristFlexsion();
}
}