Enthernet Code
Enthernet Code
DIIDevHeads IoT Integration Server
Created by Enthernet Code on 9/13/2024 in #iot-cloud
Why isn't the LED responding to voice commands in my MicroPython code?
Hey guys still based on my project on developing a home automation voice-controlled system using MicroPython and TinyML on an ESP32 microcontroller to recognize specific voice commands ("turn on" and "turn off") for controlling an LED, am currently testing the voice command recognition and validating LED control using simulated commands ("on", "off") But am getting no response from LED despite commands being printed correctly. My aim is to ensure the LED responds appropriately to the recognized voice commands, How can I resolve this? this is my code 👇
import time
import random
from machine import Pin

led_pin = Pin(2, Pin.OUT)

class LED:
def on(self):
led_pin.value(1)
print("LED is now ON.")

def off(self):
led_pin.value(0)
print("LED is now OFF.")

def process_audio():
commands = ["turn on", "turn off", "unknown command"]
return random.choice(commands)

led = LED()

while True:
command = process_audio()
print(f"Received command: {command}")

if command == "turn on":
led.on()
print("LED turned on.")
elif command == "turn off":
led.off()
print("LED turned off.")
else:
print("Command not recognized.")

time.sleep(1)
import time
import random
from machine import Pin

led_pin = Pin(2, Pin.OUT)

class LED:
def on(self):
led_pin.value(1)
print("LED is now ON.")

def off(self):
led_pin.value(0)
print("LED is now OFF.")

def process_audio():
commands = ["turn on", "turn off", "unknown command"]
return random.choice(commands)

led = LED()

while True:
command = process_audio()
print(f"Received command: {command}")

if command == "turn on":
led.on()
print("LED turned on.")
elif command == "turn off":
led.off()
print("LED turned off.")
else:
print("Command not recognized.")

time.sleep(1)
4 replies