Build a plant watering system - Internet of Things - ثاني ثانوي

Lesson 2 Build a Plant Watering System Build a Plant Watering System As the population is rising, more crops are needed to provide food and other essential products, but the large quantity of plants to be taken care of cannot be handled manually. By using automated systems for irrigation, efficiency is increased, and agriculture benefits greatly. In this lesson, you will use the Arduino UNO R3 to simulate a Plant Watering System. The system will use a motor to drive a watering system when the sensors detect that soil moisture has dropped and the temperature is high. For this project you will use the following components: • 1 DC Motor • 1 Temperature Sensor [TMP36] ⚫ 1 Soil Moisture Sensor ⚫1 Arduino UNO R3 Components that you will use in this project O UNO 18 Arduino Uno R3 2073-183 68 Line to digital lesson www.len.edu.sa DC Motor TMP Soil Moisture Sensor Temperature Sensor Figure 19: Project components

Lesson 2: Build a plant watering system

Build a Plant Watering System

Let's start by adding the components that you will need for this project to the workplane. First, find the Arduino UNO R3, add it to the workplane and rotate it 90 degrees. To add the Arduino Microcontroller: > Drag and drop the Arduino UNO R3 from the components library into the workplane. > Click on the rotation button three times. Plan Watering System وزارة التعليم 2173-1 2 1 80 UNO ARDUINO x3 Every time you click the rotation button, the selected component rotates 30 degrees clockwise. This is why you have to click the rotation button thrice to rotate the Arduino UND R3 90 degrees clockwise. Figure 3 20 Add the Arduino. Microcontroller 。 95 89

Lesson 2: Build a plant watering system

Let's start by adding the components that you will need for this project to the workplane.

90 Next, find the rest of the components, the DC Motor, the Temperature Sensor and the Soil Moisture Sensor, and add them to the workplane. To add components to the workplane: > Find the DC Motor from the components library and drag and drop it into the workplane. > Find the Temperature Sensor from the components library and drag and drop it into the workplane. > Find the Moisture Sensor from the components library and drag and drop it into the workplane. In this project, the DC Motor is used as a mean to turn on a water pump, which could provide water to the plants. Plant Watering System 3 2 وزارة التعليم 2073-1485 1 Figure 3.21. Add components to the workplane Onde 0 Basic Sanch min Send To

Lesson 2: Build a plant watering system

Next, find the rest of the components, the DC Motor, the Temperature Sensor and the Soil Moisture Sensor, and add them to the workplane.

Now, wire the DC Motor to the Arduino UNO R3. To wire the DC Motor: > Connect Terminal 1 of the DC Motor to an Arduino GND pin and change the wire color to black. > Connect Terminal 2 of the DC Motor to the Arduino Analog pin A5 and change the wire color to red. Plant Watering System درارة العالم 1 2 OO LINO TA Figure 3.22 Wire the DC Motor 91

Lesson 2: Build a plant watering system

Now, wire the DC Motor to the Arduino UNO R3.

92 وزارة التعليم Next, wire the Temperature Sensor to the Arduino UNO R3. To wire the Temperature Sensor: > Connect the Power pin of the Temperature Sensor to the Arduino 5V pin and change the wire color to red. > Connect the Vout pin of the Temperature Sensor to the Arduino Analog pin A3 and change the wire color to yellow. > Connect the GND pin of the Temperature Sensor to an Arduino GND pin and change the wire color to black. TMP Power Vout GND Plant Watering System 3 2 Figure 3.2 Wire the Temperature Sensor 0 K2 Code CONTI 80

Lesson 2: Build a plant watering system

Next, wire the Temperature Sensor to the Arduino UNO R3.

1 Continue by wiring the Soil Moisture Sensor to the Arduino UNO R3. To wire the Soil Moisture Sensor: > Connect the Power connector of the Soil Moisture Sensor to the Arduino 5V pin and change the wire color to red. > Connect the Ground connector of the Soil Moisture Sensor to an Arduino GND pin and change the wire color to black. > Connect the Signal connector of the Soil Moisture Sensor to the Arduino Analog pin A0 and change the wire color to green. Plant Wetering System وزارة التعليم 2 THE 3 Power Signal Ground 0 C7A Code Figure 3.24. Wire the Soil Moisture Sensor 93

Lesson 2: Build a plant watering system

Continue by wiring the Soil Moisture Sensor to the Arduino UNO R3.

94 The Serial Monitor The Serial Monitor is a tool we use to observe the values that we receive from the sensors. It makes the process of identifying problems in our circuit and/or code much easier by allowing the user to read output from the program and sensors. It can also be used for aesthetic reasons, to print a special message to the user, or to provide useful information and instructions. The Serial Monitor can be accessed from the bottom of the Code panel. Blocks Output Input Control Malh Serta Mantu 1 (Arduino Uno R3) Serial Monitor Show/hide serial monitor Text input Send text Clear text Toggle graph Agure 3.25 Serial Monitor Cheat newline Choose "with" to start a newline after each block's message or "without" to continue on the same line. print to serial mortal hello world The print to serial monitor () () newline block can be use to print messages in the Serial Monitor. The messages can be either character strings or numeric values. وارد الك ليدر J123-1985

Lesson 2: Build a plant watering system

The Serial Monitor

Example As an example, if you want to print the string "Soil Moisture:" without a newline, use: And if you want to print the value of analog pin A0 with a newline use: Beas DE JAP If you combine those two you will get more complete serial monitor output. Dee AA ாது walt () () Blocks Gelay the execution time of the program and its print outputs, thus providing a more pleasant output to the user. The block Puces delay the program for a defined number of seconds or milliseconds. Figure 3.26 Using the Serial Monitor Al 95

Lesson 2: Build a plant watering system

As an example, if you want to print the string "Soil Moisture: " without a newline, use:

96 The Temperature Sensor sends analog signals but it uses a special block so we can specify which temperature unit (Celsius or Fahrenheit) we want. To read the temperature in Celsius from analog pin A3 use: po to a Temprature mut point to al monitor ma tomper on p. A In units with Code Implementation First, the program prints the values of the soil moisture and the temperature to the serial monitor. Then, it checks if both conditions are evaluated true, and if so it turns the motor on, else it turns it off. Finally, the program waits for a second to avoid flooding the serial monitor with output. Тере 150 The print to serial monitor () blocks help you clearly see the values that the sensors detect in the environment The blockG decongess (he serial mentor output by stalling execution. ميلين استاد 2173-1465 The if () then else block checks if the soil moisture is under 150 and if the temperature is over 30. If both are true, it turns the motor on, by setting its pin to HIGH, else it turns it off by setting its pin to LOW. Sometimes the condition to be evaluated inside an it () then else block can be more complex than a simple value comparison. Figure 3.27 Code implementation

Lesson 2: Build a plant watering system

The Temperature Sensor sends analog

Code Implementation

Table 3.2: System input values and output states Soil moisture (pin A0) Temperature (pin A3) Output to motor (pin AS) ≥ 150 ≤30 LOW ≥ 150 >30 LOW K < 150 < 150 530 LOW >30 HIGH Now that you have finished with the coding blocks, you are ready to execute the program. Start the simulation by pressing the Start Simulation button. You can experiment and see the different states of the circuit by selecting a sensor's slider and adjusting its value:: Soil Moisture 600 and Temperature 25°C Soil Moisture 300 and Temperature 38 °C Soil Moisture 0 and Temperature 38 "C 15- כל 0000 DC Motor 0 rum DC Motor 0.rpm DC Motor 5555.rpm Figure 3.28. Motor speed at different Moisture and Temperature values 97

Lesson 2: Build a plant watering system

Table 3.2: System input values and output states

98 Exercises 1 If we wanted to set up the Smart Watering System in a more arid area where the water evaporates faster and the atmosphere is drier, what changes should we make? Describe a possible solution and present your ideas below. 2 In this lesson's project, the sensors and actuator did not require a breadboard to connect to the Arduino, In contrast with other projects. Describe the reasons why below. 3 Check with a tick the output of the following blocks. وزارة التعليم World Serial Monitor T Hello World Ho World Serial Monitor HelloWorld Helloworld Serial Monitor world! Hello World! Hello World!

Lesson 2: Build a plant watering system

If we wanted to set up the Smart Watering System in a more arid area where the water evaporates faster and the atmosphere is drier, what changes should we make? Describe a possible solution a

In this lesson’s project, the sensors and actuator did not require a breadboard to connect to the Arduino, in contrast with other projects. Describe the reasons why below.

Check with a tick the output of the following blocks.

4 Evaluate the following conditions of the code blocks as either True or False, by taking into consideration the values of the analog pins given: Read the sentences and tick True or False. True False 1. Soil Moisture Sensor Input AD: 180 - Temperature Sensor Input A3: 32 millog m 100 2. AO (Soil Moisture): 167- A3 (Temperature): 43 3. AO (Soil Moisture): 225-A3 (Temperature): 35 4. AO (Soil Moisture): 58 - A3 (Temperature): 41 150 5. AO (Soil Moisture): 150 - A3 (Temperature): 35 40 5 Extend the Smart Watering System to inform the user when the plant is being watered by printing the message "Watering Plant Now!" only when moisture is under 150 and temperature is over 30. Don't forget to add a newline in the message so that the monitor is intelligible. 6 Extend the Start Watering System so the DC Motor stays on for longer if the soil moisture levels are extremely low (under 50). Use wait blocks to make the DC Motor operate for anten التعليم 99

Lesson 2: Build a plant watering system

Evaluate the following conditions of the code blocks as either True or False, by taking into consideration the values of the analog pins given:

Extend the Smart Watering System to inform the user when the plant is being watered by printing the message “Watering Plant Now!” only when moisture is under 150 and temperature is over 30.

Extend the Smart Watering System so the DC Motor stays on for longer if the soil moisture levels are extremely low (under 50). Use wait blocks to make the DC Motor operate for longer.