X
Home > Blog > STEM for Arduino > HOW to Make a Variable Speed Fan with KidsIOT

HOW to Make a Variable Speed Fan with KidsIOT

By r October 22nd, 2024 38 views
In this experiment, we build a small fan with variable rotation speeds. The required modules are a five-channel AD button module (speed control) and an 130 motor.

Flow

4501

Assembly

line1

Required Components

45_00

line1

Step 1

45_01

line1

Step 2

45_02

line1

Step 3

45_03

line1

Step 4

45_04

line1

Step 5

45_05

line1

Step 6

45_06

line1

Step 7

45_07

line1

Completed

45_08

line1

Wiring Diagram

4502

Test Code

Open KidsBlock and connect the board to computer. Choose File –> Load from your computer.

3111

Choose path D:\Code\2.Code_kidsIOT and open 4.5Gearshift mode.sb3.

4503

Click 3209 to connect to port and then 2210.

Explanations

5top

Code Blocks

Blocks

Code block

Events

begin

P

setmode

P

readanalog

Serial

serialbegin

Serial

serialprint

Vari

variablename

Vari

setvariable

Vari

variable

Operators

less

Operators

greater

Operators

and

Motor

Motor_analogWrite

Data

map

Control

forever

Control

if

Control

wait

line5

Conceive:

  1. Initialization

    Set pin mode and initialize the serial port.

    4504

line3

  1. Main Code

    Loop:

    • Press button 5 to adjust the speed to 40%.

    • Press button 4 to adjust the speed to 60%.

    • Press button 3 to adjust the speed to 80%.

    • Press button 2 to adjust the speed to 100%.

    • Press button 1 to stop the fan.

    4505

Build blocks:

The code structure is similar to that in chapter 3.8.

In addition, here we adopt a map block to configure the motor PWM.

map

peg

line3

6top

Q :What is MAP?

A :In mathematics, MAP is the term for a relationship between two sets of elements that “correspond” to each other.

Set: a whole consisting of one or more defined elements.

There is a correspondence between Set A and B. For every Element a in Set A, there is always a unique element b corresponding to it in Set B, which is called map A to B.

The concept of mapping is not only used in mathematics, but in computer science. In a computer program, mapping is a way to map each element in one set to a unique element in another.

6bottom

line3

We know that the rotation speed is effected by PWM duty cycle.

The range of PWM is 0 ~ 255. When PWM=255, the speed is at maximum. In this experiment, we set the speed range from 0 to 100, and map the speed values to PWM by the map block.

Divide PWM equally into 100 parts, so each part is 2.55, which corresponds to 1 speed.

  • Maximum unit of PWM: 2.55

  • Maximum unit of speed: 1

4508

The speed value multiplied by 2.55 equals the corresponding PWM value:

PWMv=25501000V


map

In a map block, five operators need to be set:

  • The first is the value being mapped, here it is the speed value.

  • The second and third are the range of the value being mapped, here is the speed range.

  • The forth and fifth are the range of the mapping value, here is the range of motor PWM.

4506 returns the PWM value of speed of 40.

Put it into Motor_analogWrite to set the mapped value to the duty cycle of the motor, so that the motor will rotate at the speed of 40%.

Similarly, we duplicate this block and set speed value(the first operator in map block) to 60, 80 and 100 to make the fan work at the speed of 60%, 80% and 100%.

This map block can directly set the range of mapped values and of mapping values, so we only need to modify the mapped values without calculating the corresponding mapping values one by one.

5bottom

Test Result
4top
Please connect to an external power suplly if indeed. The fan sometimes rotates in a very low speed due to an insufficient power supply.
After uploading code, press button 5 - 2 orderly, and the fan speed will be adjusted to 40, 60, 80,100 accordingly. When you press button 1, the fan turns off.
4503
4bottom
HOW to Make a Manual Control Fan with KidsIOT
Previous
HOW to Make a Manual Control Fan with KidsIOT
Read More
HOW to Make a Track Alarm with KidsIOT
Next
HOW to Make a Track Alarm with KidsIOT
Read More
Message Us