# Night Sensor Lesson 2

This lesson focussed on the key concepts of decomposition and algorithms (pseudocode and flowcharts) as students begin to build their ‘Night Sensor’ example - a wearable device that will give an audio and visual reminder to a child to ‘be safe, be seen’ at nightfall.

• 年龄 9+
• 60 分钟
• MakeCode Editor

## 课程环节：

• Computing: Algorithms (pseudocode & flowcharts), decomposition, logical thinking, debugging
• Science: Day and Night / Sensors
• 设计和技术：产品设计

Skills: Designing, analysing, problem solving, team working.

## 背景知识

It is assumed that you have first completed Lesson 1 of the Night Sensor activity.

## 介绍

This lesson focussed on the key concepts of decomposition and algorithms (pseudocode and flowcharts) as students begin to build their ‘Night Sensor’ example - a wearable device that will give an audio and visual reminder to a child to ‘be safe, be seen’ at nightfall.

## 活动

Algorithm design

• Show students the goal/problem again (slide 6) and depending on students’ experience either as a class or in pairs write a basic, broad algorithm to solve the problem (example on slide 7). Ask questions to test understanding and encourage discussion such as:
• will this be detailed enough for someone to code?
• what would we need to do to make it detailed enough?
• which parts are ambiguous and how would we address that?
• Highlight they have just decomposed the problem into smaller parts and explain they will now design more detailed, accurate algorithms for each part using pseudocode (slide 8).

Team algorithms

• Split the class into their teams and give out the algorithm worksheets (ideally on A3 paper)
• Explain you want them to write a detailed algorithm using pseudocode that someone could follow accurately to write the code for the Night Sensor. They may wish to split the team down to write different sections on rough paper before putting it all together. An simple example is given on slide 9 and a more advanced including a start and stop button and on and off sounds on slide 10
• Depending on previous experience, you may need to spend time going through input and output devices (slide 11) and iteration, loops and selection (slide 12).

Testing and refining algorithms

• 每两个团队为一组，同组的团队交换算法， 然后测试对方团队的算法并提供反馈意见。如有必要，可进行比较和调试。
• Come up with a final algorithm as a class, ensuring an appropriate level of detail and accuracy according to your students’ experience and ability and addressing any misconceptions.

Flowcharts

• 邀请学生就“为什么算法流程图可以与伪代码一起使用或是代替伪代码（图式算法可以更容易让人看懂和注意到关键点）”这个话题分享他们的看法。
• Remind students if needed of the standard flowchart symbols (slide 13) and give each team a large sheet of paper and coloured pens. Ask them to create a flowchart for the algorithm and then share, test and debug as necessary as a class (example on slide 14 for the basic algorithm).

Lesson wrap up

• Explain next lesson they will use their algorithms to code the Night Sensor next lesson.
• Ask students a variety of questions to test their understanding (suggestions on slide 15).
• If you wish, use the learning objectives to check progress and understanding (slide 16).

Extension / homework

• 如果有扩展练习或相关家庭作业，学生可以将这些添加到他们的学习日志和/或这个主题的工作墙上。
• 学生可以编写伪代码或算法流程图来解决他们遇到的其他日常问题（例如起床、做作业、决定要观看的电影、喂养宠物等）。

### Differentiation

Support:

• Consider groupings carefully to ensure all students are able to participate
• 鼓励学生编写一个清晰且简单的算法，并帮他们把基本算法制成打印和剪切版，以便按顺序排列。

Stretch & challenge:

Students can be challenged to include additional detail and elements in their algorithms. For example, can they include the stop/start button and audio sounds straight away in their algorithm and flowchart?

Opportunities for assessment:

• Informal assessment of team algorithms (pseudocode and flowcharts) and use questioning to assess understanding and progress throughout and in lesson wrap up.