SunFounder 3in1 Kit
Note:
• Open the 5.1.if_else.ino file under the path of 3in1-kit\learning_project\5.1.if_else.
• Or copy this code into Arduino IDE.
After the code is uploaded successfully, if you do not close the door, the LED will light up, prompting you to close the
door.
By the way, if we need the opposite effect (lighting up the LED when the door is closed), we just need to modify the
condition in the if.
• if else
The if else allows greater control over the flow of code than the basic if statement, by allowing
multiple tests to be grouped.
4.5.2 5.2 Threshold
In many projects, you will encounter such a need. “When xxx reaches a certain level, then. .. ”
For example, in a smart home, when the light intensity is lower than 50Lux, turn on the light; Another example is in
the computer motherboard, if the operating temperature of the CPU is higher than 65 degrees Celsius, turn on the fan,
and so on.
In these requirements, the keyword “threshold” is reflected.
We can adjust the value of the threshold to make the circuit operate more in line with individual needs. For example,
if I like a brighter living environment, I can increase the threshold of the automatic lights of the smart home to 80Lux.
Another example is that the ventilation environment of my studio is not very good, and the heat dissipation demand is
higher, then the threshold value of automatic fan opening can be adjusted to 50 degrees Celsius.
Here we use soil moisture sensor and 2 LEDs to make a pot monitor. If the soil is too dry, the red LED will light up; if
the soil is moist enough, the green LED will light up. You need to manually adjust the thresholds for determining the
dryness and wetness of the soil.
Required Components
In this project, we need the following components.
It’s definitely convenient to buy a whole kit, here’s the link:
Name ITEMS IN THIS KIT LINK
3 in 1 Starter Kit 380+
You can also buy them separately from the links below.
4.5. 5. More Syntax 135