0

$USD

$USD
PROJECTS micro:bit

mirco:bit Project 4: Electric Fan

DFRobot Oct 14 2018 1343

Before making an electric fan that runs at different speed, we will need to learn how to switch on or off the fan with the button module as what we have done in the previous project. After that, we will learn how to control the speed of a fan with the knob module.

Components needed

Main control board of micro:bit
Expansion board of micro:bit
1×fan module
1× button module
1× knob module
1× USB cable

Hardware Connection

Connect the button module (knob module) to the P0 of the expansion board
Connect the fan module to the P1 of the expansion board


The use of electric fan

When connecting the Boson modules, we should notice that due to the power consumption of modules such as fans or servos, an external power supply is always required. Therefore, we will connect the micro: bit to the computer via one USB cable to upload the program, when finshed, we will switch USB cable to the external power supply on the expansion board.


Program

Task1:Control the fan with the button module

Goal: when the button is pressed, the fan starts running; when released, the fan stops. 
STEP1: The button module connects to P0, which means we will need to use the “digital read” function on P0 to first detect the status of the button. 

The fan module connects to P1. Likewise, to control the fan, we will use the “digital write” function on P1 to switch it between ON an OFF. 
The “digital read” and “digital write” function can be found under “Pins.”


STEP2: The condition operator "="  under “Logic” is used to determine whether the button is pressed or not. When the button is pressed, the “digital read “function returns “1”, which meets the condition of “1” that we preset at beginning, so the program under the statement will be executed. However, when it returns “0”, the program under the statement will be skipped.


STEP3: If the button is pressed, the fan will be turned on; otherwise it stays off. The “if-else” function under “logic” will help us make the choice depending on the status of the button.


STEP4: By putting the function blocks mentioned above all together, we should end up with a program with the following function: when the button is pressed, the fan is turned on, when it is released, the fan is turned off. 


Task2 : electric fan operating at various speed

Functions: a larger value the knob reaches, the higher speed the fan operates controlled by the micro: bit; a smaller value the knob reaches, the lower speed the fan operates controlled by the micro: bit. The value the knob reaches is different, so the corresponding speed is different. The speed of the fan continuously changes when the knob rotates.

STEP1: connect the hardware. The button module used in Task1 should be replaced by a knob module.


STEP2: determine the speed of the fan by reading the value the knob reaches. The simulated value falls into the range between 0 and 1023 which correspond to different speed of the fan. The knob is connected to the pin P0. The procedure for calling the instruction: Pins(Advance) ---- analog read pin (P0).


STEP3: The speed of the fan is determined by the value the knob reaches corresponding to P0. Control the speed of the fan by assign the value of P0 to P1. The procedure for calling the instruction: Pin (Advance) ---- analog write pin P0 to (1023)", change P0 to P1. The obtained value of the knob (P0) should be placed in the value of P1.


STEP4:the final program