> For the complete documentation index, see [llms.txt](https://learn.pakronics.com.au/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.pakronics.com.au/halocode-1/code-with-mu-a-simple-python-editor/examples/level-up/control-halocodes-leds-via-voice-command.md).

# Control HaloCode's LEDs via Voice Command

**Sign in to mBlock 5**

HaloCode needs to connect to the internet to use online speech recognition service. We need to sign in to mBlock 5 first.

![](/files/-Lpg9lTKtLdYdfWrlRjx)

**Connect to the internet**

1\. Drag an Events block when HaloCode starts up and a Wi-Fi block connect to Wi-Fi () password (). Input the Wi-Fi name and password.

![](/files/-Lpg9lTLraQlBOJmjLxd)

2\. We want to know when the Wi-Fi is successfully connected. Add a Control block wait (), a Wi-Fi block Wi-Fi is connected?, and a Lighting block show ().

![](/files/-Lpg9lTMeqTqU5V8gNnL)

**Speech recognition**

When the button is pressed, all LEDs will light up orange. The recognition process lasts for 2 seconds. When it's done, LED 1 will light up green.

3\. Add an Events blocks when button is pressed and a Lighting block all LEDs light up (). Change the color to orange. Then add a Control block wait (1) seconds and a Lighting block show ().

![](/files/-Lpg9lTNV2FcdN-sjBKh)

4\. Add a Wi-Fi block recognize (English) for (2) seconds, and a Lighting block light off all LEDs to light off all LEDs after the speech recognition is done.

![](/files/-Lpg9lTOIeOWCw0T0lLE)

**Recognize "blue"**

5\. Add a Control block if () then () else and an Operators block () contains ()?. Add Wi-Fi block speech recognition result to the first box and input "blue" to the second box. If the speech recognition result contains "blue", all LEDs will light up blue. Add a Lighting block all LEDs light up ()

![](/files/-Lpg9lTPZujMQ9e86epE)

**Recognize "red"**

6\. Likewise, we can recognize "red".

![](/files/-Lpg9lTQ1FNP1MQx0InU)

7\. Upload the program. When HaloCode connects to the internet successfully, try pressing the button and say "red" to the microphone. Then check the LEDs.
