#include <Wire.h> // Include the Wire library for I2C communication
#include <LiquidCrystal_I2C.h> // Include LCD library
#include <SoftwareSerial.h> // Include SoftwareSerial library for speech recognition module
#define SPEECH_RX_PIN 2 // Speech Recognition Module RX pin (connects to Arduino TX pin)
#define SPEECH_TX_PIN 3 // Speech Recognition Module TX pin (connects to Arduino RX pin)
#define VIBRATOR_PIN 5
#define IR_SENSOR_PIN 8
SoftwareSerial mySerial(2, 3); // RX, TX pins for speech recognition module
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD I2C address to 0x27
unsigned long lastSeenTime = 0;
const unsigned long eyeContactDuration = 60000; // 1 minute in milliseconds
void setup() {
// Initialize serial communication with speech recognition module
mySerial.begin(9600);
// Initialize LCD display
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Listening...");
// Initialize IR sensor pin
pinMode(IR_SENSOR_PIN, INPUT);
// Initialize vibrator pin
pinMode(VIBRATOR_PIN, OUTPUT);
// Wait for the speech recognition module to start
delay(500);
}
void loop() {
// Check if the user is making eye contact
if (digitalRead(IR_SENSOR_PIN) == LOW) {
lastSeenTime = millis();
} else {
// If the user is not making eye contact for 1 minute, vibrate
if (millis() - lastSeenTime >= eyeContactDuration) {
digitalWrite(VIBRATOR_PIN, HIGH);
delay(1000); // Vibrate for 1 second
digitalWrite(VIBRATOR_PIN, LOW);
}
}
// Check if there is data available from the speech recognition module
if (mySerial.available() > 0) {
// Read the incoming byte
char receivedByte = mySerial.read();
// If the received byte is not noise (e.g., a spoken word)
if (receivedByte != ' ') {
// Display the received byte on the LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Spoken: ");
lcd.setCursor(0, 1);
lcd.print(receivedByte);
}
}
}