Lesson 21: Plant watering
このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
English
Water the plants while you are away
- A soil sensor in the flower pot measures how wet the soil is. The Arduino reads it on A0; in the simulator the knob is the soil.
- A small pump on pin 7 gives the plant water. Here a blue LED shows when the pump runs.
- You decide when the pump goes on and when it goes off.
Words for this lesson
| Word | Meaning |
|---|---|
| moisture | how much water is in something, here in % |
| pump | a machine that moves water |
| percent (%) | out of 100 |
| limit | the number where something changes |
| bool | a variable that is only true or false |
English
From a reading to percent
| Knob | Reading | reading × 100 ÷ 1023 |
|---|---|---|
| 1.0 V | 204 | 19 % (dry: pump on) |
| 2.25 V | 460 | 44 % |
| 3.5 V | 716 | 69 % (wet: pump off) |
- Write
100L, not100: 716 × 100 = 71600, and aninton the Arduino holds at most 32767. TheLmakes it along, which holds much bigger numbers. - The Arduino drops the part after the decimal point: 69.99 becomes 69.
English
One limit or two?
| Moisture | One limit (30 %) | Two limits (on < 30 %, off > 60 %) |
|---|---|---|
| 44 %, soil drying | off | off |
| 19 %, dry | on | on |
| 44 %, getting wetter | off: the pump stops too early | on: it keeps watering |
| 69 %, wet | off | off |
- With one limit the pump stops at 30 % and starts again soon after: on, off, on, off.
- With two limits it waters until the soil is really wet, then waits until it is really dry.
bool pumpOn = false;
void setup() {
Serial.begin(9600);
pumpOn = true;
Serial.println(pumpOn ? "ON" : "OFF");
}
void loop() {
}
pumpOn ? "ON" : "OFF"means: ifpumpOnis true, use "ON", else use "OFF".
難易度 3/5 · 200 コイン + 今日初回達成時の小ボーナス
A soil sensor on A0 tells how wet the soil is. Work out the moisture in percent: moisture = reading * 100L / 1023. Print it after Moisture: . When the moisture is under 30 %, switch the pump on pin 7 on; else switch it off.
実行ボタンをクリックして出力を確認してください。
難易度 4/5 · 280 コイン + 今日初回達成時の小ボーナス
Near 30 % the pump goes on and off all the time. Real systems use two limits: switch on under 30 %, but switch off only over 60 %. In between, keep doing what you did. Use the variable pumpOn to remember it.
実行ボタンをクリックして出力を確認してください。