zt07elecfreaks 发表于 2018-1-16 17:48:02

Make A Burglar Alarm Device with Micro:bit

This article comes from: https://tinkercademy.com/tutorials/simple-alarm-machine/ .
In this project, we are going to create a simple alarm device which will alert the owner if someone has stolen his or her property. The red LED will blink when the crash sensor detects that the object has been taken away. Otherwise, the green LED will light up continuously. The OLED will display the status of the device.


Materials:



1 x BBC micro:bit

1 x Micro USB cable

1 x Breakout board

1 x Octopus LED

1 x Crash Sensor

1 x OLED

1 x LED

2 x Female-Female jumper wires



Goals:


Get to know the Octopus LED, normal LED, Crash sensor and OLED.

Make something with different types of LED

Make something with Crash sensor and OLED


Step 1 – Components

https://www.elecfreaks.com/wp-content/uploads/2017/08/1-3.jpgConnectLED module to pin 1.
https://www.elecfreaks.com/wp-content/uploads/2017/08/2-3.jpg
https://www.elecfreaks.com/wp-content/uploads/2017/08/3-5.jpgConnect the USB cable to the micro:bit and then to the breakout board as shown in the picture above. Making sure that the colour of the wire follows the colour of the pins on the break out board, plug in the crash sensor to Pin 0 and the Octopus LED to Pin 8. Lastly, plug in the OLED as shown in the picture above. You should be able to plug it into any of the three rows.
Step 2 – Pre-coding

https://www.elecfreaks.com/wp-content/uploads/2017/08/081617_1033_MakeABurgla4.jpg

We'll need to add a package of code to be able to use our kit components. Click on Advanced in the Code drawer to see more code sections and look at the bottom of the Code Drawer for Add Package.

https://www.elecfreaks.com/wp-content/uploads/2017/08/081617_1033_MakeABurgla5.jpg

This will open up a dialog box. Copy and paste the following link into the Add Package… text field: https://pxt.microbit.org/50544-64675-33322-24641. Click on the search iconor press enter, then click on the Tinkercademy button.

Note: If you get a warning telling you some packages will be removed because of incompatibility issues, either follow the prompts or create a new project in the Projects file menu.

Step 3 – Coding

https://www.elecfreaks.com/wp-content/uploads/2017/08/081617_1033_MakeABurgla6.jpg

After that, use blocks under the Tinkercademy section to initialize the OLED and Crash Sensor as shown in the picture

https://www.elecfreaks.com/wp-content/uploads/2017/08/081617_1033_MakeABurgla7.jpg

This part of the code allows the red LED to blink continuously. You can adjust the speed of blinking by changing the pause period

https://www.elecfreaks.com/wp-content/uploads/2017/08/081617_1033_MakeABurgla8.jpg

Since there are only two conditions, we need only one 'else-if' statement. When the Crash Sensor is pressed, the green Octopus LED will light up. Or else, if no force is applied to the Crash Sensor, the red LED will blink continuously.



Step 4 – Succeed!

Let's download code into it and run it. Let's find a book or something else and place it on the top of device, then see what will happen. We can see the green light illuminates as showed in the picture below. When we take away the book or something else you placed, you can see the red light starts to flash while the green light turned off.

https://www.elecfreaks.com/wp-content/uploads/2017/08/081617_1033_MakeABurgla9.jpg

Relative Reading:

Make an Intruder Detection with Micro:bit
Make a Fish Feeder by Micro:bit
Plant Humidity Monitor


https://www.elecfreaks.com/9572.html

页: [1]
查看完整版本: Make A Burglar Alarm Device with Micro:bit