Lesson 3 - eu-acerforeducation.acer.com · 2 Lesson 3: Smart Fan Step-by-step instructions 1....

5
1 Lesson 3: Smart Fan What you will need CloudProfessor (CPF) Temperature sensor Fan motor Arduino Leonardo Arduino Shield USB cable Learning Expectaons (how learning / progress will be demonstrated) All Use sequences of instrucons. Most Explain how their app works. Some Use logical reasoning to detect errors in their algorithms. Learning Objecves Design and create an app which uses sequence, selecon, repeon and variables. Program, debug and refine the code for their app. Detect and correct errors in their app. Overview In this lesson, students will explore the basics of wring algorithms using the Blockly editor. Students will explore exisng code and use what they learnt to create a smart fan which is controlled by a temperature sensor. 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 3 Smart Fan (Ramen cooler) 1

Transcript of Lesson 3 - eu-acerforeducation.acer.com · 2 Lesson 3: Smart Fan Step-by-step instructions 1....

Page 1: Lesson 3 - eu-acerforeducation.acer.com · 2 Lesson 3: Smart Fan Step-by-step instructions 1. onnect the power of loudProfessor then press and hold the power button for two seconds;

1 Lesson 3: Smart Fan

What you will need

• CloudProfessor (CPF)

• Temperature sensor

• Fan motor

• Arduino Leonardo

• Arduino Shield

• USB cable

Learning Expectations (how learning / progress will be demonstrated)

All Use sequences of instructions.

Most Explain how their app works.

Some Use logical reasoning to detect errors in their algorithms.

Learning Objectives

Design and create an app which uses sequence, selection, repetition and variables.

Program, debug and refine the code for their app.

Detect and correct errors in their app.

Overview

In this lesson, students will explore the basics of writing algorithms using the Blockly editor. Students will explore existing

code and use what they learnt to create a smart fan which is controlled by a temperature sensor.

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 3 Smart Fan (Ramen cooler)

1

Page 2: Lesson 3 - eu-acerforeducation.acer.com · 2 Lesson 3: Smart Fan Step-by-step instructions 1. onnect the power of loudProfessor then press and hold the power button for two seconds;

2 Lesson 3: Smart Fan

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 Temperature Sensor to port A1 and the Fan motor to port D3.

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 then select the CPF Arduino Blockly app. Click on Lesson 3.

4. Press the execute button to enter the control user interface (UI).

5. Press the edit button to enter the program editing page.

2

1

2

3

CPF Arduino Blockly app

Edit button

Execute button

Control user interface (UI) Program editing page

Page 3: Lesson 3 - eu-acerforeducation.acer.com · 2 Lesson 3: Smart Fan Step-by-step instructions 1. onnect the power of loudProfessor then press and hold the power button for two seconds;

3 Lesson 3: Smart Fan

Exploring the code (Blockly)

Let’s explore the code.

1. Temperature Get Temp.:

The Temperature Get Temp. block returns the reading taken from the tempera-

ture sensor in degrees Celsius.

2. Fan Control Set Speed:

The Fan Control Set Speed block sets the speed of the Fan.

3. 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, the speed of the fan motor is determined by the reading taken from the temperature sensor.

A. When the measured temperature is less than or equal to 28

degrees Celsius (the if() formula is true), then set the rotation

speed of the fan to 0.

B. When the measured temperature is between 29 and 31 degrees Celsius, set the rotation speed of the fan to 60.

C. When the measured temperature is between 31 and 35 degrees Celsius, set the rotation speed of the fan to 130.

D. When the measured temperature is greater than 35 degrees

Celsius, set the rotation speed of the fan to 255.

4. 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.

3

Experiment with different fan speeds and temperature intervals to find the best setup for your environment.

Fan speed

A

B

C

D

Page 4: Lesson 3 - eu-acerforeducation.acer.com · 2 Lesson 3: Smart Fan Step-by-step instructions 1. onnect the power of loudProfessor then press and hold the power button for two seconds;

4 Lesson 3: Smart Fan

Exploring the code (JavaScript)

Let’s explore the code.

1. var value = cpf.get(“temperature sensor”);

var value = cpf.get(“temperature sensor”); returns the reading taken from

the temperature sensor and stores the result in a variable called value.

var celsius = toCelsius(value); converts the value taken from the

temperature sensor to degrees Celsius (See function ’toCelsius’ below).

ui.set(“temperature sensor”, celsius); displays the temperature reading (in degrees Celsius) in the program UI.

2. cpf.set(“fan”, speed);

cpf.set(“fan”, speed); sets the speed of the Fan. The speed of the fan can be set

manually (2) or controlled by the program UI (1).

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, the speed of the fan motor is determined by the reading taken from the temperature sensor.

A. When the measured temperature is less than 28 degrees

Celsius (the if() formula is true), then set the rotation speed of the

fan to 0.

B. When the measured temperature is between 28 and 31

degrees Celsius, set the rotation speed of the fan to 60.

C. When the measured

temperature is between 31 and 35 degrees Celsius, set

the rotation speed of the fan to 130.

D. When the measured temperature is greater than 35 degrees Celsius,

set the rotation speed of the fan to 255.

4. function toCelsius(value) {

The value returned by the temperature sensor is not in

Celsius. The function ’toCelsius’ reads the value taken

from the temperature sensor and converts it into

degrees Celsius.

3

Experiment with different fan speeds and temperature intervals to find the best setup for your environment.

A

B

C

D

1

2

Page 5: Lesson 3 - eu-acerforeducation.acer.com · 2 Lesson 3: Smart Fan Step-by-step instructions 1. onnect the power of loudProfessor then press and hold the power button for two seconds;

5 Lesson 3: Smart Fan

Extension

Students to take a screenshot of their code and add comments to explain how it works.

Differentiation

To support students, provide step by step guides.

To stretch students ask them to create a flowchart / pseudocode of their code first or code their solution using JavaScript.

Homework

Students to write up a summary of what they’ve learned; students to include screenshots and snippets of their code in

their summary.

Students to explore how Internet-linked smart thermostats work such as Nest and Hive.

Links

How thermostats work: http://www.explainthatstuff.com/thermostats.html

Hive Active heating: https://www.hivehome.com/products/hive-active-heating

Nest vs Hive—Which is the best smart thermostat? http://www.trustedreviews.com/opinions/nest-vs-hive

Disclaimer: Use these sites at your own risk. Acer is not responsible for the content of external Internet sites. We

recommend that you check the suitability of any recommended websites links before giving them to students.

4

5

6

7