HOW to Control Micro Servo with Microbit
Overview
For those DIY smart cars, they often have a function of automatic obstacle avoidance. In the DIY process, we need a servo to control the ultrasonic module to rotate left and right, and then to detect the distance between car and obstacles, so as to control the car to avoid obstacles.
If use other microcontrollers to control the rotation of servo, we need to set a pulse of a certain frequency and a certain width in order to control the servo angle.
But if use the micro bit main board to control the servo angle, we only need to set the control angle in the development environment. The corresponding pulse will be automatically set in the development environment to control the servo rotation.
In this project, you will learn how to control the micro servo rotate back and forth between 0°and 90°.
Component Required
-
Micro:bit main board*1
-
Keyestudio Micro bit Sensor V2 Shield*1
-
USB Cable*1
-
keyestudio Micro Servo*1
-
DuPont jumper wire*3
-
Premium Battery Holder 6-cell AA*1
-
1.5V AA Battery*6
Component Introduction
keyestudio Micro Servo:
The servo has three interfaces,distinguished by brown, red and orange line(different brand may have different color). Brown line is for GND, red one for power 5V, orange one for signal terminal (PWM signal).
The rotation angle of servo is controlled by regulating the duty cycle of the PWM(Pulse-Width Modulation) signal. The standard cycle of the PWM signal is fixed at 20ms (50 Hz), and the pulse width is distributed between 1ms-1.5ms. The pulse width corresponds to the rotation angle ( 0°~90°).
Connection Diagram
Test Code
Test Results
Done wiring and plug in external power, send the above code to micro:bit. You should see the servo turn back and forth between 0°and 180°.