#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Define the analog pins where the flex sensors are connected
#define FLEX_SENSOR_1_PIN 34 // Thumb
#define FLEX_SENSOR_2_PIN 35 // Index Finger
#define FLEX_SENSOR_3_PIN 32 // Middle Finger
#define FLEX_SENSOR_4_PIN 33 // Ring Finger
#define FLEX_SENSOR_5_PIN 25 // Pinky Finger
// LCD initialization
LiquidCrystal_I2C lcd(0x27, 16, 2); // Adjust address and size (0x27 for many common LCDs)
void setup() {
// Start serial communication for debugging
Serial.begin(115200);
// Initialize LCD
lcd.begin();
lcd.backlight();
// Display an initial message
lcd.setCursor(0, 0);
lcd.print("Smart Glove Ready");
delay(2000); // Wait for 2 seconds
lcd.clear();
}
void loop() {
// Read values from flex sensors (assuming 0-1023 range)
int thumbReading = analogRead(FLEX_SENSOR_1_PIN);
int indexReading = analogRead(FLEX_SENSOR_2_PIN);
int middleReading = analogRead(FLEX_SENSOR_3_PIN);
int ringReading = analogRead(FLEX_SENSOR_4_PIN);
int pinkyReading = analogRead(FLEX_SENSOR_5_PIN);
// Define thresholds for finger movements (adjust as needed)
int threshold = 500; // If the sensor reading goes above this value, we consider it a gesture
// Display corresponding messages based on finger movement
lcd.clear();
lcd.setCursor(0, 0);
if (thumbReading > threshold) {
lcd.print("Thumb: Hello");
}
else if (indexReading > threshold) {
lcd.print("Index: Need Help");
}
else if (middleReading > threshold) {
lcd.print("Middle: Water");
}
else if (ringReading > threshold) {
lcd.print("Ring: Pain");
}
else if (pinkyReading > threshold) {
lcd.print("Pinky: Yes");
}
else {
lcd.print("No Gesture");
}
delay(500); // Delay for readability and sensor stability
}