> 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/workshop/smart-home.md).

# Smart Home

With built-in Wi-Fi and User Cloud Message, HaloCode can play its role in your smart home. Let's build a house. On the one hand, HaloCode can be the light source of the room; on the other, by connecting to a servo, HaloCode can control garage door.

![](/files/-LpgANNKoN9OO3hr9Td0)

**Set stage background**

1\. Delete default sprite Panda

![](/files/-LpgANNLqADZ_rKT9dXx)

2\. Under "Background", click "Costumes", and then add "Bedroom2"

![](/files/-LpgANNMvmbm7P2e9PA7)

**Add a button**

3\. Click "+" under "Sprites", and then add "Empty button1".

![](/files/-LpgANNN16IBq7l7i_mW)

4\. Choose "Empty button1". Then click "Costume". Add text "Bright" to the button.

![](/files/-LpgANNODkWUiafk7O8Z)

**Program the button**

5\. Under "Sprites", click "+" in the Blocks area to add User Cloud Message blocks.

![](/files/-LpgANNPxK3LK-wFABrh)

6\. Add an Events block when this sprite clicked and a User Cloud Message block send user cloud message (). Name the message "bright".

![](/files/-LpgANNQxc51HN0ar7fu)

7\. Add some special effects to the button when it is clicked. Drag two Looks block change size by (10) and change (color) effect by (5). Then add a Control block wait () seconds, and set the value to 0.1.

![](/files/-LpgANNRBGOCDjXW95ve)

8\. Add another two Looks blocks set size to (100)% and set (color) effect to (0).

![](/files/-LpgANNSfjcv3LKHuRpH)

**Add buttons: "Soft", "Night", and "Colorful"**

9\. Duplicate "Empty button1" to make create another button for soft light, and edit the program accordingly. Likewise, we can create two more buttons for "night" and "colorful".

![](/files/-LpgANNTVHZ0newj5fU0)

![](/files/-LpgANNUuYqG98gl8Dah)

**Add garage button**

10\. Under "Sprites", click "+" to add "Blue button45". Add text "garage lock" to the button.

![](/files/-LpgANNVHgnBvXHWwI6v)

11\. Choose "Blue button45", and then click "Costumes". Duplicate the costume. Edit the costume. Name the two costumes "lock", and "unlock"

![](/files/-LpgANNWXx9yoIGb0LIu)

**Program garage button**

12\. Choose Variables blocks, and click "Make a Variable". Name the variable "lock state".

![](/files/-LpgANNXdeJq10zjgX8p)

13\. Add an Events block when this sprite clicked, a control block if () then () else (), an Operators block () = (), and a Variables block lock state. Input "unlocked" to the second slot of the Operators block

![](/files/-LpgANNYJorOn38Oih7G)

14\. When the door is open, we want to close the door. Add a User Cloud Message block send user cloud message (), and name the message "lock garage". Add a Variables block set (lock state) to (locked) and a Looks block switch to costume(lock).

![](/files/-LpgANNZPq-BzA70f1TF)

15\. Duplicate the script, to open garage lock. Change the variables accordingly.

![](/files/-LpgANN_mgZSct-bFOlT)

16\. Add some special effects to the button when it is clicked. Add the following blocks: change size by (10), change (color) effect by (5), set size to (100)%, wait () seconds, and set (color) effect to (0).

![](/files/-LpgANNak1SsOafE1Cz4)

**Connect to the internet**

17\. To use User Cloud Message, we have to connect HaloCode to the internet. Add two blocks: when HaloCode starts up, and connect to Wi-Fi () password ().

![](/files/-LpgANNbIHpRCBw7vClU)

18\. Add some special effects to HaloCode when successfully connected to the internet

![](/files/-LpgANNcHV0CIY14C1wU)

**Add light effect**

19\. Add a Wi-Fi block when receiving user cloud message (), and input "bright". Add a Lighting block all LEDs light up (), brightness ()%, to light up all LEDs white.

![](/files/-LpgANNd-pISNZSA5KiI)

20\. Likewise, for User Cloud Message "soft", all LEDs will light up 40% white.

![](/files/-LpgANNe-B6u6UxXm58W)

21\. For User Cloud Message "night", fewer LEDs will light up. Add a Wi-Fi block when receiving user cloud message () and a Lighting block show ().

![](/files/-LpgANNfCkEYwSSPwdBP)

22\. For User Cloud Message "colorful". the LED right will light up with multiple colors. We'll need these blocks: show (), wait () seconds, light off all LEDs, and repeat ().

![](/files/-LpgANNgFKh0Gj_s_rzM)

**Connect second HaloCode to the servo**

23\. The red line of the servo means the positive pole, and is connected to the red line of the alligator clip, which is connected to the 3.3v pin of HaloCode. The black line of the servo means the negative pole, and is connected to the blue line of the alligator clip, which is connected to the GND pin of HaloCode. The white line of the servo is the communication line, and is connected to the yellow line of the alligator clip, which can be connected to any touchpad of HaloCode. We'll use touchpad0 in this example.

![](/files/-LpgANNhdG6o-ZYqzJBT)

![](/files/-LpgANNifu6RfxIjG5CW)

![](/files/-LpgANNjpNzgQPsglpzX)

**Program the servo**

24\. Add a Wi-Fi block when receiving user cloud message (), and input message "lock garage". Add a Pins block servo pin () rotates to () (actual rotating degree depends on the angle of the servo), to close the door.

![](/files/-LpgANNkM4oa6w4yD2XH)

24\. Add another Wi-Fi block when receiving user cloud message (), and input message "unlock grage". Add a Pins block servo pin () rotates to () (actual rotating degree depends on the angle of the servo), to open the door.

![](/files/-LpgANNlBRzkUMf-dmNQ)

**Programming result**

26\. Upload program.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://learn.pakronics.com.au/halocode-1/code-with-mu-a-simple-python-editor/examples/workshop/smart-home.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
