#include <EasyVR.h>
#include <SoftwareSerial.h>
// Create software serial on pins 12 (RX), 13 (TX)
SoftwareSerial easyvrSerial(12, 13);
EasyVR easyvr(easyvrSerial);
// RGB LED pins
const byte red = 11;
const byte green = 10;
const byte blue = 9;
void setup() {
Serial.begin(9600); // Serial Monitor
easyvrSerial.begin(9600); // EasyVR Module
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
Serial.println("Initializing EasyVR...");
if (!easyvr.detect()) {
Serial.println("EasyVR not detected!");
while (1); // Halt
}
Serial.println("EasyVR detected. Ready.");
}
void loop() {
int commandIndex = -1;
// Start listening in Command Group 0
Serial.println("Listening for command...");
easyvr.recognizeCommand(0);
while (!easyvr.hasFinished()); // Wait for response
if (easyvr.getCommand() >= 0) {
commandIndex = easyvr.getCommand(); // Get command index
Serial.print("Command recognized: Index ");
Serial.println(commandIndex);
if (commandIndex == 0) {
// Turn ON all LEDs
digitalWrite(red, HIGH);
digitalWrite(green, HIGH);
digitalWrite(blue, HIGH);
Serial.println("Lights ON");
}
else if (commandIndex == 1) {
// Turn OFF all LEDs
digitalWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
Serial.println("Lights OFF");
}
else {
Serial.println("Unknown Command Index");
}
}
else if (easyvr.isTimeout()) {
Serial.println("Timeout: No command detected.");
}
else {
Serial.println("Error or unrecognized command.");
}
delay(1000);
}