Buy from US Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES ここでご購入を!


Connect Ultrasonic detector module to  the 4-pin port “+,p8,p16,-” of PnP board with a 4-pin PnP cable ;

Connect green LED module to port P0 in OSOYOO PnP board with OSOYOO 3-pin PnP cable ;

Connect yellow LED module to PnP board port P1 with   3-pin PnP cable;

Connect red LED module to PnP board port P2 with  3-pin PnP cable as below;

Step 0: Go to urlhttps://makecode.microbit.org, click New Project  

Step 1. In the Toolbox, click on the Variables category and then click the Make a Variable button, and then In the New Variable name window, type “range” as the variable name, then click on the Ok button as following figure。

Step 2. Drag and drop a set range to 0 block inside the forever block.

Step 3. In the Editor controls, click on the Advanced button and then Extensions as following figure.

Step 4.In the Extensions page , enter project “Sonar ” in the Search textbox and click on the Search button. The page will show you all the matching extensions based on your search string. Now, click on sonar to add it into your project as following figure.

Step 5. In the Toolbox, click on the Sonar category . Drag the ping trig echo unit block  and place it inside the placeholder of the set range to 0 block. Then choose P8 in ping trig ,choose p16 in echo pin ,choose cm in unit from the drop-down menu as following figure.

Step 6. Click on the Basic category and drag the show number block  place it inside the placeholder of the forever block just below the set range to 0 block as following figure.

Step 7.In the Toolbox, click on the Variables category . Drag the range block  and place it inside the placeholder of the show number block as following figure.

Step 8. In the Toolbox, click on the Logic category and drag the if-then-else block over .

Step 9. Place the if-then-else block   inside the placeholder of the forever block below the show number 0 block. Click on the plus icon to add another section to the if-then-else block as following figure.

Step 10. In the Toolbox, click on the Logic category again, click and drag the 0=0 block over and place it inside of the forever block below the show number block.then set “0≥0”from the drop-down menu as following figure.

Step 11. Drag and drop a range block from variable category and place it inside the placeholder of the 0≥0 block .Then set range≥20 in it as following figure .

Step 12. In the Toolbox, click on the Pin category. Then  drag a digital write pin to block  and place it inside the forever block. Then set write pin value to “1” from the drop-down menu as following figure.

Step 13. Right click duplicate  digital write pin to block select duplicate twice . You will get two duplicated digital write pin blocks ,and place them inside the on forever block just below the if range ≥20 then block .set write pin to P1 ,P2 as following figure.

Step 14. Click on the Logic category. Then click and drag the and block over and place it inside the placeholder of else block.

Step 15. Click on the Logic category again and drag  the 0 <0 block   and place it in front the “and” section of the else block.

Step 16. Drag and drop a range block from variable category   and place it inside the placeholder of the 0<0 block.then set range < 20 in it as below figure.

Step 17. Click on the Logic category again , drag   an 0 <0 block  and place it behind the “and” section of the else block. then set 0 ≥10 in it as below figure.

Step 18. Drag   a range block from variable category again. and place it in front the placeholder of the 0≥10 block.

Step 19. use duplicate method to make  another three digital write pin block , drop these new block below else if range <20 and range ≥10 then block .  Then Set the pin#  toP1,P2, the value o to 1  as following figure.

Step 20.  Repeat duplicate method to make another three digital write pin blocks. drop these new blocks below else block .  Set the pinto P1,P2, the value o to 1  as following figure.
Step 21. In the Toolbox, click on the Basic category. Then  drag the pause(ms) block and place it inside the else block below the three digital write pin to block .

Step 22. Download this “.hex” file and save it to your MICROBIT disk Driver as following figure.

Below are the full Graphic programming code blocks  we have done for you as reference:

Learn More about parts

No. Picture Product Name Link
1 BBC micro:bit micro Mainboard https://osoyoo.store/products/bbc-micro-bit-micro-controller-with-motion-detection-compass-led-display-and-bluetooth?variant=31021023002735
2 OSOYOO Expansion board for Micro:bit https://osoyoo.store/products/pnp-board-for-micro-bit-stem-kitmodel-2018005900?variant=31698997444719
3 Green LED Module https://osoyoo.store/products/green-led-module-for-osoyoo-stem-kit-for-micro-bit-model-2019011500?variant=31957968158831
4 Yellow LED Module https://osoyoo.store/products/yellow-led-module-for-osoyoo-stem-kit-for-micro-bit-model-2019011500
5 Red LED Module https://osoyoo.store/products/red-led-module-for-osoyoo-stem-kit-for-micro-bit-model-2019011500?variant=31957964882031
6 White LED Module https://osoyoo.store/products/white-led-module-for-osoyoo-stem-kit-for-micro-bit-model-2019011500?variant=31816681128047
7 Humi & Temp Module https://osoyoo.store/products/humi-temp-module-for-osoyoo-stem-kit-for-micro-bit-model-2019011500?variant=31957977563247
8 Passive buzzer Module https://osoyoo.store/products/passive-buzzer-module-for-osoyoo-stem-kit-for-micro-bit-model-2019011500
9 Flame sensor Module https://osoyoo.store/products/flame-sensor-module-for-osoyoo-stem-kit-for-micro-bit-model-2019011500
10 Red Button Module https://osoyoo.store/products/red-button-module-for-osoyoo-stem-kit-for-micro-bit-model-2019011500?variant=31958006693999
11 Yellow Button Module https://osoyoo.store/products/yellow-button-module-for-osoyoo-stem-kit-for-micro-bit-model-2019011500?variant=31958014328943
12 Photoresitor Module https://osoyoo.store/products/photoresitor-module-for-arduino-microbit-osoyoo-stem-kitmodel-2019011500?variant=31958061154415
13 RGB Module https://osoyoo.store/products/rgb-module-for-osoyoo-stem-kit-for-micro-bit-arduino-raspberry-pi-model-2019011500?variant=31958069739631
14 IR Receiver Module https://osoyoo.store/products/ir-receiver-module-for-arduino-raspberry-pi-micro-bit-stem-model-2019011500?variant=31958077309039
15 Infrared Remote Controller https://osoyoo.store/products/infrared-remote-controller-for-arduino-raspberry-pi-microbit-stemmodel-2019011500?variant=31958087532655
16 Microphone Module https://osoyoo.store/products/microphone-module-for-arduino-raspberry-pi-micro-bit-stem-model-2019011500?variant=31958089597039
17 Potentiometer Module https://osoyoo.store/products/potentiometer-module-for-osoyoo-stem-kit-for-micro-bit-model-2019011500?variant=31817102852207
18 Fan Motor module https://osoyoo.store/products/fan-motor-module-for-osoyoo-stem-kit-for-micro-bit-model-2019011500?variant=31957989359727
19 Micro Servo motor https://osoyoo.store/products/micro-servo-sg90-blue-for-arduino-v2-0-robot-carmodel-lacc200610
20 Ultrasonic detector module https://osoyoo.store/products/ultrasonic-detector-module-for-arduino-raspberry-pi-micro-bit-stemmodel-2019011500?variant=31958286729327
21 1602 I2C LED Screen https://osoyoo.store/products/white-led-module-for-osoyoo-stem-kit-for-micro-bit-model-2019011501?variant=31817047048303
22 1 Channel Relay Module https://osoyoo.store/products/1-channel-relay-module-for-osoyoo-stem-kit-for-micro-bit-model-2019011500?variant=31957950562415