Tutorial series list:
Tutorial | Micro:bit Particle Kit (Based on Mind+) 01 – Introduction
Tutorial | Micro:bit Particle Kit (Based on Mind+) 02 – DIY Emoji
Tutorial | Micro:bit Particle Kit (Based on Mind+) 03 – Blinking LED
The spaceship drifts in the universe, watching the alternating lights outside the porthole.
The temperature inside the cabin is also slowly rising, and beads of sweat have formed on Mike’s forehead. Mike wipes his sweat and says, “Let’s make a small fan to cool down.” micro:bit immediately agrees.
However, the two of them are a bit at a loss. Suddenly, Mike has a bright idea and remembers what Teacher Xiaomi taught the students in the last class. The brightness change of the breathing light is just the principle of speed control for a fan. So, Mike and micro:bit began to make the small fan.
Required Components
1× micro:bit main control board
1× micro:bit expansion board
1× fan module
Similar to the principle of household fans, it has a motor inside, and the blades can rotate with adjustable speed.
1× button module
1× knob module
1× MicroUSB connection cable
Task 1: Button Fan Functionality
When the button is pressed, the external fan rotates, and when the button is released, the fan stops rotating.
Hardware Connection
Connect the button module (knob module) to the P0 interface on the expansion board;
Connect the fan module to the P1 interface on the expansion board.
Using the fan module
When connecting hardware, we connect micro:bit to the computer for program debugging and downloading;
In the experiment, due to the high power consumption of fans or servos and other sensors, an external power supply (or computer USB port) is required for independent power supply. The external power supply is connected to the external power interface VIN on the expansion board.
By detecting the value of pin P0, we can determine whether the button is pressed. When the button is pressed, set the fan connection pin to high level, and the fan rotates; when the button is released, set the fan connection pin to low level, and the fan stops rotating.
STEP1: The button module belongs to digital input. Click on the “microbit” module, select the “read digital pin P0” command, and drag it to the script area.
STEP2: The “operator” module’s “ = ” can determine whether the button is pressed. If the button value is “1”, it means the button is pressed; otherwise, the button is not pressed. Embed “read digital pin P0” in the equation.
STEP3: Conditional judgment – how to determine if the button is pressed? In the “control” module, find the “if then do, else do” command. Drag it into the script area of the loop module.
STEP4: Embed the “ = ” condition instructions into the judgment instruction “if then do, else do”.
STEP5: Find the “set digital pin P0 output low level” command in the “microbit” module, modify it to “set digital pin P1 output high level” and “set digital pin P1 output low level”, and place them under “then do” and “else do” respectively. When the button is pressed, this command will be executed to make the fan rotate. When the button is released, the fan will stop rotating.
Task 2: Speed Control Fan
Functionality
When the knob is turned to a larger value, micro:bit controls the fan speed to increase; when the knob is turned to a smaller value, micro:bit controls the fan speed to decrease. Different rotation values of the knob correspond to different fan speeds.
Hardware Connection
Replace the button module used in Task 1 with the knob module.
Write Program
By reading the value of the knob, we can determine the speed of the fan. The knob value is an analog value, ranging from 0-1023, which will be mapped to the fan’s speed value.
STEP1: Connect the knob to pin P0 of the board. Click on the “microbit” module, select the “read analog pin P0” command, and drag it to the script area.
STEP2: The speed of the fan is determined byP0, and the value ofP0 is assigned toP1, which can control the change of the fan speed. The range of the value read by the Microbit board (knob) is 0-1023, which is larger than the output analog (fan) range 0-255. The parameter range of the knob far exceeds the output range. In addition to using the “ / ( division )” module to reduce the range, we can also use the “ mapping” command to map the range of 0-1023 down to 0-255.
Drag the “mapping from __ to __” from the “operator” module into the script area, place “read analog pin P0” in the right box of “mapping”, and change the value to “from [0,1023] to [0,255]”.
STEP3: Drag the “set analog pin P0 output” from the “microbit” module into the “loop execute” area of the script, change P0 to P1, and nest the two commands together.
Skill Enhancement
Can the knob and button only control small fans? Can they control other hardware? Let’s try programming the knob or button to control a dot matrix screen.


Follow the store to receive a large gift package (99-5 yuan coupon)
https://mall.jd.com/index-195980.html

Sign in to receive gifts, up to 30 yuan store coupons
https://mall.jd.com/index-195980.html

Best-selling item at the lowest price in five consecutive years, original price 259 yuan/item, 618 price 219 yuan/itemhttps://item.jd.com/10262868196.html

Raspberry Pi 3b+ available for sale, only 289 yuan/item, limited to one per IDhttps://item.jd.com/28478523065.html
—— End of text —
Recommended reading:
Using programming to solve college entrance examination math problems
The Central Committee of the Communist Youth League stated: “Every child should learn programming, let’s promote programming education development together”
Mind+ graphical programming: specially designed for teenagers to learn programming
Heavyweight! The offline version of the official micro:bit programming software is officially launched!
2018 focus on the development of maker education in primary and secondary schools in Sichuan Province
The new curriculum standards for high schools: maker education content has become the main force of technical courses!
mushroom
cloud
maker
The Mushroom Cloud Maker Space, initiated by DFRobot in 2013, is a national maker space recognized by the Ministry of Science and Technology.
As a sub-brand of DFRobot, it plays multiple service roles in the maker education ecosystem built by the company, including maker space solutions, teacher training, course development, cultural dissemination, project guidance, etc.
Reply【mb】 to download micro:bit Chinese learning materials
Reply【mc】 to get the makecode official software download link
Reply【mind】 to get the Mind+ programming software download link
Reply【books】 to see recommended maker education textbooks
Reply【courses】 to see primary and secondary maker education curriculum system
Reply【space】 to see primary and secondary campus maker space solutions
Long press the QR code to follow,
More exciting content is continuously updated!
↓↓↓Click“Read Original” to read the original page!