zt07elecfreaks 发表于 2018-1-16 17:38:51

Make A Motion Detector with Micro:bit and Elecfreaks Octopus Kits

Don't like people sneaking up on you? Here's just the right micro:bit project for you! In this course, we learn how to make use of the motion sensor, the moisture sensor as well as how they can be coded for.
Goals:


Get to know the PIR Sensor Brick and moisture sensor.

Make something with a PIR Sensor Brick.

Make something with a Moisture Sensor.
Materials:

1 X BBC micro:bit

1 X Micro USB cable

1 X Breakout board (Elecfreaks will soon publish a new fully compatible Breakout board for it. For more details, you can see: Elecfreaks Micro:bit Adapter)

1 X Mini buzzer

1 X Octopus PIR sensor Brick

1 X Moisture sensor

2 X Female-Female jumper wires



Step 1:

After connecting one end of the USB cable to your computer, connect the other end to the micro:bit as shown in the picture. Connect the side of the micro:bit where the pins are located to the breakout board.
https://www.elecfreaks.com/wp-content/uploads/2017/08/082217_1039_MakeAMotion2-1.jpg

Step 2:
Plug in the buzzer to Pin 0 (the pins beside the number '0' on the breakout board). Plug in the moisture sensor to Pin 3. Plug in the motion sensor to Pin 1 .Make sure the colour of the wire of the buzzer and the ADKeyboard follows the colour of the pins on the breakout board.

https://www.elecfreaks.com/wp-content/uploads/2017/08/2-2.jpghttps://www.elecfreaks.com/wp-content/uploads/2017/08/3-3.jpghttps://www.elecfreaks.com/wp-content/uploads/2017/08/4-1.jpg
Step 3:
https://www.elecfreaks.com/wp-content/uploads/2017/08/082217_1039_MakeAMotion5.png

Click on \"Advanced\" in the code drawer to see more code sections.

To code for our extra kit components (the ADKeyboard and the buzzer), we will need to add a package of code.

https://www.elecfreaks.com/wp-content/uploads/2017/08/082217_1039_MakeAMotion6.png

Look at the bottom of the code drawer for \"Add Package\" and click it to open up a dialogue box. Copy and paste this 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.

https://www.elecfreaks.com/wp-content/uploads/2017/08/082217_1039_MakeAMotion7.png

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.

https://www.elecfreaks.com/wp-content/uploads/2017/08/082217_1039_MakeAMotion8.png

Click on Tinkercademy inside the Code Drawer to find our custom blocks for the various components in your kit.

https://www.elecfreaks.com/wp-content/uploads/2017/08/082217_1039_MakeAMotion9.png

For this project, we are going to use the blocks read value from moisture sensor and motion sensor.

Step 4

In this step, we will code the Micro:bit with Block Editor. We begin by coding a starting screen, by placing the \"Show Icon\" block under the \"On Start\" block as shown in the picture on the right.

This causes the icon to appear on the screen whenever the micro:bit is powered on.

https://www.elecfreaks.com/wp-content/uploads/2017/08/082217_1039_MakeAMotion10.png

Step 5:

Next, let's create some music using the moisture sensor values.

Select the \"Play Tone\" block under the \"Music\" code section and place the value of Moisture Sensor code block in it

The pitch can be adjusted by multiplying the sensor values by different numbers, as shown in the image on the left.

https://www.elecfreaks.com/wp-content/uploads/2017/08/082217_1039_MakeAMotion11.jpg

Step 6

Finally, make the buzzer sound when the motion sensor detects movements. The micro:bit will only show an icon on the screen if there is no movement.

This can be done by using a conditional (if-then-else) statement and inserting the relevant blocks in the appropriate spots, as shown in the picture on the right.

https://www.elecfreaks.com/wp-content/uploads/2017/08/082217_1039_MakeAMotion12.jpg

Succeed! You now have your very own Micro:bit motion detector!

Relative Reading:

Make an Intruder Detection with Micro:bit

Make a Fish Feeder by Micro:bit

Plant Humidity Monitor

Make A Burglar Alarm Device with Micro:bit



This article is from Tinkercademy: Make a Motion Detector
https://www.elecfreaks.com/9643.html
页: [1]
查看完整版本: Make A Motion Detector with Micro:bit and Elecfreaks Octopus Kits