# Case 07: The Basketball Counter ## Purpose --- To make a basketball counter. ![](./images/case-07-01.png) ## Link: --- [micro:bit Wonder Building Kit](https://shop.elecfreaks.com/products/elecfreaks-micro-bit-32-in-1-wonder-building-kit-without-micro-bit-board?_pos=5&_sid=2094afd2f&_ss=r) ## Materials Required --- ![](./images/case-07-02.png) Video link: [https://youtu.be/0P88GP4RQaw](https://youtu.be/0P88GP4RQaw) ## Bricks build-up --- ![](./images/step-case-07-01.png) ![](./images/step-case-07-02.png) ![](./images/step-case-07-03.png) ![](./images/step-case-07-04.png) ![](./images/step-case-07-05.png) ![](./images/step-case-07-06.png) ![](./images/step-case-07-07.png) ![](./images/step-case-07-08.png) ![](./images/step-case-07-09.png) ![](./images/step-case-07-10.png) ![](./images/step-case-07-11.png) ![](./images/step-case-07-12.png) ![](./images/step-case-07-13.png) ![](./images/step-case-07-14.png) ![](./images/step-case-07-15.png) ![](./images/step-case-07-16.png) ![](./images/step-case-07-17.png) ## Installation Mthods of Hardwares Install the sonar:bit with the bricks. ![](./images/Wonder-Building-Kit-step-sonar-bit-2.png) ## Hardware Connection Connect a [sonar:bit](https://www.elecfreaks.com/sonar-bit-for-micro-bit-ultrasonic-sensor-distance-measuring-3v-5v.html) to P1 port on [Wukong breakout board](https://www.elecfreaks.com/wukong-board-with-lego-holder-for-micro-bit.html). ![](./images/Wonder-Building-Kit-case-07-06.png) ## Software Platform --- [MakeCode](https://makecode.microbit.org/) ## Coding --- ### Add extensions Click "Advanced" in the MakeCode to see more choices. ![](./images/case-01-03.png) Search with Wukong in the dialogue box to download it. ![](./images/case-01-04.png) Search with https://github.com/elecfreaks/pxt-sonarbit in the dialogue box to add the sonar:bit extension. ![](./images/case-04-04.png) ### Program ![](./images/case-07-03.png) Link:[https://makecode.microbit.org/_hueHXycJJgv1](https://makecode.microbit.org/_hueHXycJJgv1) ### Result When the ultrasonic sensor detects the ball goes through the basket, it will be counted, and the value will be displayed on the micro:bit. (The principle of ultrasonic counting in this case requires to be tested according to the actual construction of the basket, it is the detection of ultrasonic sensors to the ball basket with the fixed distance value, and by judging this fixed distance value, the score plus one, so as to achieve the purpose of counting. (Ultrasonic sensor counting may have deviations, inaccurate, belonging to the normal situation of not detecting the small ball.