63. Case 62: The Gesture-controlled Fan#

63.1. Introduction#

Use Nezha 48 IN 1 Inventor’s Kit with ELECFREAKS Planetx Gesture Sensor, 8 RGB Rainbow LED Ring and ELECFREAKS PlanetX Motor Fan to create a fan that can control the wind speed through gestures.

../../_images/neza-inventor-s-kit-case-62-01.png

63.2. Case Build-up#

Materials Required#

Nezha 48 IN 1 Inventor’s Kit

ELECFREAKS Planetx Gesture Sensor

8 RGB Rainbow LED Ring

ELECFREAKS PlanetX Motor Fan

Structure building#

Component Details

../../_images/neza-inventor-s-kit-case-62-02.png

Build it as the assembly steps suggest:

../../_images/neza-inventor-s-kit-step-62-01.png

../../_images/neza-inventor-s-kit-step-62-02.png

../../_images/neza-inventor-s-kit-step-62-03.png

../../_images/neza-inventor-s-kit-step-62-04.png

../../_images/neza-inventor-s-kit-step-62-05.png

../../_images/neza-inventor-s-kit-step-62-06.png

../../_images/neza-inventor-s-kit-step-62-07.png

../../_images/neza-inventor-s-kit-step-62-08.png

../../_images/neza-inventor-s-kit-step-62-09.png

Build completion :

../../_images/neza-inventor-s-kit-step-62-10.png

Connection Diagram#

As the picture suggests, Connect the ELECFREAKS Planetx Gesture Sensor to IIC port and the ELECFREAKS PlanetX Motor Fan to J1 port and the 8 RGB Rainbow LED Ring to J2 port on Nezha breakout board.

../../_images/neza-inventor-s-kit-case-62-03.png

63.3. MakeCode Programming#

Step 1#

Click “Advanced” in the MakeCode drawer to see more choices.

../../_images/neza-inventor-s-kit-case-37-04.png

For programming the ELECFREAKS Planetx Gesture Sensor, ELECFREAKS PlanetX Motor Fan, and the 8 RGB Rainbow LED Ring, enter “PlanetX” in the dialog box and click search to download it.

../../_images/neza-inventor-s-kit-case-37-05.png

For programming the Nezha, click “Extensions” at the bottom of the drawer and search with “nezha” to download it.

../../_images/neza-inventor-s-kit-case-37-06.png

Notice: If you met a tip indicating that some codebases would be deleted due to incompatibility, you may continue as the tips say or create a new project in the menu.

Step 2#

Program as picture suggests#

Initialize the 8 RGB Rainbow LED Ring to connect to the J2 port of the Nezha expansion board.

../../_images/neza-inventor-s-kit-case-62-07.png

Set when the gesture sensor detects upward gesture, judge whether the level is less than 8, if less than 8 then the variable level will automatically add one. Set when the gesture sensor detects a downward gesture, judge whether the level is greater than 0, if greater than 0 then the variable level is automatically minus one, and set the light to black. Set when the gesture sensor detects the gesture to the left, turn off the fan, and lights, and set the variable level to 0.

../../_images/neza-inventor-s-kit-case-62-08.png

When the value of the variable level is not 0, set speed=level×10+20, set the speed of the motor fan module connected to the J1 port of which Zha expansion board to speed%, set the number of lights to be lit according to the value of level, and set the light color to blue. ../../_images/neza-inventor-s-kit-case-62-09.png

Full procedure :

../../_images/neza-inventor-s-kit-case-62-10.png

Reference#

Link: https://makecode.microbit.org/v4.0.18#editor/_fv3Fht0bbEXT

You may also download it directly:

Result#

Fan speed is controlled by gestures. Upward gestures control fan acceleration, downward gestures control fan deceleration, leftward gestures control fan stop rotation, and fan speed is displayed by the LED rings, and the faster the speed is, the stronger lights are lit.

../../_images/neza-inventor-s-kit-case-62.gif