Outline
Make a simple anti-theft alarm system, controlling the system to start with a touch button.
Suitable kits: mCookie302, IBC
Module Bill
Module
Other Equipment
- USB cable*1
- Sensor cable*3
- Lego shell
- Lego or other fixation structure
Module Setup
==
- Assemble the modules and sensors:
- Stick the red core module, battery base and green extension module;
- Connect the touch button to pin 2/3 of Hub;
- Connect the color LED to pin 8/9 of Hub;
- Connect the PIR sensor to pin 10/11 of Hub;
- Plug one end of USB cable into the battery base, and connect the other to computer;
Programming
Required Program Blocks
Programming Thought
- Declare a variable “on” to store the state of the switch. You can set open an close two states of the switch with touch button 2.
- on=0 represents open;
- on=1 represents close at night. If there is someone rushing into the museum, the value of on will change into 2;
- on=2 represents there is someone rushing into the museum, and it is on alarm state, the LED will flash red to alarm.
Programming
1. Color LED prepares, and declare variables.
ColorLED prepare. Declare a variable named on to record the working mode.
2. Press the touch button 2 to change the state of the switch.
If the power button is pressed, it will execute the internal program. If on is 1 (it is on the closed state at night), set on to 0 (open in the daytime). Otherwise (on open or alarm state), set on to 1 (close at night). Wait for the power button to be released.
3. If on=0, open in the daytime, and the color LED will change into green.
If on is equivalent to 0(open in the daytime), activate the color LED in green.
4. If on=1, closed at night, the color LED will change into red.
If on is 1(closed at night), judge whether the PIR sensor of pin 10 has detected the movement of people, it it has, set on to 2 (change from closed state to alarm state), otherwise the color LED will light red (it is safe currently, and keep alarm).
5. If on=2, someone has rushed into the house, flash and alarm and then close.
If on is equivalent to 2(alarm), set the color LED to red and flash (alarm).
Test the result
After upload, it is on open state by default, and the color LED will light green; press the touch button 2, switch it to closed state, and the color LED will light red. At this time, wave in front of the PIR sensor (it will detect the movement of people), and you will see the color LED flash red to alarm.
Q: When it alarms, only the color LED flashes red, which is not obvious enough, an alarm bell is supposed to be added, which will better!
A: You just need to add a buzzer.
- When someone rushes into the museum, the alarm lamp will flash, and the alarm bell will alarm at the same time.
- on=0, the color LED lights green, and it is on open state.
- on=1, if the PIR sensor has detected the movement of people, on=2, and it will enter the alarm state.
- on=2, the color LED lights red, and the buzzer alarms.
Technical Specification
Related Cases
FAQ
|