edge lab LIVE! starts Tuesday in Munich. Grab a workshop seat and take home the board you build on. Code FRIEND-HACKSTER saves 20%. () Learn more!
varun komal
Published © MIT

Gesture-Controlled Smart Glove with Li-Fi Communication

A smart glove that helps speech-impaired people communicate through hand gestures, using Arduino and flex sensors to transmit messages

IntermediateFull instructions provided3 days22
Gesture-Controlled Smart Glove with Li-Fi Communication

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Arduino Nano R3
Arduino Nano R3
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

smart gloves gloves side

smart gloves lcd side

Code

smart gloves lcd side code

C/C++
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>

// =====================================================
// LCD - PARALLEL 16x2
// =====================================================

// RS, EN, D4, D5, D6, D7
LiquidCrystal lcd(7, 9, 10, 11, 12, 13);


// =====================================================
// LDR
// =====================================================

const int LDR_PIN = A0;

// IMPORTANT:
// Nee circuit lo light padinappudu value decrease avtundi
// Light detected = LDR value BELOW threshold

const int THRESHOLD = 600;


// =====================================================
// LED
// =====================================================

// LCD D13 use chestundi
// So LED ki D3 use chestunnam

const int LED_PIN = 3;


// =====================================================
// TIMING
// =====================================================

// Last detection tarvata message confirm cheyyadaniki
const unsigned long CONFIRM_TIME = 1000;

// Maximum detection window
const unsigned long WINDOW_TIME = 10000;


// =====================================================
// DFPLAYER
// =====================================================

// Arduino D5 = DFPlayer RX
// Arduino D6 = DFPlayer TX

SoftwareSerial mp3Serial(5, 6);

DFRobotDFPlayerMini player;

bool dfPlayerReady = false;


// =====================================================
// DFPLAYER BUSY
// =====================================================

// BUSY LOW  = Playing
// BUSY HIGH = Stopped

const int DF_BUSY_PIN = 4;


// =====================================================
// DETECTION VARIABLES
// =====================================================

int lastState = LOW;

int detectCount = 0;

unsigned long startTime = 0;

unsigned long lastDetectionTime = 0;


// =====================================================
// MP3 VARIABLES
// =====================================================

bool mp3Playing = false;

unsigned long mp3StartTime = 0;

const unsigned long MP3_TIMEOUT = 30000;


// =====================================================
// POWER ON SCREEN
// =====================================================

void showPowerOn() {

  lcd.clear();

  lcd.setCursor(0, 0);
  lcd.print("POWERED BY");

  lcd.setCursor(0, 1);
  lcd.print("voltageaxis");

  delay(2500);

  lcd.clear();
}


// =====================================================
// DATA DETECTING SCREEN
// =====================================================

void showDetecting() {

  lcd.clear();

  lcd.setCursor(0, 0);
  lcd.print("DATA DETECTING");
}


// =====================================================
// START MP3
// =====================================================

void startMP3(int number) {

  if (!dfPlayerReady) {

    Serial.println("DFPLAYER NOT READY");

    return;
  }


  Serial.print("Playing: 000");
  Serial.print(number);
  Serial.println(".mp3");


  player.stop();

  delay(100);


  player.play(number);


  mp3Playing = true;

  mp3StartTime = millis();
}


// =====================================================
// CHECK MP3
// =====================================================

void checkMP3() {

  if (!mp3Playing) {
    return;
  }


  // MP3 finished
  if (digitalRead(DF_BUSY_PIN) == HIGH) {

    mp3Playing = false;

    Serial.println("MP3 COMPLETE");

    return;
  }


  // Safety timeout
  if (millis() - mp3StartTime >= MP3_TIMEOUT) {

    mp3Playing = false;

    Serial.println("MP3 TIMEOUT");
  }
}


// =====================================================
// SHOW MESSAGE
// =====================================================

void showMessage(int count) {

  lcd.clear();


  // =================================================
  // 2 DETECTIONS
  // =================================================

  if (count == 2) {

    lcd.setCursor(0, 0);

    lcd.print("OK");

    Serial.println("MESSAGE: OK");

    startMP3(1);
  }


  // =================================================
  // 3 DETECTIONS
  // =================================================

  else if (count == 3) {

    lcd.setCursor(0, 0);

    lcd.print("WAIT");

    Serial.println("MESSAGE: WAIT");

    startMP3(2);
  }


  // =================================================
  // 4 DETECTIONS
  // =================================================

  else if (count == 4) {

    lcd.setCursor(0, 0);

    lcd.print("DONT DISTURB");

    Serial.println("MESSAGE: DONT DISTURB");

    startMP3(3);
  }


  // =================================================
  // 5 DETECTIONS
  // =================================================

  else if (count == 5) {

    lcd.setCursor(0, 0);

    lcd.print("HELP ME");

    Serial.println("MESSAGE: HELP ME");

    startMP3(4);
  }


  // =================================================
  // 6 DETECTIONS
  // =================================================

  else if (count == 6) {

    lcd.setCursor(0, 0);

    lcd.print("NEED TO USE");

    lcd.setCursor(0, 1);

    lcd.print("TOILET");

    Serial.println("MESSAGE: NEED TO USE TOILET");

    startMP3(5);
  }
}


// =====================================================
// RESET DETECTION
// =====================================================

void resetDetection() {

  detectCount = 0;

  startTime = 0;

  lastDetectionTime = 0;


  // Read current LDR
  int ldrValue = analogRead(LDR_PIN);


  // Light ON = LOW VALUE
  if (ldrValue < THRESHOLD) {

    lastState = HIGH;

    digitalWrite(LED_PIN, HIGH);
  }

  else {

    lastState = LOW;

    digitalWrite(LED_PIN, LOW);
  }


  lcd.clear();


  Serial.println("--------------------------------");

  Serial.println("READY FOR NEXT GESTURE");

  Serial.println("--------------------------------");
}


// =====================================================
// SETUP
// =====================================================

void setup() {

  // =================================================
  // SERIAL
  // =================================================

  Serial.begin(9600);


  // =================================================
  // LCD
  // =================================================

  lcd.begin(16, 2);

  lcd.clear();


  // =================================================
  // LDR
  // =================================================

  pinMode(LDR_PIN, INPUT);


  // =================================================
  // LED
  // =================================================

  pinMode(LED_PIN, OUTPUT);

  digitalWrite(LED_PIN, LOW);


  // =================================================
  // DFPLAYER BUSY
  // =================================================

  pinMode(DF_BUSY_PIN, INPUT);


  // =================================================
  // POWER ON
  // =================================================

  showPowerOn();


  // =================================================
  // DFPLAYER
  // =================================================

  mp3Serial.begin(9600);

  delay(1000);


  Serial.println("Starting DFPlayer...");


  if (player.begin(mp3Serial)) {

    dfPlayerReady = true;

    Serial.println("DFPLAYER READY");


    player.volume(30);

    delay(300);


    player.stop();

    delay(300);
  }

  else {

    dfPlayerReady = false;

    Serial.println("DFPLAYER NOT FOUND");
  }


  // =================================================
  // INITIAL LDR STATE
  // =================================================

  int ldrValue = analogRead(LDR_PIN);


  if (ldrValue < THRESHOLD) {

    lastState = HIGH;

    digitalWrite(LED_PIN, HIGH);
  }

  else {

    lastState = LOW;

    digitalWrite(LED_PIN, LOW);
  }


  // =================================================
  // INITIAL VALUES
  // =================================================

  detectCount = 0;

  startTime = 0;

  lastDetectionTime = 0;


  // =================================================
  // START SYSTEM
  // =================================================

  lcd.clear();


  Serial.println();

  Serial.println("==============================");

  Serial.println("SYSTEM READY");

  Serial.println("==============================");
}


// =====================================================
// LOOP
// =====================================================

void loop() {

  // =================================================
  // READ LDR
  // =================================================

  int ldrValue = analogRead(LDR_PIN);


  // =================================================
  // SERIAL MONITOR
  // =================================================

  Serial.print("LDR = ");

  Serial.print(ldrValue);


  // =================================================
  // DETERMINE CURRENT STATE
  // =================================================

  int currentState;


  // =================================================
  // LIGHT DETECTED
  // =================================================

  if (ldrValue < THRESHOLD) {

    currentState = HIGH;

    digitalWrite(LED_PIN, HIGH);

    Serial.println(" | LIGHT DETECTED");
  }


  // =================================================
  // NO LIGHT
  // =================================================

  else {

    currentState = LOW;

    digitalWrite(LED_PIN, LOW);

    Serial.println(" | NO LIGHT");
  }


  // =================================================
  // DETECTION
  // =================================================
  //
  // IMPORTANT:
  //
  // LOW  = NO LIGHT
  // HIGH = LIGHT
  //
  // So only LOW -> HIGH counts.
  //
  // LIGHT ON continuously:
  // Only ONE detection.
  //
  // LIGHT OFF -> LIGHT ON:
  // Another detection.
  //
  // =================================================

  if (currentState == HIGH &&
      lastState == LOW) {


    detectCount++;


    lastDetectionTime = millis();


    Serial.println();

    Serial.print(">>> DETECTION = ");

    Serial.println(detectCount);


    // =================================================
    // FIRST DETECTION
    // =================================================

    if (detectCount == 1) {

      startTime = millis();


      showDetecting();


      Serial.println(">>> DATA DETECTING...");

      Serial.println();
    }


    // =================================================
    // SIXTH DETECTION
    // =================================================

    if (detectCount == 6) {

      Serial.println();

      Serial.println(">>> 6 DETECTIONS CONFIRMED");


      showMessage(6);


      // Keep system waiting for light OFF
      // before next gesture

      detectCount = 0;

      startTime = 0;

      lastDetectionTime = 0;
    }
  }


  // =================================================
  // SAVE CURRENT STATE
  // =================================================

  lastState = currentState;


  // =================================================
  // CONFIRM 2 TO 5 DETECTIONS
  // =================================================

  if (detectCount >= 2 &&
      detectCount < 6) {


    if (millis() - lastDetectionTime >= CONFIRM_TIME) {


      Serial.println();

      Serial.print("FINAL COUNT = ");

      Serial.println(detectCount);


      // Show corresponding message
      showMessage(detectCount);


      // Reset AFTER message command
      //
      // IMPORTANT:
      // Don't immediately use current HIGH as
      // another detection.

      int currentLDR = analogRead(LDR_PIN);


      if (currentLDR < THRESHOLD) {

        lastState = HIGH;
      }

      else {

        lastState = LOW;
      }


      detectCount = 0;

      startTime = 0;

      lastDetectionTime = 0;


      Serial.println("--------------------------------");

      Serial.println("READY FOR NEXT GESTURE");

      Serial.println("--------------------------------");
    }
  }


  // =================================================
  // 10 SECOND WINDOW
  // =================================================

  if (detectCount > 0 &&
      startTime > 0 &&
      millis() - startTime >= WINDOW_TIME) {


    Serial.println();

    Serial.println("10 SECOND WINDOW EXPIRED");

    Serial.println("WINDOW RESET");


    // Read current state
    int currentLDR = analogRead(LDR_PIN);


    if (currentLDR < THRESHOLD) {

      lastState = HIGH;
    }

    else {

      lastState = LOW;
    }


    detectCount = 0;

    startTime = 0;

    lastDetectionTime = 0;


    lcd.clear();


    Serial.println("--------------------------------");

    Serial.println("READY FOR NEXT GESTURE");

    Serial.println("--------------------------------");
  }


  // =================================================
  // CHECK MP3
  // =================================================

  checkMP3();


  // =================================================
  // SMALL DELAY
  // =================================================

  delay(50);
}

smart gloves gloves side code

C/C++
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>

// =====================================================
// LCD - PARALLEL 16x2
// =====================================================

// RS, EN, D4, D5, D6, D7
LiquidCrystal lcd(7, 9, 10, 11, 12, 13);


// =====================================================
// LDR
// =====================================================

const int LDR_PIN = A0;

// Light detected when LDR value is BELOW threshold
const int THRESHOLD = 600;


// =====================================================
// LED
// =====================================================

// LCD uses D13
// LED uses D3
const int LED_PIN = 3;


// =====================================================
// TIMING
// =====================================================

const unsigned long CONFIRM_TIME = 1000;
const unsigned long WINDOW_TIME = 10000;


// =====================================================
// DFPLAYER
// =====================================================

// Arduino D5 = RX
// Arduino D6 = TX
SoftwareSerial mp3Serial(5, 6);

DFRobotDFPlayerMini player;

bool dfPlayerReady = false;


// =====================================================
// DFPLAYER BUSY
// =====================================================

const int DF_BUSY_PIN = 4;


// =====================================================
// DETECTION VARIABLES
// =====================================================

int lastState = LOW;

int detectCount = 0;

unsigned long startTime = 0;

unsigned long lastDetectionTime = 0;


// =====================================================
// MP3 VARIABLES
// =====================================================

bool mp3Playing = false;

unsigned long mp3StartTime = 0;

const unsigned long MP3_TIMEOUT = 30000;


// =====================================================
// POWER ON SCREEN
// =====================================================

void showPowerOn() {

  lcd.clear();

  lcd.setCursor(0, 0);
  lcd.print("POWERED BY");

  lcd.setCursor(0, 1);
  lcd.print("voltageaxis");

  delay(3000);

  lcd.clear();
}


// =====================================================
// DATA DETECTING SCREEN
// =====================================================

void showDetecting() {

  lcd.clear();

  lcd.setCursor(0, 0);
  lcd.print("DATA DETECTING");
}


// =====================================================
// START MP3
// =====================================================

void startMP3(int number) {

  if (!dfPlayerReady) {

    Serial.println("DFPLAYER NOT READY");

    return;
  }

  Serial.print("Playing: 000");
  Serial.print(number);
  Serial.println(".mp3");


  // Stop previous track
  player.stop();

  delay(100);


  // Play selected track
  player.play(number);


  // MAXIMUM VOLUME
  player.volume(30);


  mp3Playing = true;

  mp3StartTime = millis();
}


// =====================================================
// CHECK MP3
// =====================================================

void checkMP3() {

  if (!mp3Playing) {
    return;
  }


  // MP3 finished
  if (digitalRead(DF_BUSY_PIN) == HIGH) {

    mp3Playing = false;

    Serial.println("MP3 COMPLETE");

    return;
  }


  // Safety timeout
  if (millis() - mp3StartTime >= MP3_TIMEOUT) {

    mp3Playing = false;

    Serial.println("MP3 TIMEOUT");
  }
}


// =====================================================
// SHOW MESSAGE
// =====================================================

void showMessage(int count) {

  lcd.clear();


  // =================================================
  // 2 DETECTIONS
  // =================================================

  if (count == 2) {

    lcd.setCursor(0, 0);
    lcd.print("OK");

    Serial.println("MESSAGE: OK");

    startMP3(1);
  }


  // =================================================
  // 3 DETECTIONS
  // =================================================

  else if (count == 3) {

    lcd.setCursor(0, 0);
    lcd.print("WAIT");

    Serial.println("MESSAGE: WAIT");

    startMP3(2);
  }


  // =================================================
  // 4 DETECTIONS
  // =================================================

  else if (count == 4) {

    lcd.setCursor(0, 0);
    lcd.print("DONT DISTURB");

    Serial.println("MESSAGE: DONT DISTURB");

    startMP3(3);
  }


  // =================================================
  // 5 DETECTIONS
  // =================================================

  else if (count == 5) {

    lcd.setCursor(0, 0);
    lcd.print("HELP ME");

    Serial.println("MESSAGE: HELP ME");

    startMP3(4);
  }


  // =================================================
  // 6 DETECTIONS
  // =================================================

  else if (count == 6) {

    lcd.setCursor(0, 0);
    lcd.print("NEED TO USE");

    lcd.setCursor(0, 1);
    lcd.print("TOILET");

    Serial.println("MESSAGE: NEED TO USE TOILET");

    startMP3(5);
  }
}


// =====================================================
// RESET DETECTION
// =====================================================

void resetDetection() {

  detectCount = 0;

  startTime = 0;

  lastDetectionTime = 0;


  // Read current LDR
  int ldrValue = analogRead(LDR_PIN);


  // Light = LOW VALUE
  if (ldrValue < THRESHOLD) {

    lastState = HIGH;

    digitalWrite(LED_PIN, HIGH);
  }

  else {

    lastState = LOW;

    digitalWrite(LED_PIN, LOW);
  }


  lcd.clear();


  Serial.println("--------------------------------");
  Serial.println("READY FOR NEXT GESTURE");
  Serial.println("--------------------------------");
}


// =====================================================
// SETUP
// =====================================================

void setup() {

  // =================================================
  // SERIAL
  // =================================================

  Serial.begin(9600);


  // =================================================
  // LCD
  // =================================================

  lcd.begin(16, 2);

  lcd.clear();


  // =================================================
  // LDR
  // =================================================

  pinMode(LDR_PIN, INPUT);


  // =================================================
  // LED
  // =================================================

  pinMode(LED_PIN, OUTPUT);

  digitalWrite(LED_PIN, LOW);


  // =================================================
  // DFPLAYER BUSY
  // =================================================

  pinMode(DF_BUSY_PIN, INPUT);


  // =================================================
  // POWER ON SCREEN
  // =================================================

  showPowerOn();


  // =================================================
  // DFPLAYER SERIAL
  // =================================================

  mp3Serial.begin(9600);

  delay(1000);


  Serial.println("Starting DFPlayer...");


  // =================================================
  // DFPLAYER INITIALIZATION
  // =================================================

  if (player.begin(mp3Serial)) {

    dfPlayerReady = true;

    Serial.println("DFPLAYER READY");


    // MAXIMUM VOLUME
    player.volume(30);

    delay(300);


    player.stop();

    delay(300);
  }

  else {

    dfPlayerReady = false;

    Serial.println("DFPLAYER NOT FOUND");
  }


  // =================================================
  // INITIAL LDR STATE
  // =================================================

  int ldrValue = analogRead(LDR_PIN);


  if (ldrValue < THRESHOLD) {

    lastState = HIGH;

    digitalWrite(LED_PIN, HIGH);
  }

  else {

    lastState = LOW;

    digitalWrite(LED_PIN, LOW);
  }


  // =================================================
  // INITIAL VALUES
  // =================================================

  detectCount = 0;

  startTime = 0;

  lastDetectionTime = 0;


  // =================================================
  // START SYSTEM
  // =================================================

  lcd.clear();


  Serial.println();
  Serial.println("==============================");
  Serial.println("SYSTEM READY");
  Serial.println("==============================");
}


// =====================================================
// LOOP
// =====================================================

void loop() {

  // =================================================
  // READ LDR
  // =================================================

  int ldrValue = analogRead(LDR_PIN);


  // =================================================
  // SERIAL MONITOR
  // =================================================

  Serial.print("LDR = ");
  Serial.print(ldrValue);


  // =================================================
  // DETERMINE CURRENT STATE
  // =================================================

  int currentState;


  // =================================================
  // LIGHT DETECTED
  // =================================================

  if (ldrValue < THRESHOLD) {

    currentState = HIGH;

    digitalWrite(LED_PIN, HIGH);

    Serial.println(" | LIGHT DETECTED");
  }


  // =================================================
  // NO LIGHT
  // =================================================

  else {

    currentState = LOW;

    digitalWrite(LED_PIN, LOW);

    Serial.println(" | NO LIGHT");
  }


  // =================================================
  // NEW DETECTION
  // =================================================
  //
  // NO LIGHT -> LIGHT = ONE DETECTION
  //
  // Example:
  //
  // OFF -> ON  = Detection 1
  // ON  -> OFF
  // OFF -> ON  = Detection 2
  //
  // Detection 2 = OK
  //
  // =================================================

  if (currentState == HIGH &&
      lastState == LOW) {


    detectCount++;

    lastDetectionTime = millis();


    Serial.println();
    Serial.print(">>> DETECTION = ");
    Serial.println(detectCount);


    // =================================================
    // FIRST DETECTION
    // =================================================

    if (detectCount == 1) {

      startTime = millis();

      showDetecting();

      Serial.println(">>> DATA DETECTING...");
    }


    // =================================================
    // SIXTH DETECTION
    // =================================================

    if (detectCount == 6) {

      Serial.println();
      Serial.println(">>> 6 DETECTIONS CONFIRMED");


      showMessage(6);


      // Reset count
      detectCount = 0;

      startTime = 0;

      lastDetectionTime = 0;
    }
  }


  // =================================================
  // SAVE CURRENT STATE
  // =================================================

  lastState = currentState;


  // =================================================
  // CONFIRM 2 TO 5 DETECTIONS
  // =================================================

  if (detectCount >= 2 &&
      detectCount < 6) {


    if (millis() - lastDetectionTime >= CONFIRM_TIME) {


      Serial.println();

      Serial.print("FINAL COUNT = ");
      Serial.println(detectCount);


      // Show message + MP3
      showMessage(detectCount);


      // Read current LDR
      int currentLDR = analogRead(LDR_PIN);


      // Prevent same light from being counted again
      if (currentLDR < THRESHOLD) {

        lastState = HIGH;
      }

      else {

        lastState = LOW;
      }


      // Reset count
      detectCount = 0;

      startTime = 0;

      lastDetectionTime = 0;


      Serial.println("--------------------------------");
      Serial.println("READY FOR NEXT GESTURE");
      Serial.println("--------------------------------");
    }
  }


  // =================================================
  // 10 SECOND WINDOW
  // =================================================

  if (detectCount > 0 &&
      startTime > 0 &&
      millis() - startTime >= WINDOW_TIME) {


    Serial.println();
    Serial.println("10 SECOND WINDOW EXPIRED");
    Serial.println("WINDOW RESET");


    int currentLDR = analogRead(LDR_PIN);


    if (currentLDR < THRESHOLD) {

      lastState = HIGH;
    }

    else {

      lastState = LOW;
    }


    detectCount = 0;

    startTime = 0;

    lastDetectionTime = 0;


    lcd.clear();


    Serial.println("--------------------------------");
    Serial.println("READY FOR NEXT GESTURE");
    Serial.println("--------------------------------");
  }


  // =================================================
  // CHECK MP3
  // =================================================

  checkMP3();


  // =================================================
  // SMALL DELAY
  // =================================================

  delay(50);
}

Credits

varun komal
1 project • 1 follower
Thanks to T.VARUNKOMAL.

Comments