16. Adv IoT Case 13: Smart Fan Voice Control

Level: level

16.1. Goal


Make a remotely controlled fan by using a voice assistant.

16.2. Background


What is Smart Fan Voice Control?

It is a fan that is connected to the internet and can be woken up by voice command using a voice assistant. The user can define different voice commands to control fan in different speeds or modes. In this case, the user can turn on and off from the voice command.

Smart Fan Voice Control Principle

In the program, the micro:bit connects to WIFI and gets the device ID. By setting the received command (turn_on_fan and turn_off_fan), the motor will be turned on and off.
In the Smarthon IoT:bit extension on IFTTT platform, commands can be pre-set such that when a specific phrase is said to the corresponding voice assistant it will send the commands through the internet to the fan and trigger on or off actions.

pic

Know more: What is a Voice Assistant?

An intelligent virtual assistant (IVA) or intelligent personal assistant (IPA) is a software agent that can perform tasks or services for an individual based on commands or questions. The term “chatbot” is sometimes used to refer to virtual assistants generally or specifically accessed by online chat. Common giant examples are Amazon Alexa, Google Home and Apple Siri.

It is capable of voice interaction, music playback, making to-do lists, setting alarms, streaming podcasts, playing audiobooks, and providing weather, traffic, sports, and other real-time information, such as news. They can also control several smart devices using itself as a home automation system.

Nowadays, to make a home smarter, Amazon Echo Dot or Google Home or Apple home pod is a central control device which contains a voice assistant inside at home so that the user can use the voice command to control different electronics easily.

pic

16.3. Part List


pic_90

16.4. Assembly step


Step 1

In this case, build the “Big Style Model” as a home base.

pic_90

Step 2

Insert the model E1 on model A, align with the holes on model A and B3.

pic_90

Step 3

Attach the motor fan into the model F using M4 * 10mm screws and nuts. And the connecting wire could be bended to the hole next to it.

pic_90

Step 4

To build a fan stand, put model F into the model B3 and B4.

pic_90

Step 5

To build a sofa model. Put the model K3 to the two sides of model K1.

pic_90

Step 6

Put model K2 all together to the cardboard parts (K1-K3).

pic_90

Step 7

The sofa completed~

pic_90

Step 8

Place the sofa next to the fan.

pic_90

Step 9

Place the decoration board (Model H) on model B3.

pic_90

Step 10

Completed!

pic_90

Optional:

Step 1

Place the Amazon Alexa/Google Nest Mini/Apple Homepod mini at the living room. In this case, we put Amazon Alexa here.

pic_90

Step 2

Assembly Completed!

pic_90

16.5. Hardware connect


  1. Connect the motor module to P1 pic_80

16.6. Programming (MakeCode)


Step 1. Initialize OLED, IoT:bit and connect to WiFi

  • Snap Initialize OLED with width:128, height: 64 to on start

  • Snap Initialize IoT:bit TX P16 RX P8 from IoT:bit to on start

  • Snap Set Wi-Fi to ssid pwd from IoT:bit

  • Enter your Wi-Fi name and password. Here we set smarthon as SSID and 12345678 as password pic_60

Step 2. Show icon “tick” and Device ID after WiFi connection

  • Snap show icon from basic to On WiFi connected and select icon tick

  • Draw the Device ID variable from On WiFi connected to the show string block placeholder pic_50

Step 3. Receive Command

  • Inside the On WiFi Received, show the command on OLED display

  • Clear the display before each update by Clear OLED display

  • Show the WAN_Command with text explanation by show string join Command: WAN_Command pic_50

Step 4. Action with command

  • put a nested if-else statement with different conditions

  • Set the first condition as WAN_Command = turn_off_fan

  • In the if segment, turn off the fan by set Motor fan with speed 0 at P1

  • In the second if condition, use WAN_Command = turn_on_fan

  • In the second if segment, turn on the fan by set Motor fan with speed 1023 at P1

pic_80

Full Solution

MakeCode: https://makecode.microbit.org/_HRzCxhELKDMH

You could also download the program from the following website:

16.7. IoT (Alexa, Cloud Control, IFTTT)


Part 1. Setup Amazon Alexa

  1. Get the amazon alexa apps.
    pic_90

  2. Create Amazon Account (if not have amazon account) and login.
    pic_90

  3. Optional:

    Setup the alexa device and connect to the amazon account.

Part 2. Setup IFTTT

  1. Install IFTTT from Google Play Store.
    pic_100

  2. Open and login to IFTTT.

  3. Press create to create the applet.

  4. At the IF, search “alexa “ and choose “Amazon Alexa” and choose “Say a specific phrase.”
    pic_90

  5. It will detect the login account from Amazon Alexa app. Then, type the phrase here. For this example, we type “turn on the fan”.
    pic_90

  6. Click Add and type “smarthon iot” and choose Smarthon IoT as “then” service.
    pic_90

  7. In the service, choose “Control Command” and then fill in the Device ID, the command name that can read from the Micro:bit, and click “continue”, DONE!
    pic_90

Result


  1. Open the Amazon Alexa App, switch to the alexa account which connected to IFTTT.

  2. Talk to alexa with “Trigger turn on the fan” by pressing the button in the right bottom corner.
    pic_100

  3. In the first time, it will ask you whether to turn on. Press turn on and say the phase. The phase should be trigger the IFTTT and send the command to Iot:bit.
    pic_90

  4. When say “Alexa trigger turn on the fan”, the fan will be turn on; When say “ Alexa trigger turn off the fan”, the fan will be turn off.
    pic_100

  5. Optional:

    You can connect the real device Amazon echo dot to the app so that you can do the voice control with a real voice controller.
    pic_100

16.8. IoT (Google Assistant)


Part 1. Setup Google Home and Google Assistant App

  1. Install Google Home and Google Assistant app.
    pic_100

  2. Login with your google account.

  3. Open the google home app, switch to your google account.

  4. Press the settings button, choose “Works with Google”.
    pic_100

  5. Search and select IFTTT, provide authorize of Google to access the IFTTT service.
    pic_100

  6. After linked, the IFTTT will show on the list.
    pic_100

Part 2. Setup IFTTT

  1. Install IFTTT from Google Play Store. pic_100

  2. Open and login to IFTTT.

  3. Press create to create the applet.

  4. At the IF, search “google assistant “ and choose “Google assistant V2”. pic_100

  5. In “Activate scene” input the phase for trigger the command. In this case, we input “fan on”. pic_100

  6. At the THEN, search “iot” and choose “Smarthon IoT (micro:bit)”. pic_100

  7. Press the “Control Command”, input the device ID of Iot:bit and the command “turn_on_fan”. pic_100

  8. Then click continue and finish button to save the applet. pic_90

Result

  1. Open the Google Home App or Google Assistant App. Make sure the login google account is connected to IFTTT in the previous setup on Google Home App.

  2. Say “Hey google, activate (your phase)” or press the button and say “activate (your phase)”. pic_100

  3. The phase should be trigger the IFTTT and send the command to Iot:bit. pic_90

  4. The fan will be turned on. pic_100

  5. (Optional):

    You can connect the real device Google Nest Mini or Google Home to the app so that you can do the voice control with a real voice controller. pic_100

16.9. IoT (Apple’s Siri)


Part 1. Setup IFTTT

  1. Install “IFTTT” App from Apple store. pic_100

  2. Open the APP, login into IFTTT.

  3. Tap “Create” to create an applet.

  4. Click If This “Add” button. Select the “iOS Shortcuts” and click “Shortcut automation started”. pic_100

  5. Click Then That “Add” button, search “Smarthon IoT” and select the “Smarthon IoT (mirco:bit)”. pic_100

  6. Choose the “Control Command”, and fill in the Device ID, and the command name that can read from the Micro:bit, and click “Continue”, then save the applet. pic_100

Part 2. Setup IOS ShortCut on Iphone

  1. Open the Shortcuts app and tap the plus button ( + ) in the top right corner. pic_50

  2. Tap Add Action > Apps > IFTTT. pic_100

  3. Select Trigger Applet, Tap the blue arrow ( > ) next to ‘Select an Applet’, then tap Choose. pic_100

  4. Select the Applet you’d like this Shortcut to run (please note that only Applets that use the iOS Shortcuts - Shortcut automation started trigger will appear in this list). pic_70

  5. Name your Shortcut by tapping Trigger Applet at the top of the screen. This will be the custom phrase you will use to trigger your Applet. pic_100

  6. Save the shortcut. pic_90

Results

  1. Click the shortcut or Hold the button on iphone. Say “turn on the fan” or “Siri turn on the fan”. pic_100

  2. The applet will be triggered. pic_100

  3. (Optional)

    You can connect the real device Apple Homepod to the Apple Home App so that you can do the voice control with a real voice controller. pic_100

16.10. Think


  1. Apart from “Say a specific phrase” Alexa IFTTT trigger, any other Alexa trigger can use in case?