# Case 03: Environmental Motor Fan Level:  
## Goal
## Background
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.

## Part List
## Assembly step
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!

## Hardware connect
## Programming (MakeCode)
* In `on start`, put `initialize 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 by `Read 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 display * Then 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 nested `if-else` statement * Use the `temperature < 22` as first condition * In the first `if` segment, turn off the fan by `Set Motor fan with speed 0 at P1` * Use the `temperature < 26` as second condition * In the second `if` segment, turn on the fan with half speed by `Set Motor fan with speed 600 at P1` * Use the `temperature >= 26` as third condition * In the third `if` segment, turn on the fan with full speed by `Set Motor fan with speed 1023 at P1` 
Full Solution
MakeCode: [https://makecode.microbit.org/S26451-01818-60712-97331](https://makecode.microbit.org/S26451-01818-60712-97331)
You could also download the program from the following website:

## Think
## 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.
Q1. Apart from open the fans, any other method to reduce the temperature?