# Case 39:The Mechanical Crab ## Introduction Build a mechanical crab with the [Nezha Inventor's Kit](https://shop.elecfreaks.com/products/elecfreaks-micro-bit-nezha-48-in-1-inventors-kit-without-micro-bit-board?_pos=2&_sid=ed1b6fbd2&_ss=r). ![](./images/39_1.png) ## Quick to Start --- ### Materials Required [Nezha Inventor's Kit](https://shop.elecfreaks.com/products/elecfreaks-micro-bit-nezha-48-in-1-inventors-kit-without-micro-bit-board?_pos=2&_sid=ed1b6fbd2&_ss=r) ### Assembly --- Components List ![](./images/neza-inventor-s-kit-case-39-02.png) Build it as the assembly steps suggest: ![](./images/neza-inventor-s-kit-step-39-01.png) ![](./images/neza-inventor-s-kit-step-39-02.png) ![](./images/neza-inventor-s-kit-step-39-03.png) ![](./images/neza-inventor-s-kit-step-39-04.png) ![](./images/neza-inventor-s-kit-step-39-05.png) ![](./images/neza-inventor-s-kit-step-39-06.png) ![](./images/neza-inventor-s-kit-step-39-07.png) ![](./images/neza-inventor-s-kit-step-39-08.png) ![](./images/neza-inventor-s-kit-step-39-09.png) ![](./images/neza-inventor-s-kit-step-39-10.png) ![](./images/neza-inventor-s-kit-step-39-11.png) ![](./images/neza-inventor-s-kit-step-39-12.png) ![](./images/neza-inventor-s-kit-step-39-13.png) ![](./images/neza-inventor-s-kit-step-39-14.png) ![](./images/neza-inventor-s-kit-step-39-15.png) ![](./images/neza-inventor-s-kit-step-39-16.png) ![](./images/neza-inventor-s-kit-step-39-17.png) ![](./images/neza-inventor-s-kit-step-39-18.png) ![](./images/neza-inventor-s-kit-step-39-19.png) ![](./images/neza-inventor-s-kit-step-39-20.png) ![](./images/neza-inventor-s-kit-step-39-21.png) ![](./images/neza-inventor-s-kit-step-39-22.png) ![](./images/neza-inventor-s-kit-step-39-23.png) ![](./images/neza-inventor-s-kit-step-39-24.png) ![](./images/neza-inventor-s-kit-step-39-25.png) ![](./images/neza-inventor-s-kit-step-39-26.png) ![](./images/neza-inventor-s-kit-step-39-27.png) We can see that the construction is completed as shown in the following figure: ![](./images/neza-inventor-s-kit-case-39-01.png) ### Connection Diagram Connect the [Ultrasonic Sensor](https://shop.elecfreaks.com/products/elecfreaks-planetx-ultrasonic-sensor?_pos=1&_sid=d432fa273&_ss=r) to J1 and the [motor ](https://shop.elecfreaks.com/products/elecfreaks-high-speed-building-blocks-motor?_pos=4&_sid=bfad50d7f&_ss=r)to M1 on [Nezha Breakout Board](https://shop.elecfreaks.com/products/elecfreaks-nezha-breakout-board?_pos=1&_sid=c41e367c3&_ss=r). ![](./images/neza-inventor-s-kit-case-39-03.png) ## MakeCode Programming --- ### Step 1 Click "Advanced" in the MakeCode drawer to see more choices. ![](./images/neza-inventor-s-kit-case-37-04.png) For programming the [Ultrasonic Sensor](https://www.elecfreaks.com/planetx-ultrasonic.html), we need to add a package. Search with "PlanetX" in the dialogue box and click to download it. ![](./images/neza-inventor-s-kit-case-37-05.png) For programming [Nezha Breakout Board](https://shop.elecfreaks.com/products/elecfreaks-nezha-breakout-board?_pos=1&_sid=00432325a&_ss=rl), we need to add a package. Search with "Nezha" in the dialogue box and click to download it. ![](./images/neza-inventor-s-kit-case-37-06.png) *Notice*: If you met a tip indicating that some codebases would be deleted due to incompatibility, you may continue as the tips say or create a new project in the menu. ### Step 2 ### Code as the picture suggests ![](./images/neza-inventor-s-kit-case-39-07.png) ### Reference Link: [https://makecode.microbit.org/_09MCJLLdTYcr](https://makecode.microbit.org/_09MCJLLdTYcr) You may also download it directly:
--- ### Result After powering on, if the crab sees an approaching object ahead, it will crawl towards sideways. ![](./images/39_39.gif)