← 返回资讯屏轩教育 · 行业资讯

Case Study Practicum: Smart School Locker System | 案例分析实战演练:智能校园储物柜系统

2026-07-18 12:44 · 本文部分内容由AI辅助创作

📚 Case Study Practicum: Smart School Locker System | 案例分析实战演练:智能校园储物柜系统

In this case study, we will apply the core concepts of OCR Year 9 Computer Science to design a 'Smart School Locker System'. This system allows students to unlock their assigned lockers using a PIN code or an RFID card, keeps an access log, and alerts staff if a locker is forced open. We will walk through computational thinking, data representation, algorithm design, and security considerations step by step. By working through this realistic scenario, you will see how abstract classroom topics come together to solve a genuine problem in a school environment.

在这个案例研究中,我们将运用 OCR 九年级计算机科学的核心概念,设计一个“智能校园储物柜系统”。该系统允许学生使用 PIN 码或 RFID 卡解锁分配给自己的储物柜,保留访问日志,并在储物柜被强行打开时向教职工发出警报。我们将一步步走过计算思维、数据表示、算法设计以及安全考量。通过这个贴近现实的场景,你会看到抽象的课堂知识是如何整合在一起,来解决校园环境中的真实问题的。


1. Understanding the Problem: Requirements Gathering | 理解问题:需求收集

The first phase of any computing project is to clearly define the problem. For our smart locker system, we need to talk to the stakeholders: students, teachers, and the school administration. Students want a fast, reliable way to access lockers during breaks. Teachers need to know if a locker is being misused. The administration requires a system that is cost-effective, maintainable, and compliant with data protection laws. The key functional requirements are: (a) each locker can be unlocked via a 4‑digit PIN or a school‑issued RFID card; (b) the system must log every open and close event with a timestamp and student ID; (c) if a locker door is opened without authorisation, a buzzer sounds and a notification is sent to the office; (d) an administrator can view today's log and revoke a student's access remotely.

任何计算项目的第一阶段都是清晰地定义问题。对于我们的智能储物柜系统,我们需要与利益相关方沟通:学生、老师和学校管理层。学生希望课间能够快速可靠地打开储物柜。老师需要知道储物柜是否被不当使用。校方管理层则要求系统成本效益高、便于维护,并且符合数据保护法规。关键的功能需求有:(a) 每个储物柜可以通过 4 位 PIN 码或学校发放的 RFID 卡解锁;(b) 系统必须记录每一次开柜和关柜事件,包括时间戳和学生 ID;(c) 如果柜门被未经授权地打开,蜂鸣器会响起,并向办公室发送通知;(d) 管理员可以查看当天的日志,并远程撤销某个学生的访问权限。


2. Decomposition: Breaking Down the System | 分解:拆分系统

Decomposition means breaking a complex problem into smaller, manageable parts. We can decompose the smart locker system into several sub‑systems: Input Module (keypad and RFID reader), Processing Unit (a microcontroller like a Raspberry Pi Pico or Arduino), Output Module (solenoid lock, LED indicators, buzzer), Data Logging (local SD card or cloud database), and a Communication Module (Wi‑Fi to send alerts). Each sub‑system can be developed and tested independently. For instance, the keypad input can be tested by simply printing the entered digits to a serial monitor before it ever unlocks a lock. This modular approach makes the project less overwhelming and easier to debug.

分解是指将一个复杂问题拆分成更小、更易于管理的部分。我们可以将智能储物柜系统分解为几个子系统:输入模块(键盘和 RFID 阅读器)、处理单元(如 Raspberry Pi Pico 或 Arduino 微控制器)、输出模块(电磁锁、LED 指示灯、蜂鸣器)、数据记录(本地 SD 卡或云端数据库),以及通信模块(用于发送警报的 Wi‑Fi)。每个子系统都可以独立开发和测试。例如,键盘输入部分可以先只将输入的各位数字打印到串口监视器上,在真正用于开柜之前就完成测试。这种模块化的方法让项目不那么令人望而生畏,也更容易调试。


3. Pattern Recognition: Spotting Similarities | 模式识别:发现相似性

Pattern recognition involves looking for similarities among problems or within data. When designing the locker system, we recognise that many other access‑control systems work in a similar way: hotel room key cards, gym lockers, and even smartphone screen locks. They all rely on ‘something you know’ (PIN) or ‘something you have’ (card). We also see a repeating pattern in the access log: every entry has an event type (open/close), a student ID, and a time. By generalising these patterns, we can reuse well‑known solutions, such as a simple database schema with fields: LogID, StudentID, LockerNumber, EventType, Timestamp. Recognising that a brute‑force attack (trying many PINs quickly) is a common threat pattern helps us design a lockout mechanism: after three wrong attempts, the keypad is disabled for 30 seconds.

模式识别涉及在问题之间或数据内部寻找相似之处。在设计储物柜系统时,我们识别出许多其他门禁系统都以类似的方式工作:酒店房卡、健身房储物柜,甚至是智能手机的屏幕锁。它们都依赖于“你知道的东西”(PIN 码)或“你拥有的东西”(卡片)。我们在访问日志中也发现了重复的模式:每条记录都有一个事件类型(开/关)、一个学生 ID 和一个时间。通过归纳这些模式,我们可以复用那些众所周知的解决方案,比如一个简单的数据库模式,包含字段:LogID, StudentID, LockerNumber, EventType, Timestamp。识别出暴力破解攻击(快速尝试多个 PIN 码)是一种常见的威胁模式,有助于我们设计出锁定机制:在三次错误尝试后,键盘将被禁用 30 秒。


4. Abstraction: Filtering Out Unnecessary Details | 抽象:滤除不必要细节

Abstraction is about focusing on the essential features and ignoring irrelevant details. When we model a student in the locker system, we don't need their home address or maths grades; we only need a unique StudentID, their assigned locker number, their PIN hash, and their RFID card serial number. Similarly, we can abstract the locking mechanism: from the software perspective, it doesn't matter whether the lock is a solenoid or a motor; we only need a function like unlock_locker(locker_id) that sends a digital HIGH signal for three seconds. This allows the hardware team to change the lock type later without rewriting the entire program. Abstraction also helps us design a clean user interface: the LCD screen only shows essential prompts like “Enter PIN:” and “Access Granted”, hiding the complex processes running underneath.

抽象是指聚焦于关键特性,而忽略无关的细节。当我们在储物柜系统中为一个学生建模时,我们不需要他们的家庭住址或数学成绩;我们只需要一个唯一的 StudentID、他们分配的柜号、PIN 码的哈希值,以及 RFID 卡的序列号。同样,我们可以对锁定机构进行抽象:从软件角度看,锁是电磁式的还是电机式的并不重要;我们只需要一个类似 unlock_locker(locker_id) 的函数,该函数会发送一个持续三秒的数字高电平信号。这使得硬件团队可以在日后更换锁的类型,而无需重写整个程序。抽象还帮助我们设计出简洁的用户界面:LCD 屏幕只显示诸如“输入 PIN 码:”和“已授权”之类的必要提示,而将运行在底层的复杂过程隐藏起来。


5. Algorithm Design: The PIN Unlock Flowchart | 算法设计:PIN 码解锁流程图

An algorithm is a step‑by‑step procedure to solve a problem. We can design the PIN unlock algorithm using a flowchart. The process starts when a student presses the “Start” button. The system displays “Enter PIN:” and waits for four digits. Once entered, the microcontroller hashes the input and compares it with the stored hash for that locker. If they match, the lock opens and “Access Granted” is shown; the event is logged. If they don't match, an attempt counter increases. When the counter reaches three, the system activates a 30‑second lockdown and alerts the office. This algorithm can be implemented in Python on a Raspberry Pi Pico, using a simple while loop and an if‑else structure.

算法是解决某个问题的一步一步的过程。我们可以用流程图来设计 PIN 码解锁算法。过程始于一名学生按下“开始”按钮。系统显示“输入 PIN 码:”并等待四位数字。输入后,微控制器对输入内容进行哈希运算,并将其与为该柜存储的哈希值进行比较。如果匹配,锁打开,并显示“已授权”;该事件被记录。如果不匹配,尝试计数器加一。当计数器达到三次时,系统启动 30 秒的锁定状态,并向办公室发出警报。这个算法可以在 Raspberry Pi Pico 上用 Python 实现,只需使用一个 while 循环和 if‑else 结构。

The following table outlines the steps in pseudocode, which is a way of describing an algorithm without worrying about exact syntax:

下表以伪代码的形式概述了这些步骤,伪代码是一种无需纠结精确语法即可描述算法的方式:

StepPseudocode伪代码
1SET attempt = 0设定 attempt = 0
2WHILE attempt < 3当 attempt < 3 时
3    GET user_input    获取 user_input
4    IF hash(user_input) == stored_hash THEN    如果 hash(user_input) == stored_hash 则
5        UNLOCK locker; LOG "open"; BREAK        解锁储物柜;记录“open”;跳出循环
6    ELSE    否则
7        attempt = attempt + 1; SHOW "Try again"        attempt = attempt + 1;显示“再试一次”
8END WHILE结束循环
9IF attempt == 3 THEN SOUND buzzer; ALERT office如果 attempt == 3 则 鸣响蜂鸣器;向办公室发警报

广告 / Sponsored

6. Data Representation: Storing Student IDs in Binary | 数据表示:用二进制存储学生 ID

Computers store all data in binary (1s and 0s). In our system, each student is assigned a unique 8‑bit StudentID. For example, student number 27 is represented as 00011011 its, often 32 bits long. When the system compares a scanned card to the stored list, it performs a bit‑by‑ 256 students x 8 bits = 2048 bits, or 256 bytes, which easily fits in the microcontroller's memory. We also use binary logic to set control registers: for instance, writing 00000001 to port B might turn on LED 0, while 00000010 turns on LED 1.

计算机将所有数据以二进制(1 和 0)的形式存储。在我们的系统中,每个学生都会被分配一个唯一的 8 位 StudentID。例如,学号 27 在二进制中表示为 00011011。我们选择 8 位是因为它允许有 2⁸ = 256 个唯一的 ID,这对一所小型学校来说足够了。RFID 卡序列号也是一串比特流,通常为 32 位长。当系统将扫描到的卡片与存储列表比较时,它会执行逐比特比较。理解二进制有助于我们计算所需的存储空间:256 个学生 × 8 位 = 2048 位,即 256 字节,这可以轻松放入微控制器的内存中。我们还用二进制逻辑来设置控制寄存器:例如,向端口 B 写入 00000001 可能点亮 LED 0,而写入 00000010 则点亮 LED 1。


7. Hardware and Software Components | 硬件与软件组件

A system like this combines both hardware and software. The hardware includes: a microcontroller (e.g., Arduino Uno), a 4x4 matrix keypad, an MFRC522 RFID reader, a 12V solenoid lock with a relay module, a 16x2 LCD character display, red and green LEDs, a buzzer, and a Wi‑Fi module (ESP8266). The software is written in C++ or MicroPython. It must include libraries for the keypad, RFID, LCD, and Wi‑Fi. The main program loop constantly checks for input: if a card is presented, read the UID; if a key is pressed, build the PIN string. The software also implements non‑blocking delays using the millis() function to handle the 30‑second lockout without freezing the entire system. The interaction between hardware and software is crucial: a bug in the debounce logic for the keypad could cause a single press to be read as multiple digits, leading to false lockouts.

像这样的系统结合了硬件和软件。硬件包括:一个微控制器(如 Arduino Uno)、一个 4x4 矩阵键盘、一个 MFRC522 RFID 阅读器、一个搭配继电器模块的 12V 电磁锁、一个 16x2 字符型 LCD 显示屏、红色和绿色 LED、一个蜂鸣器,以及一个 Wi‑Fi 模块(ESP8266)。软件用 C++ 或 MicroPython 编写。它必须包含用于键盘、RFID、LCD 和 Wi‑Fi 的库。主程序循环不断检查输入:如果有卡片靠近,就读出其 UID;如果有按键按下,就构建 PIN 字符串。软件还使用 millis() 函数实现非阻塞延时,以处理 30 秒锁定状态,同时又不会让整个系统冻结。硬件和软件之间的交互至关重要:键盘去抖动逻辑中的一个小 bug 就可能导致一次按键被读成多个数字,从而引发误锁。


8. Cybersecurity and Data Protection | 网络安全与数据保护

No school system can ignore security. Our smart locker system must protect student data and prevent unauthorised access. First, PINs are never stored as plain text; we store only a cryptographic hash (like SHA‑256) so that even if the database is stolen, the PINs cannot be recovered. Second, communication between the locker and the office must be encrypted, using WPA2 for Wi‑Fi and TLS for data messages. Third, we implement a physical tamper switch on each locker door; if the circuit is broken before a legitimate unlock, the alarm triggers instantly. We also need to comply with GDPR principles: log data must be deleted after 30 days, students must be told what data is collected, and access to the log must be restricted to authorised staff only. A simple role‑based access control (RBAC) ensures that a teacher can only view logs but not change PINs, while an admin can do both.

任何学校系统都不能忽视安全。我们的智能储物柜系统必须保护学生数据,并防止未经授权的访问。首先,PIN 码绝不以纯文本的形式存储;我们只存储一个加密哈希值(如 SHA‑256),这样即使数据库被盗,PIN 码也无法被恢复。其次,储物柜与办公室之间的通信必须加密,Wi‑Fi 使用 WPA2,数据消息使用 TLS。第三,我们在每个柜门上安装物理防拆开关;如果电路在合法开锁之前就被断开,警报会立刻触发。我们还需要遵守 GDPR 原则:日志数据必须在 30 天后删除,必须告知学生哪些数据会被收集,日志的访问权限必须仅限于被授权的教职工。一个简单的基于角色的访问控制(RBAC)能够确保老师只能查看日志而不能更改 PIN 码,而管理员则可以两者都做。


9. Testing and Evaluation | 测试与评估

Thorough testing is essential. We need to design test plans for each module. For the PIN entry module, we test normal cases (correct PIN unlocks immediately), boundary cases (three wrong attempts triggers lockdown), and erroneous cases (pressing non‑numeric keys should be ignored). We also perform integration testing: when the RFID reader fails, does the system fall back to PIN entry smoothly? A stress test simulates a high‑load scenario, such as 30 students trying to access lockers during a 5‑minute break; the log must not miss any entry. Usability testing involves real students and teachers using a prototype. We collect feedback: the LCD text is too small, the buzzer is too loud, the lock does not engage if the door is slightly misaligned. Evaluation against the original requirements shows that the system meets all functional goals, but we might identify future improvements like adding a fingerprint sensor or a mobile app.

全面的测试必不可少。我们需要为每个模块设计测试计划。对于 PIN 输入模块,我们测试正常情况(正确 PIN 码立即解锁),边界情况(三次错误尝试触发锁定),以及错误情况(按下非数字键应被忽略)。我们还要进行集成测试:当 RFID 阅读器故障时,系统能否顺利降级为 PIN 输入?压力测试模拟高负载场景,比如在 5 分钟课间休息内,有 30 名学生试图使用储物柜;日志必须一条不漏。可用性测试邀请真实的学生和老师使用原型机。我们收集反馈:LCD 字体太小,蜂鸣器声音太响,如果柜门稍有错位,锁就扣不上。对照最初的需求进行评估,表明系统达到了所有功能目标,但我们可能会提出未来的改进方向,比如增加指纹传感器或配套的手机应用。


10. Conclusion and Real‑World Connections | 总结与现实世界联系

This case study has demonstrated how the theoretical concepts of Year 9 OCR Computer Science—computational thinking, binary logic, algorithm design, and cybersecurity—directly apply to a tangible engineering project. The smart locker system is not just an academic exercise; similar principles are used in airport baggage systems, automated warehouse picking, and smart home door locks. By working through decomposition, pattern recognition, abstraction, and algorithm creation, you have practiced the same skills that professional software engineers and system architects use every day. Remember, every complex system is built from simple, well‑tested components, and the ability to think computationally will help you no matter which field of technology you pursue.

本案例研究展示了 OCR 九年级计算机科学中的理论概念——计算思维、二进制逻辑、算法设计和网络安全——如何直接应用于一个有形的工程项目。智能储物柜系统不仅仅是一个学术练习;类似的原理被用于机场行李系统、自动化仓库分拣以及智能家居门锁中。通过亲历分解、模式识别、抽象和算法创建的过程,你已经练习了专业软件工程师和系统架构师每天都会使用的技能。请记住,每个复杂的系统都是由简单、经过良好测试的组件构建而成的,而无论你将来进入哪个技术领域,计算思维的能力都会让你受益无穷。

Published by TutorHao | Computer Science Revision Series | aleveler.com

广告 / Sponsored
Linux高级程序设计(高等院校计算机技术十二五规划教材)/刘加海/季江民/浙江大学出版社
计算机 备考教辅 · 正版现货 · 与本文内容相关
查看详情 / View on Taobao参考价 ¥55.6

更多咨询请联系16621398022(同微信)

备考资讯每日更新,关注不错过
考纲变化 · 科目分析 · 学习方法
扫码关注公众号 tutorhao
在微信里长按二维码识别关注
或截图后用「扫一扫 → 相册」选择本图
公众号:tutorhao