Learning objectives
- Connect CyberPi and mBuild modules, and program them with block coding in mBlock.
- Use sensor input and conditional logic to control lights, a fan, a servo lock and an alarm.
- Combine the separate subsystems into one working smart home system.
Lesson plan
Basic programming and assembly (light control) | Identify the parts of the CyberPi board and power base and the areas of the mBlock editor | Hands-on: i) Connect CyberPi to mBlock through the Serial connection ii) Wire CyberPi to the LED Driver and LED strip using 4-pin and 3-pin cables iii) Add the LED Driver extension, build a first block program and upload it to the device iv) Change the colour and the number of lit LEDs, and use event blocks to switch the strip on and off with a button
Smart fan system | Understand PIR human-motion sensing and how the IF conditional block selects between actions | Hands-on: i) Wire the PIR sensor and display a message on the CyberPi screen when movement is detected ii) Wire the motor driver, fan motor and fan, and start and stop the fan with buttons A and B iii) Combine the two programs so that the fan runs while movement is detected and stops when it is no longer detected iv) Extend the program so the buttons adjust fan speed
Door access system (smart handle / smart door lock) | Understand the analogue output of the angle sensor and the fixed-angle positioning of a servo motor | Hands-on: i) Add the Angle Sensor extension and show the rotation angle on the screen ii) Use if...else with a comparison operator to display "Door is unlocked!" or "Door is locked!" at a chosen angle iii) Wire the servo driver and servo motor, and turn the servo to 90 degrees to unlock and back to the zero position to lock iv) Use a variable to require a sequence of correct angles, as in a safe
Smart burglar alarm system | Understand ultrasonic and time-of-flight distance measurement and the use of a distance threshold as an alarm trigger | Hands-on: i) Add the Ranging Sensor extension and display the measured distance on the screen in a loop ii) Use if...else to display "Alarm!" when an object comes within the set threshold, 20 cm in the example iii) Add the speaker module and sound an alarm tone when the threshold is crossed iv) Add the LED strip and make it flash red in rhythm with the alarm
Integration project: build a smart home system | Combine the lighting, fan, door and alarm subsystems into one program | Hands-on: Select and build one or more scenarios with the blocks learnt in the course: i) Intrusion detection with a flashing red RGB LED ring and a high-volume speaker alarm ii) Distance-triggered cooling with multi-stage fan speed and automatic shut-off when the user leaves iii) Angle-sensor door handle with servo unlock and gradual night lighting iv) Additional scenarios such as welcome lighting at the door, a sleep mode with dim warm light and a low-speed fan, or an air-circulation reminder triggered by time spent in the room
Prerequisites
Hardware
- CyberPi x 1
- CyberPi power base (battery module with M1/M2 motor ports and S1/S2 sensor ports)
- 4-pin mBuild connecting cable x 2
- 3-pin connecting cable x 1
- 2-pin connecting cable x 1
- LED Driver x 1 and LED strip x 1
- RGB LED ring x 1 (integration project)
- PIR human-motion sensor x 1
- DC Motor Driver x 1
- Fan motor x 1 and fan blade x 1
- Servo Driver x 1 and servo motor x 1
- Angle Sensor x 1
- Ranging Sensor x 1
- Speaker x 1
Software
- mBlock (ide.mblock.cc)
- Up-to-date Chrome browser (Computer)
Other requirements