# 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.

![](https://2169521322-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fpakronics-education%2F-Lpg0r0jyU3XQdgAmqp8%2F-Lpg9lTKtLdYdfWrlRjx%2F0.gif?generation=1569477827139173\&alt=media)

**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.

![](https://2169521322-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fpakronics-education%2F-Lpg0r0jyU3XQdgAmqp8%2F-Lpg9lTLraQlBOJmjLxd%2F1.gif?generation=1569477827088230\&alt=media)

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 ().

![](https://2169521322-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fpakronics-education%2F-Lpg0r0jyU3XQdgAmqp8%2F-Lpg9lTMeqTqU5V8gNnL%2F2.gif?generation=1569477827159014\&alt=media)

**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 ().

![](https://2169521322-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fpakronics-education%2F-Lpg0r0jyU3XQdgAmqp8%2F-Lpg9lTNV2FcdN-sjBKh%2F3.gif?generation=1569477827178225\&alt=media)

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.

![](https://2169521322-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fpakronics-education%2F-Lpg0r0jyU3XQdgAmqp8%2F-Lpg9lTOIeOWCw0T0lLE%2F4.gif?generation=1569477827162013\&alt=media)

**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 ()

![](https://2169521322-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fpakronics-education%2F-Lpg0r0jyU3XQdgAmqp8%2F-Lpg9lTPZujMQ9e86epE%2F5.gif?generation=1569477827179699\&alt=media)

**Recognize "red"**

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

![](https://2169521322-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fpakronics-education%2F-Lpg0r0jyU3XQdgAmqp8%2F-Lpg9lTQ1FNP1MQx0InU%2F6.gif?generation=1569477827136502\&alt=media)

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.
