Jotrin Electronics
Description Quantity Total (USD) Operation
Shopping cart products
Shopping cart products : 0
Home > Technology List > Micro bit can be used to DIY smart small fans

Micro bit can be used to DIY smart small fans

Update Time: 2019-12-20 11:33:23

DIY gadgets using Micro bits - smart little fans.We have introduced several Micro Bit programming tools, so today I would like to use one of them to experience the fun of Micro Bit programming.

First of all, a brief introduction is given to the members of the hardware part. The main control part and the carrier use the Micro Bit smart car kit of "absense" :

The fan part is the "mini 130 motor electric pony set" that the author spent a few yuan on a certain treasure. It looks very small but full of power. The wind power is quite good, but the fan blade is a little small, otherwise it is no worse than those small desktop fans:

The fan drive is also purchased from a certain treasure. It is a PWM regulating module with dual MOS tubes in parallel, which can be used for dimming and motor speed regulation.

The control principle is actually very simple. After correctly connecting the circuit, as long as Micro bit gives a high level signal to the PWM speed regulating module, the MOS tube can conduct.After checking the hardware schematic diagram of Micro bit car, it was found that there were several independent led pins, one of which P7 pin was selected as the control pin of the fan:

First, we open the browser and enter the address of Micro bit's official website: There are two development environments to choose from. The author selects the JavaScript module editor.

In the open programming interface, find the "new project" option, click and create a new project:

Next, we named the project "Micro bit smart fan" and saved it in a custom folder:

Then we can start building blocks.After contact with the modular programming of Micro bit, you will find that the Micro bit of programming is very simple, simply drag the blocks, change number, you can easily realize the function that we want to, for example in this small project, we want to let the wind up, only need to write such a simple way, then it is ok to download the program to Micro -, is very simple:

Of course, this function is too simple, not to mention the so-called "intelligent fan", we can also use some resources on the car, let this fan appear more intelligent, for example: we can use the "infrared obstacle avoidance sensor" to detect whether there is a person in front of the fan, automatically open the fan;Micro bit's built-in temperature sensor is used to detect the ambient temperature to determine whether to turn on the fan.There are also buttons on the Micro bit to control fan start and stop;The remote control of the car comes with remote control of fan start, stop, shift and so on.

First to add an "infrared obstacle avoidance sensor" it, we judge the sensor signal, when the sensor has a signal, that there is someone in front of the car (or object, of course, if the human body at this time if the infrared sensor, the effect should be better), and then automatically open the fan;When the sensor signal is no, automatically close the fan;Since the building blocks on the chassis of the car are used here, the drive package of "absense" needs to be loaded. The specific steps are as follows:

1. Click the "expand" option:

2. Enter the address of the driver package and click the "search" button:

3. After finding the driver package, click to load it successfully:

4. After successful loading, we can see that many new blocks are added to the block column:

Next, we use the blocks that have just been loaded. We find the blocks of "obstacle avoidance sensor" in "car class" :

And when we drag this block into the program, we see that the block is gray, which means it can't be used. Why?We can guess from the name of the building blocks, this should be a judgment condition, then, we must also add some logical building blocks, yes, it is true, next, we find the following building blocks in the "logical" building blocks, this building block is equivalent to the "if...The else..."Statement:

Then, it becomes simple. When there is a signal from the obstacle avoidance sensor, pin P7 is set to 1.When there is no signal from the obstacle avoidance sensor, the fan can be started and stopped by setting the P7 pin to 0. The blocks can be built as follows:

Of course, the above program can only realize the fan switch, and can not achieve speed regulation, if we also need to speed the fan, then we need to change the program, for example, we can change:

The author changed the pin output mode to PWM output, and set a variable to adjust the duty cycle of PWM. The value of this variable can be adjusted by two buttons on the Micro bit, thus realizing the speed regulation of the fan.

Of course, we can also add infrared remote control for remote control. For example, we can divide the value of PWM from 0 to 1000 into the following five gears:

 When the PWM value is 0, the speed is 0, that is, the fan stops.

 When the PWM value is 250, the speed is 1 file;

 When the PWM value is 500, the speed is 2 files;

 When the PWM value is 750, the speed is 3 files;

 When the PWM value is 1000, the speed is 4 files, and the fan speed is maximum.

Then, we can quickly select the corresponding gear by pressing the corresponding speed on the remote control, that is, when the number is 0, the fan is 0, and when the number is 1, the fan is 1...And so on;

Next, we create a function that specifically to deal with the PWM value fan gear (you can also use other ways, the author here is mainly to teach you how to customize the function and function calls), click on the "function" blocks, and then choose in the pop up building blocks "to create a function", and name, the author here named "FanSwitchSet" :

In this way, in the program interface, there is an extra functional block:

Next, we need to add corresponding functions to this building block, which can also be realized in the way of building blocks. However, I will tell you how to program it in JavaScript.If we switch to the JavaScript interface for code interface, find the function "functionFanSwitchSet()" and add the corresponding functional code to it. The author USES a switch statement to implement this function:

Once the code is written, it can be converted directly to building blocks, but there is no standard building block to convert this custom function.


Previous: Lite-On Technology Selected as a Member of 2012 DJSI two years in a row, ranked as the Sector Leader of Electronic Component & Equipment

Next: Ams a number of innovative sensor technologies appear in MWC



Account Center


Live Chat