Advanced Lesson 9 Automatic Fan

Share for us

Introduction

In this lesson, let’s make an intelligent fan. As the temperature rises, the rotation speed of the fan becomes faster and faster, and when the temperature drops, it gets slower.

Components

Circuit

L293D is a chip that can drive the motor. Thermistor is a kind of sensitive component and it can be divided into PTC and NTC. In this experiment, what we use is NTC  whose resistance value decreases with the higher temperature.

Programming Steps

Step 1

After creating the project, click Variables category to create 4 variables: motor1, motor2, ther, and therVal.

Step 2

Initialize the values of pins in Start block.

Step 3

Create a function to control the motor. Next, click on the Functions category to drag the to do something block to the right area and rename it “ Motor”. Then click the setting button to add an input name block and name it “Speed”.

Step 4

Put set pwm P0 frequency to block and 2 set pwm P0 pulse width to 0 % blocks from Raspberry Pi category into Motor function block. Place blocks, motor1 and motor2 into the the slot of pins. Add a Speed block to control the pulse width of motor2.

Step 5

Click the Remote Control icon to enter the Remote Control page.

Step 6

Add a switch to the control area.

Step 7

Go back to the Programming page, click on the Remote category, and drag the read from remote block into Forever block.

Step 8

Get an if do block from Logic category then put it into the Forever block. Click the setting button and add an else block accordingly.

Step 9

Place a Comparison Operator ( = ) block into the if block. Put the Switch A get value block on the left side of the equals sign and the number block, 0 on the right, then change 0 to 1.

Step 10

When Switch A has a value of 1, read the value of thermistor and assign it to the variable, therVal.

Step 11

Display the value of therVal in the Debug Monitor by print block.

After clicking the Flash button, you can see the value of thermistor under the current environment.

Step 12

Add another if do block below the print block and change it into if do else block.

Step 13

A judgment condition is set by using the if do else block and the Comparison Operator ( = ) block to judge if the therVal is less than the 2300. The value 2300 is the threshold gotten by referring to Step 11.

Step 14

If the judgment condition set above is true, set the speed of motor to 80; otherwise, set it to 40.

Step 15

Inside the first else of the if do else block, set Speed to 0.

Step 16

Save the project and flash it into the Raspberry Pi (refer to lesson 0 for details). When the temperature is higher than the set value, the rotation speed of the fan increases.

Fold Cardboard

Step 1

Take out the matching cardboard of this lesson.

Step 2

Based on the creases, fold the cardboard into the cube as shown.

Step 3

Build the circuit as shown in the picture below. Please do NOT change the position of components optionally when building circuits, in case the card cannot be installed.

Step 4

Mount the cube of cardboard on the circuit as shown.