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.
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.
After creating the project, click Variables category to create 4 variables: motor1, motor2, ther, and therVal.
Initialize the values of pins in Start block.
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”.
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.
Click the Remote Control icon to enter the Remote Control page.
Add a switch to the control area.
Go back to the Programming page, click on the Remote category, and drag the read from remote block into Forever block.
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.
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.
When Switch A has a value of 1, read the value of thermistor and assign it to the variable, therVal.
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.
Add another if do block below the print block and change it into if do else block.
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.
If the judgment condition set above is true, set the speed of motor to 80; otherwise, set it to 40.
Inside the first else of the if do else block, set Speed to 0.
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.
Take out the matching cardboard of this lesson.
Based on the creases, fold the cardboard into the cube as shown.
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.
Mount the cube of cardboard on the circuit as shown.