6. Case 03: Environmental Motor Fan¶
Level:
6.1. Goal¶
Make an environmentally friendly automated motor fan by detecting the surrounding temperature.
6.2. Background¶
What is an Environmental Motor Fan??
Smart motor fan is a fan that can adjust the power, turn on and off automatically to save electricity when not needed. Nowadays, for example, the temperature in the room is very low and cold, the air-conditioner also keeps turned on at high intensity. If there is a temperature sensor to detect surrounding parameters and change the power automatically, it can save much energy.
Environmental Motor Fan Principle
The temperature and humidity sensor installed in the house will scan for surrounding conditions continuously. When the temperature is too low or at average, the fan will change the intensity to off or low. When the temperature is high the fan will adjust to max power.
6.3. Part List¶
6.4. Assembly step¶
Step1
To start with, build the Big House Model.
Step 2
To build a small living room at the right side in the home, put Model E4 onto A model as a wall.
Step 3
Attach the Temperature and humidity sensor to Model E4 using M4 * 10mm screws and nuts.
Step 4
Attach OLED Display to the Model E4 using M2 * 10mm screws and nuts.
Step 5
Attach motor fan to the Model F using M4 * 10mm screws and nuts. And the connecting wire could be bended to the hole next to it.
Step 6
To build a fan stand, put Model F into the B3, B4 model.
Step 7
To build a table, put the Model I1 onto the model I2.
Step 8
The table completed!
Step 9
Place the table at the living room.
Step 10
Assembly Completed!
6.5. Hardware connect¶
Connect the Temperature and Humidity sensor (DHT11) to P2
Connect the extended OLED display to I2C Port
Connect the Motor module to P1
6.6. Programming (MakeCode)¶
Step 1. Initialize OLED display
In
on start
, putinitialize OLED with width 128 height 64
to initialize the OLED display
Step 2. Create variable
Create a variable called
temperature
Step 3. Read and show the reading from DHT11
In
Forever
, read the data byRead Temperature & Humidity Sensor at pin P2
Get the temperature value from data, and save it to variable by
(set temperature to Get Temperature °C
)Before update the screen infomation, suggest clear up the OLED display each time
Use
clear OLED display
to clear the displayThen use
show string join Temperature: temperature
to show the temperature value with formatted text on display
Step 4. Examine the temperature
In
Forever
, put a nestedif-else
statementUse the
temperature < 22
as first conditionIn the first
if
segment, turn off the fan bySet Motor fan with speed 0 at P1
Use the
temperature < 26
as second conditionIn the second
if
segment, turn on the fan with half speed bySet Motor fan with speed 600 at P1
Use the
temperature >= 26
as third conditionIn the third
if
segment, turn on the fan with full speed bySet Motor fan with speed 1023 at P1
Full Solution
MakeCode: https://makecode.microbit.org/_c2637VXcbfHP
You could also download the program from the following website:
6.7. Result¶
When the room temperature changing, it will match either one of the condition, and the fans will turn on or off with different speed according to the room temperature.