![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/a884812ef91f5151a1999fd24c55054a.png)
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/6c47d57e4449701b19f55c7c30310910.png)
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/bf808a458e5cc212406296b6397db029.png)
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/fa7f9fff71c6c9c3bdd64228e7574081.png)
STEP1: connect micro: bit board to computer with USB cable, plug the earphone in the expansion board; connect the motion sensor to pin P1 of the expansion board.
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/9926cff7f1a6832b26c13d0c97d8a2ff.png)
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/73a9fc17f181e6d03a3cdc8437fcc189.png)
STEP2: Programming
1. Drag “pin P0 play sound…until done” block from “micro: bit” module to script area. There are many built-in sounds to choose. We select the sound “dadadadum” here.
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/14fc1e38b79a70c0c8cf62201a484742.png)
2. Run the program
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/76019d554594163a670c591a9e0b3822.png)
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/424334ce7b6e87ba226c0eeddd047375.png)
1. Program to generate a piece of music of Twinkle, Twinkle, Little Star.
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/b7342fecb99c93b70ba17fabdf2040b1.png)
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/027c392c8bdf3de9551faee67f01c312.png)
2. Drag “pin P0 play note-C2 for 1beat” from the “micro: bit” module to script area. Revise the parameter “C2” to play different notes, and change the parameter ”1” to adjust the beat.
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/dbb173226bddeb33b0f9f03a51baa2be.png)
3. Motion sensor has been connected to pin P1, if someone passes near the device, the value of P1 will be 1, otherwise, it will be 0. Therefore, combining it a “if then…else” statement, we can make the smart music box come to life.
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/01fd11e9c4babad43097fd5f1599bedd.png)
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/be9571e3a09893d6bfee45c8a8da5d96.png)
![licensBg](/images/license_bg.png)