97.9k views
1 vote
For this option you must design a security system. Your microbit will be your hub that displays information when a sensor (can be shake sensor, buttons, temperature, light, etc.) detects trouble. Your microbit will also serve as your security sensors. You must devise a way to detect trouble with at least two separate sensors on a single microbit. You can describe how you propose to do this with comments in your code. Make sure your microbit can reset an alarm if it has tripped and that it also knows which sensor is being triggered.

1 Answer

5 votes

Final answer:

Design a security system using a microbit by programming it to utilize its built-in sensors, such as the accelerometer for detecting shakes and the light sensor for detecting light levels. Include code to reset the alarm and display which sensor was triggered.

Step-by-step explanation:

Designing a Microbit Security System

To design a security system using a microbit as a hub, you will need to program it to interact with onboard sensors such as the accelerometer (shake sensor) and light sensor. The accelerometer can detect movement which may signify an intrusion, while the light sensor can detect changes in light intensity which could also indicate someone entering a room.

Here's a simple example of how this might be coded:

from microbit import *

# Define variables to keep track of which sensor was triggered last
last_triggered_sensor = None

# Function to update the display
def update_display(sensor_name):
display.clear()
display.scroll(sensor_name)

while True:
# Checking for accelerometer shake
if accelerometer.was_gesture('shake'):
last_triggered_sensor = 'SHAKE'
update_display(last_triggered_sensor)

# Checking the light level
light_level = display.read_light_level()
if light_level > threshold:
last_triggered_sensor = 'LIGHT'
update_display(last_triggered_sensor)

# Button A to reset the alarm
if button_a.is_pressed():
last_triggered_sensor = None
update_display('RESET')

You would need to set a threshold value for the light intensity that, when exceeded, triggers the alarm. The 'RESET' message appears when the alarm is reset using Button A on the microbit.

User Bhavin Ramani
by
7.9k points