using single-board computer in teaching programming at ......teaching programming at junior...

147
Using Single-board Computer in Teaching Programming at Junior Secondary Level By Chu K F 26 June 2018 1

Upload: others

Post on 17-May-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Using Single-board Computer in Teaching Programming at Junior

Secondary Level

By Chu K F

26 June 2018

1

Some Questions to Consider

• Hardware and Software

– Balance between Circuit Building and Program Coding

• Choice of microcontroller

– Arduino or BBC micro:bit

• Development tool:

– Arduino IDE / Python Editor or Visual Programming

• Duration of each lesson (single / double period)

• Task-based or Project-based

• etc.

2

Arduino UNO

3

BBC micro:bit

4

BBC micro:bit

5

Learning Components

• Basic knowledge

• Guided tasks

• Self-exploration project

– Students can apply the skills they learnt in the guided tasks to complete simple project

6

Sample Projects

1. A light show with LEDs and Buzzer

2. A simple interactive game using push-buttons, LEDs and buzzer.

3. A light-control music box

4. A smart fan

7

Project 1

A Light Show with LEDs and Buzzer

8

Project Requirements • Designing a light show by using a single-board

microcontroller, LEDs and buzzer.

9

Knowledge and Skills

• Construct simple circuits by using single-board microcontroller, breadboard, LEDs, buzzers, resistors, etc.

• Create simple programs by using visual programming IDE – definite loop

– indefinite loop

– infinite loop

– selection statements

– etc.

10

Basic Knowledge

• What is Arduino?

11

Digital I/O Pins D0 to D13

USB Port

External Power Supply

Analog Input Pins A0 to A5

Ground Pin

5V Power Pin

Basic Knowledge • Breadboard (different types)

12

Basic Knowledge • Breadboard (different types)

13

Basic Skills

• Construction of Circuit (Circuit Diagram)

14

To USB port

of PC

Basic Skills

• Construction of Circuit (Photos)

15

Knowledge and Skills

• Program Coding

16

Script Area

Knowledge and Skills

• Using mBlock 3 (Basic Settings)

17

Knowledge and Skills

• Scratch mode

18

Knowledge and Skills

• Arduino mode

19

Guided Tasks

• Blinking 1 LED

20

To USB port

of PC

Guided Tasks

• Controlling three LEDs

21

To USB port

of PC

Guided Tasks

• Controlling three LEDs

– Other choices

22

Guided Tasks

• Traffic Light Simulation

23

Guided Tasks

24

Guided Tasks

25

Guided Tasks • Controlling a series of LEDs

26

Guided Tasks

• Controlling a series of LEDs

– Other choices

27

Guided Tasks

• Turning ON the LEDs One by One

• Programming Skills

– Using definite loops to simplify some repeated patterns.

– Using user-defined blocks (subprograms) to make the program more modular.

– Using variable to adjust the waiting time.

28

29

Guided Tasks

• Be careful when using Arduino mode

– Inspect the program code if necessary

– Are the output pins set properly at the start?

30

31

Guided Tasks

• Blinking the LEDs Continuously

• Blinking the LEDs Randomly

• Turning ON and OFF the LEDs in Different Directions

• Blinking the Red, Green and Yellow LEDs Randomly

• Slowing Down the Blinking Rate of LEDs

32

Guided Tasks

33

Guided Tasks

34

Guided Tasks

35

Guided Tasks

• For micro:bit, using on-board LED Screen

36

Guided Tasks • Blinking the LEDs on the Middle Row Continuously

37

Guided Tasks • micro:bit - Controlling a Series of External LEDs

38

39

Guided Tasks • Composing and Playing Music

40

41

Guided Tasks • Blinking LEDs and Playing Music Concurrently

42

Guided Tasks • Blinking LEDs and Playing Music Concurrently

– Scratch mode vs Arduino mode

43

44

45

Guided Tasks • Blinking LEDs and Playing Music Concurrently

– No problem with micro:bit

47

48

Self-Exploration Project

• Students are required to develop a Light Show by using Arduino/micro:bit and LEDs.

– with no more than 10 LEDs

– design a program that display at least four lighting patterns

– If possible, add music by using a buzzer

49

Self-Exploration Project

• System Development Life Cycle

1. Problem definition

2. Problem analysis

3. Algorithm design and Program coding

4. Program debugging/testing

5. Program documentation

50

Project 2

A Simple Interactive Game

51

Project Requirements

• Designing a simple interactive game using push-buttons, LEDs and buzzer.

52

Knowledge and Skills

• Construct simple circuits by using single-board microcontroller, breadboard, push-buttons, LEDs, buzzers, resistors, etc.

• Create simple programs by using visual programming IDE – definite loop

– indefinite loop

– infinite loop

– selection statements

– etc.

53

Basic Knowledge

• Momentary Switch

• Maintained Switch (Toggle Switch)

• Push-button

54

Basic Knowledge

• Push-button module

• No need to connect the 10 kΩ pull-down resistor

55

Basic Knowledge

• Other choice

– Touch Sensor

56

Guided Tasks • 1 Push-button & 1 LED

57

Guided Tasks

58

Guided Tasks

• Using a Push-button as a Momentary Switch

59

Guided Tasks • Using a Push-button as Toggle Switch

60

Guided Tasks • 2 Push-buttons & 1 LED

61

Guided Tasks • Using Sensor Shield with GVS pins to simplify

connection

62

Guided Task

63

Guided Tasks

• Using two Push-buttons as On and Off Switches

64

Guided Tasks

• Controlling several LEDs by a Push-button

65

Guided Task

66

Guided Tasks • Referring to the previous task, when the push

button is pressed, the LEDs will blink. When the button is released, the LEDs will stop blinking and all the LEDs will be turned off.

• Question:

Modify the program so that when the button is released, the LEDs will stop blinking and only one LED will remain on.

67

Guided Task

68

Guided Task

69

Guided Tasks

• Designing a Fast Answer Game System (搶答遊戲)

70

Self-Exploration Project

71

Guided Tasks

• Step-by-Step

1. Turn an LED on when pressing the corresponding push-button.

2. Ensure that only one LED is turned on at a time.

3. Produce suitable sound effect when pressing each button.

4. Make the program more modular

72

73

74

75

76

77

78

Guided Tasks

79

• For micro:bit

80

Self-Exploration Project

• Designing a simple interactive game using push-buttons, LEDs and buzzer.

81

Self-Exploration Project

82

Self-Exploration Project

83

Self-Exploration Project

84

85

86

micro:bit version

87

Project 3

A Light-Control Music Box

88

Project Requirements

• Design a light-control music box.

89

Knowledge and Skills

• Construct simple circuits with single-board microcontroller, potentiometer, RGB LED, light sensor (LDR) and DC motor, etc.

• Know how to handle analog input in microcontroller

• Know how to handle analog output (PWM) in microcontroller

• Create simple light sensor control systems

90

Basic Knowledge

• Analog Input

• Analog (PWM) Output

91

Basic Knowledge

• Analog Input in Arduino

92

Analog Input pins A0, A1, A2, A3, A4, A5

Digital Input / Output pins D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13

Basic Knowledge

• Analog (PWM) Output in Arduino

93

PWM Output pins D3, D5, D6, D9, D10, D11

Basic Knowledge

• Analog Input and Output in micro:bit

94

Guided Tasks • Controlling the Colour of an RGB LED

95

Common cathode

Guided Tasks • Controlling the Colour of an RGB LED

96

Guided Tasks • Controlling the Colour of an RGB LED

97

Guided Tasks • Automatic LED Control by Light Sensor (LDR)

98

Guided Tasks • Automatic LED Control by Light Sensor (LDR)

99

Guided Tasks • Control of Music Playing by Light Sensor (LDR)

100

Guided Tasks • Control of Music Playing by Light Sensor (LDR)

101

102

103

Guided Tasks • Controlling DC Motor

104

Guided Tasks • Controlling DC Motor

105

Guided Tasks • Controlling Direction of Rotation

106

Guided Tasks • Controlling Speed of Rotation

107

Self-Exploration Project

• Design a light-control music box.

108

Self-Exploration Project

• Design a light-control music box.

109

Self-Exploration Project

• Design a light-control music box.

110

Self-Exploration Project

• Design a light-control music box.

111

Self-Exploration Project

• Design a light-control music box.

112

113

114

Project 4

A Smart Fan

115

Project Requirements

• Design a smart fan

116

Guided Tasks

• Measuring Temperature by LM35

117

Guided Tasks

• Measuring Temperature by LM35

118

A0 value 5000 125 A0 value

1024 10 256T

Guided Tasks

• Measuring Temperature and Humidity by DHT11

119

Guided Tasks

• Measuring Temperature and Humidity by DHT11

120

Guided Tasks

• Measuring Temperature and Humidity by DHT11

121

Guided Tasks

• Controlling a Fan by using Temperature Sensor

122

Guided Tasks

• Controlling a Fan by using Temperature Sensor

– Other choices

123

Guided Tasks

• Controlling the On / Off of a Fan

124

Guided Tasks

• Controlling the Speed of a Fan

125

Temperature (C) Speed (%) PWM (D6)

< 25 0 0

25 - 26 40% 255 × 0.4 = 102

27 - 28 60% 255 × 0.6 = 153

29 - 30 80% 255 × 0.8 = 204

> 30 100% 255

126

Guided Tasks

• Controlling a Fan by using Temperature Sensor

127

Guided Tasks

• Controlling a Fan by using Temperature Sensor

128

Guided Tasks

• Measuring Distance by using Ultrasonic Sensor

129

Guided Tasks

• Measuring Distance by using Ultrasonic Sensor

130

Guided Tasks

• Measuring Distance by using Ultrasonic Sensor

131

Guided Tasks

• Measuring Distance by using Ultrasonic Sensor

132

Guided Tasks

• Controlling Servo Motor

133

Guided Tasks

• Controlling Servo Motor

134

to PWM pin

to 5V pin

to GND pin

Guided Tasks

• Servo Motor with Ultrasonic Sensor

135

Guided Tasks

• Detecting the Nearest Obstacle to the Sensor

136

Guided Tasks

• Detecting the Nearest Obstacle to the Sensor

137

138

Self-Exploration Project

• Design a smart fan

139

Self-Exploration Project

• Design a smart fan

140

Self-Exploration Project

• Design a smart fan

141

Self-Exploration Project

• Design a smart fan

142

Self-Exploration Project

• Design a smart fan

143

Self-Exploration Project

• Design a smart fan

144

Self-Exploration Project

• Further example

– https://www.youtube.com/watch?time_continue=79&v=nhLk_kOy6w8

145

Reference

• Arduino輕鬆入門 : 範例分析與實作設計 / 葉難,博碩文化股份有限公司

• Beginning Arduino by Michael McRoberts

• 用mBlock玩Arduino - Starting from Scratch:林信良

• etc.

146

~ END ~

Thank You!

147