1 Lesson 26: CPF Smart Plant What you will need CloudProfessor (CPF) Moisture Sensor Light sensor RGB LED Arduino Leonardo Android Shield Learning Expectaons (how learning / progress will be demonstrated) All Explain how weather predicons are made and the importance of data collecon. Most Create a plant monitoring system which detects the amount of water/light a plant receives. Some Create a watering device for the plant which acvates when the moisture level is too low. Learning Objecves Understand how weather predicons are made, and the importance of data collecon. Know how to collect data received from sensors. Interpret data retrieved from sensors and present the results in a meaningful way. Overview In this lesson, students will create a plant monitoring system using a moisture sensor, light sensor and RGB LCD Backlight. Curriculum Links (Compung PoS) Designs simple algorithms using loops, and selecon i.e. if statements. (AL) Uses logical reasoning to predict outcomes. (AL) Detects and corrects errors i.e. debugging, in algorithms. (AL) Creates programs that implement algorithms to achieve given goals. (AL) Understands that programming bridges the gap between algorithmic soluons and computers. (AB) Computaonal Thinking Concepts: AB = Abstracon; DE = Decomposion; AL = Algorithmic Thinking; EV = Evaluaon; GE = Generalisaon. Lesson 26 CPF Smart Plant 1 RGB LCD Backlight USB lead
12
Embed
Lesson 26 - eu-acerforeducation.acer.com · notification to launch the Arduino Leonardo APP, and select the PF Arduino lockly app. lick on Lesson 9. 4. Press the execute button to
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1 Lesson 26: CPF Smart Plant
What you will need
CloudProfessor (CPF)
Moisture Sensor
Light sensor
RGB LED
Arduino Leonardo
Android Shield
Learning Expectations (how learning / progress will be demonstrated)
All Explain how weather predictions are made and the importance of data collection.
Most Create a plant monitoring system which detects the amount of water/light a plant receives.
Some Create a watering device for the plant which activates when the moisture level is too low.
Learning Objectives
Understand how weather predictions are made, and the importance of data collection.
Know how to collect data received from sensors.
Interpret data retrieved from sensors and present the results in a meaningful way.
Overview
In this lesson, students will create a plant monitoring system using a moisture sensor, light sensor and RGB LCD Backlight.
Curriculum Links (Computing PoS)
Designs simple algorithms using loops, and selection i.e. if statements. (AL)
Uses logical reasoning to predict outcomes. (AL) Detects and corrects errors i.e. debugging, in algorithms. (AL)
Creates programs that implement algorithms to achieve given goals. (AL)
Understands that programming bridges the gap between algorithmic solutions and computers. (AB)
Computational Thinking Concepts: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation;
GE = Generalisation.
Lesson 26 CPF Smart Plant
1
RGB LCD Backlight
USB lead
2 Lesson 26: CPF Smart Plant
Step-by-step instructions
1. Connect the power of CloudProfessor then press and hold the power button for two seconds; it will turn on and the
power indicator will light up.
2. Insert the Arduino Shield into Arduino Leonardo and use the USB cable to connect the CloudProfessor with Arduino
Leonardo. Attach the moisture sensor to port A2, the light sensor to port A0 and the RGB LCD backlight to port I2C.
3. When the CloudProfessor detects the Arduino Leonardo, a notification will appear on your device; click the
notification to launch the Arduino Leonardo APP, and select the CPF Arduino Blockly app. Click on Lesson 9.
4. Press the execute button to enter the control user interface (UI). The UI can be used to adjust the speed of the fan.
5. Press the edit button to enter the program editing page.
2
CPF Arduino Blockly app
Edit button
Execute button
Control user interface (UI) Program editing page
1
2
3
3 Lesson 26: CPF Smart Plant
Let’s explore some of the code used in the previous lessons.
1. Light Get Value:
The Light Get Value block returns the value of the light sensor (Returns a numeric
value based on the brightness level of the environment).
2. White LED Set
The White LED Set block controls the attached White LED light. The led can be set
to either ‘ON’ or ‘OFF’.
3. Servo Pin# D4:
The Servo block allows the user to control the attached
servo by specifying the angle (degrees) and delay (milliseconds).
4. If / else:
The if / else block is used to conditionally run code
depending on whether a Boolean condition is true or false.
In this example, if the light sensor value is less than (<) 500,
the RGB LED light will light up; or else (else), if the light sen-
sor value is greater than or equal to 500, the RGB LED light
will automatically turn off.
5. Title Name Panel Set:
The Title Name Panel Set block displays a message on the screen. In this
example it will display a “Downloading…” message on the UI (User Interface).
6. Delay Time(Sec.):
The Delay Time(Sec.) block is used to pause the code (time set in milliseconds). In the example above, the
program is paused for 1000 milliseconds (1 second).
7. Set CPF control request:
Finally, the Set CPF control request block at the end of the program tells the program to run the code from the
beginning again. The program will continuously repeat until the user closes the app or stops the program manually.
Code recap (Blockly) 3
4 Lesson 26: CPF Smart Plant
Step-by-step instructions (Blockly) - Part 1
Let’s write the code for our smart plant.
1. Clear the existing code so that you have a blank canvas to create your new program. Click on the bin icon (1). Click
on ‘OK’ (2) to create a blank canvas.
2. Note: You can return to the original program at any time by clicking on
the restore icon (3).
3. First, let’s set the ‘Title name’. Click on CPF UI. Select the ‘Title Name Panel
Set’ block and drag it onto your code canvas. Set the title to ‘Smart Plant’.
4. Next, we need to write the condition which checks for vibration and turns the RGB LED red when vibration is
detected. For this we will use an IF statement.
a) Click on the ’Logic’ tab. Drag the ‘if do’ block and attach it to the end of
your code (4).
b) Click the cog inside your if block. Drag an ‘else’ and ‘else’ if block inside the
pop-up window (5).
c). Click on the ‘logic’ tab. Drag the ‘=‘ block and attach it to your ‘if’ block (6).
Change the ’=’ value to less than ’<’
d) Click on the ‘Sensor Modules’ tab.
Select ‘Input Devices’ and ‘Environment
Sensors’. Drag the ‘Moisture Sensor’
block onto the first slot in your logic
block (7).
e) Click on the ‘Math’ tab. Drag the ‘0’
block onto the second slot in your logic
block. Change this value to a ’100’ (8).
3
3 1 2
4
5
6
7 8
5 Lesson 26: CPF Smart Plant
Step-by-step instructions (Blockly) - Part 2
5. Let’s now display the message ‘I’m thirsty! :(’ on the RGB LCD backlight when the moisture level drops below 100.
Click on ‘Output Devices’. Select ‘Display’. Drag the ‘RGB LCD(IC2) setCursor’ block and place it inside the first
empty ‘do’ slot. Change the Print value to ’I’m thirsty! :( ’ (9).
6. Next, let’s write the condition for when the light level falls below 200 (light < 200).
a). Click on the ‘logic’ tab. Drag the ‘=‘ block and attach it to your ‘if’ block. Change the ’=’ value to less than ’<’ (10).
b) Click on the ‘CPF’ tab and select ‘CPF Devices’. Drag the ‘Light Get Value’ block onto the first slot in your logic
block (11).
c) Click on the ‘Math’ tab. Drag the ‘0’ block onto the second slot in your logic block. Change this value to a
’200’ (12).
7. Let’s now display the message ‘Its ‘too dark! :(’ on the RGB LCD backlight when the light level drops below 200. Click
on ‘Output Devices’. Select ‘Display’. Drag the ‘RGB LCD(IC2) setCursor’ block and place it inside the ‘else if do’ slot.
Change the Print value to ’It’s too dark! :( ’ (13).
3
9
10
11
12
13
6 Lesson 26: CPF Smart Plant
Step-by-step instructions (Blockly) - Part 3
8. Next, let’s write the condition which displays a message if both the moisture and light levels are acceptable.
Click on ‘Output Devices’. Select ‘Display’. Drag the ‘RGB LCD(IC2) setCursor’ block and place it inside the ‘else do’
slot. Change the Print value to a smiley face ’ :) ’ (14).
9. Finally, we want the program to run continuously until the user ends the program.
Select the ‘CPF Devices’ tab. Click and drag the ‘Set CPF control repeat block and attach it to the end of your code.
Instructions
Place the tip of the moisture sensor (A) into soil and attach the light sensor (B) to the plant pot (See figure 1).
3
Your finished code should look like this.
A B
Connect a white LED light to your plant monitoring system and program it to automatically turn on when the
there is not enough light in the room.
14
Figure 1.
7 Lesson 26: CPF Smart Plant
1. Connect the power of CloudProfessor then press and hold the power button for two seconds; it will turn on and the
power indicator will light up.
2. Insert the Arduino Shield into Arduino Leonardo and use the USB cable to connect the CloudProfessor with Arduino
Leonardo. Attach the moisture sensor to port A2, the light sensor to port A0 and the RGB LCD backlight to port I2C.
3. When the CloudProfessor detects the Arduino Leonardo, a notification will appear on your device; click the
notification to launch the Arduino Leonardo APP, and select the CPF Arduino app. Click on Socket Mode.
4. Press the execute button to enter the control user interface (UI).
5. Press the edit button to enter the program editing page.
Setup instructions (JavaScript) 2
1
2
3
CPF Arduino app
Edit button
Execute button
Control user interface (UI) Program editing page
8 Lesson 26: CPF Smart Plant
Code recap (JavaScript)
Let’s explore some of the code used in the previous lessons.
1. var value = cpf.get(“light sensor”);
The cpf.get(“light sensor”); statement returns the value taken from the light sensor and stores it in a variable called
value.
2. cpf.set(“socket d4”, 180, 20);
The cpf.set(“socket d4”, 180, 20); statement controls the attached servo. The syntax for moving the servo is
cpf.set(socket, angle, delay).
3. If / else:
The if / else statement is used to conditionally run code
depending on whether a Boolean condition is true or false.
In this example from lesson 1, if the light sensor value is less than (<) 500, the
RGB LED light will light up (based on the values taken from the UI); or else
(else), if the light sensor value is greater than (>) 500, the RGB LED light will