![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/37be6b47958f8492c74fc81635b821d3.png)
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/6be3ea862531173077d9c6421918efe9.png)
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/9a47062c3506c7d45409f4ac0098b29b.png)
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/6439d64e681f62e6aacde20be4a252fb.png)
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/c5c62330e25d86d99615fa96893c2507.png)
STEP1: Connect the servo to the pin P0 of micro: bit expansion board.
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/b0e3d67aebb1c84893a4f4569e9ebf11.png)
STEP2: Programming
1. Drag the “read acceleration” block in micro: bit module to script area. It can be used to get the acceleration of X, Y and Z axes.
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/d06af733b2e920acef3a225bee61a68b.png)
2. The output value of the accelerometer ranges between -1023 and 1023, and we can use “display” block to check it.
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/7034ee59396f16608e72d57e829f6690.png)
3. When micro: bit board is titled to the left, a negative output value will be produced along the X direction, so we need the servo to rotate toward right to compensate this angle.
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/8c49e02b695c90b53c52814923cbcb1f.png)
Here we have to use “map” function. Mapping the value of accelerometer’s X axis (-1023~1023) onto the degree that the servo rotates (0~180 degree). After mapping, when the board lays flat on the desktop, the angle of the servo will be 90 degrees. The corresponding relations show as Table 4.1.1
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/c0407cd9633f44d691dd7dbe40eb192a.png)
Find “map…from…to…” block in “Operators” module.
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/367fb68320700301296a4dce18c16b52.png)
4. Click Expansions->Actuator->Micro Servo and back to the former interface.
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/d74a776da0b17114cfb5c5aa9ecc3937.png)
5. Drag “set pin servo to… degree” block to script area, and put it inside the “forever” block, then nest the “map…” block into it. Shown as below:
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/0afba645069947856adca374febe9f8e.png)
6. Fix the servo onto the expansion board with double-side adhesive tape so that they both remain relatively still.
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/09fa860bfbf03cfd4c1e6187c0f4068a.png)
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/d6be3783ffba893a20971c21acdaf573.png)
![projectImage](https://dfimg.dfrobot.com/6188847caa9508d63a4183aa/makelog/9f73343f8ed1f8dcafa9026ad9952b28.png)
![licensBg](/images/license_bg.png)