This project is a simple voice-controlled interactive prototype built with Arduino Nano 33 and p5.js.
I connected a fan and an LED light to the Nano 33, and used speech recognition(the browser’s built-in SpeechRecognition API (Web Speech API)) in p5.js to control them through spoken words.
When I say “hot”, the fan turns on.
When I say “stop”, the fan turns off.
When I say “cold”, the LED turns on as a form of visual warmth.
When I say “stop”, the LED turns off.
const int MOTOR_PIN = 5;
const int LED_PIN = 6;
void setup() {
digitalWrite(MOTOR_PIN, LOW);
digitalWrite(LED_PIN, LOW);
pinMode(MOTOR_PIN, OUTPUT);
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
char c = Serial.read();
if (c == 'M') {
digitalWrite(MOTOR_PIN, HIGH);
digitalWrite(LED_PIN, LOW);
}
else if (c == 'L') {
digitalWrite(MOTOR_PIN, LOW);
digitalWrite(LED_PIN, HIGH);
}
else if (c == 'S') {
digitalWrite(MOTOR_PIN, LOW);
digitalWrite(LED_PIN, LOW);
}
}
}