Electric fans are a common electric appliance globally. Just in my country, it is estimated that there are 45 to 52 million electric fans, with an average of 3 per household.
For a non-air-conditioned household, there are electric fans in every room. The graphic picture below shows the daily situation for non-air-conditioned households located in tropical climate countries.
To turn on an electric fan, you need to press the fan speed controller, either through buttons or a rotary selector switch. Here are the options below.
- 0: fan off.
- 1: fan on, low speed.
- 2: fan on, medium speed.
- 3: fan on, high speed.
So this routine of operating the electric fan to turn it on, set the desired fan speed, and then turn it off is what everyone does in the house every day. For me, an able-bodied person, it's not a problem. But, for elderly people with walking problems, this routine of operating the electric fan daily becomes a burden.
Solution:The solution is to operate the electric fan using voice commands. Doing this will eliminate the need to physically operate the electric fan to turn it on, set the desired fan speed, and turn it off.
To implement this solution, I am going to modify the electric fan speed controller to have internet connectivity using the nRF7002 DK. Then, I am going to use the Google Nest Mini 2nd Generation to accept voice commands to change the speed of the electric fan.
Initial project steps:I started this project by buying a nRF7002 DK and a Google Nest Mini 2nd Generation. Because it is my first time doing a project using the nRF7002 DK, I went through the Nordic Developer Academy to learn some basics.
For this project, I am going to modify the speed controller for an electric stand fan. Shown below is a rotary switch-type speed controller that is attached to the back of the electric stand fan.
Shown below are the disassembled rotary speed controller pictures of a Hanabishi electric stand fan.
Fan speed controller wire color descriptions:
- Blue and brown wires are connected to a 220V AC plug.
- Blue wire is shorted to the white wire connected to the motor.
- White, grey, red, and yellow wires are connected to the motor.
Rotary selector switch operation:
- Fan speed 1: brown wire is shorted to grey wire.
- Fan speed 2: brown wire is shorted to red wire.
- Fan speed 3: brown wire is shorted to yellow wire.
According to the above information, I can replace the rotary selector switch with solid state relays.
nRF7002DK GPIO Output Voltage:After learning some basics from Nordic Developer Academy, I drove some nRF7002 DK GPIO's high and low. I measured the GPIO output high voltage, and I read 1.8V. VDD output is also 1.8V. Normally, microcontroller board VDD and GPIO high voltages are 3.3V. Knowing the VDD and GPIO high output voltages is important since I am going to drive a 5V, 4-channel solid state relay board. Based on this information, I need to use a logic-level shifter board to drive the 5V, 4-channel solid state relay board.
Since the 4-channel solid state relay is a low level trigger, I drove the nRF7002 DK GPIO11, GPIO12, and GPIO13 low. I was able to confirm that the solid state relays were triggered. The small board in the middle is the logic level shifter board. The component at the bottom is a 220VAC to 5VDC step down power supply module.
For this project, I am going to use MQTT to send a message to the electric fan speed controller to turn it on and change speed. MQTT or Message Queueing Telemetry Transport, is a lightweight, publish-subscribe, machine-to-machine network protocol for a message queue/message queuing service.
I am going to define a custom Google action that will recognize a phrase, for example, "Hey Google, activate fan low speed" and then send this action to an MQTT topic. It is easy to recognize custom phrases using Google Assistant by using the Google Assistant to IFTTT custom integration. IFTTT is short for If This Then That and is the best way to integrate apps, devices, and services. The problem is that IFTTT does not have an action to send messages to an MQTT topic. To connect IFTTT and MQTT, I am going to use the Beebotte MQTT broker. IFTTT can send action to the MQTT topic using the Beebotte Rest API webhooks.
Beebotee MQTT Broker Setup:- Create an account at Beebotte. Then create a channel with two resources, as shown below.
- After saving the channel, go to your channel and copy the channel token to a notepad.
- Create a dashboard with two widgets, the input control widget and a basic value widget.
I am going to use the networking MQTT example application from nRF Connect SDK 2.4.2 as the base program.
- Import the MQTT sample program to VS Code and create a build configuration for the nRF7002 DK.
- Open the Kconfig.transport file and set the MQTT broker hostname to mqtt.beebotte.com.
- Add config MQTT_SAMPLE_HELPER_USERNAME and set the username to your Beebotte channel token.
- Set MQTT_SAMPLE_TRANSPORT_CLIENT_ID to your Beebotte channel name.
- Set MQTT_SAMPLE_TRANSPORT_PUBLISH_TOPIC to pubga.
- Set MQTT_SAMPLE_TRANSPORT_SUBSCRIBE_TOPIC to subga.
- Open prj.conf and add CONFIG_WIFI_CREDENTIALS_STATIC_SSID and CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD. Set these to your Wi-Fi router SSID and PASSWORD.
- Add these two code lines to transport.c->connect_work_fn().
- Do a pristine build.
Open the VS Studio nRF Serial Terminal. Then erase and flash the firmware to the nRF7002 DK. These are the logs that show a successful connection. nRF7002 DK led 1 on also indicates a successful connection.
The nRF7002 DK MQTT firmware will publish to topic IFTTT/pubga on a regular time interval and upon button press. For this project, publishing to the topic IFTTT/pubga is not needed but it is just nice to have for further improvements.
Using the Beebotte dashboard input widget, I am going to send these message strings to operate the electric fan.
- FANOFF: fan off.
- FANLOW: fan on, low speed.
- FANMED: fan on, medium speed.
- FANHIGH: fan on, high speed.
Here are the logs after sending the messages. The received messages at nRF7002 DK are in JSON format.
I am going to use the nRF7002 DK GPIO11, GPIO12, and GPIO13 to drive the 4-channel low level trigger solid state relay board. For more detailed information on how to do this, refer to the Nordic Developer Academy Course: nRF Connect SDK Fundamentals Lesson 2 and Lesson 6.
Reading the Received JSON Data:The received MQTT messages are in JSON format from the Beebotte Dashboard.
{"data":"FANLOW", "ispublic":false}
{"data":"FANMED", "ispublic":false}
{"data":"FANHIGH", "ispublic":false}
{"data":"FANOFF", "ispublic":false}
To read the received JSON data, I am going to use the cJSON library, which is already available at the nRF Connect SDK. Instructions are below.
- Set CONFIG_CJSON_LIB=y, CONFIG_NEWLIB_LIBC=y, and CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y at prj.conf.
- At transport.c, add cJSON includes.
- At transport.c->transport_task(), call cJSON_Init().
- At transport.c->on_mqtt_publish(), read or parse the received JSON message. Then set the correct GPIO output to drive the solid state relays, which will control the electric fan.
Using IFTTT Google Assistant, the trigger phrase needs to start with "Hey Google, activate", then your trigger phrase. To set fan speed to low speed, the complete trigger phrase will be "Hey Google, activate fan low speed".
- Since this project requires more than two IFTTT applets, subscribe to the IFTTT pro plan.
- Create a new applet. First, setup If This by clicking "Add".
- Select Google Assistant as a service.
- Select activate scene.
- Set the scene name to "fan low speed" and then click "Create Trigger".
- Setup, Then That by clicking "Add".
- Select Webhooks as a service.
- Select make a web request.
- Set URL to https://api.beebotte.com/v1/data/publish/IFTTT/subga?token=token_xxxxxxxxxxxxxxxx.
- Set method to POST.
- Set content type to application/json.
- Set body to {"data":"FANLOW"}.
- Repeat the same procedures above to set fan mode to off, medium speed, and high speed.
I attached all components on a PVC board by using double-sided foam tape. Then I also connected the PVC board to the back of the electric fan using double-sided foam tape. I used a 2/3/5-way lever nut terminal block to connect AC wires and motor wires. I cut a 220V AC extension cord and used it to connect the set-up to the 220V AC socket.
Comments