X
Home > Blog > STEM for Arduino > HOW to Make an Automatic Fan with KidsIOT

HOW to Make an Automatic Fan with KidsIOT

By r October 17th, 2024 51 views
We design to trigger the fan to automatically work when something approaches to it. This trigger mode integrates an ultrasonic sensor and an 130 motor.

Flow

4201

Assembly

line1

Required Components

42_00

line1

Step 1

42_01

line1

Step 2

42_02

line1

Step 3

42_03

line1

Step 4

42_04

line1

Step 5

42_05

line1

Step 6

42_06

line1

Step 7

42_07

line1

Completed

42_08

line1

Wiring Diagram

4202

Test Code

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

3111

Choose path D:\Code\2.Code_kidsIOT to open 4.2Trigger mode.sb3.

4203

Click 3209 to connect to port and then 2210.

6top

Q :After uploading the code, the detected distance is closer than the set value, and the fan starts to work, yet the monitor stops outputting distance values, with a prompt reading:

4204

A :The power supply may be insufficient, so an external power supply may be required.

DC

6bottom

Explanations

5top

Code Blocks

Blocks

Code block

Events

begin

Vari

variablename

Vari

setvariable

Vari

variable

Serial

serialbegin

Serial

serialprint

U

ultrasonic

Operators

less

Motor

Motor_analogWrite

Control

forever

Control

ifelse

Control

wait

line5

Build blocks:

Click add to add libraries DC Motor for esp32 and Ultrasonic.

4205

  1. Initialization

    Initialize the serial port first.

    4206

line3

  1. Main Code

    Loop: the ultrasonic sensor reads the distance values and the serial monitor prints them. It determines whether the value is less than 10cm(this threshold can be modified).

    • Distance < 10, fan rotates.

    • Distance > = 10, fan stops.

4207

5bottom

Test Result
4top
After uploading code, approach to the ultrasonic sensor.
When the ultrasonic sensor detects things around itself with a distance less than 10, the fan will rotate. If the distance equals or is greater than 10, the fan will stop rotating.
4203
4bottom
HOW to Make A Fan with Temperature Detection Function by KidsIOT
Previous
HOW to Make A Fan with Temperature Detection Function by KidsIOT
Read More
HOW to Make a Track Alarm with KidsIOT
Next
HOW to Make a Track Alarm with KidsIOT
Read More
Message Us