Micro:bit Experiment 08:Servo —— Elecfreaks Mirco: bit Starter Kit Course
Servo is a kind of driver for position (angle) servo. It is suitable to control system with constant angle change and can remain its status. In this experiment, we are going to use Micro:bit to make a servo rotate circularly within a travel range.
1 x Micro:bit Board
1 x Micro-B USB Cable
1 x Microbit Breadboard Adapter
1 x Transparent Breadboard - 83 * 55 mm
1 x TowerPro SG-90 Mini Servo(1.6kg)
1 x Breadborad jumper wire 65pcs pack
Tips: If you want all components above, you may need Elecfreaks Micro:bit Starter Kit.
Microsoft Makecode Online Editor
Major Component Introduction Servo
Servo is a set of automatic control system, which consists of DC motor, reduction gear unit, potentiometer and control circuit. It can define rotate angle of output shaft by sending signals. Usually, a servo has a maximum rotate angle(e.g. 180 degrees). Compared with ordinary DC motor, servo rotates within a certain angle range only while ordinary DC motor rotates in circle. This is the major difference between ordinary DC motor and servo. Servo can not rotate in circle. (Note: digital servo do not have this problem because it can switch between servo mode and motor mode.) Ordinary DC motor cannot give us feedback about rotate angle but servo can do it. Their usage are different too. Ordinary DC motor use a whole circle rotation as power while servo use certain angle of an object it controlled such as robot joint. The servo system can be controlled by impulse, which can change its width. We use control cable to transmit impulse. The parameter of impulse has maximum value, minimum value and frequency. Generally speaking, the cycle of servo reference signal is 20ms and the width is 1.5ms. The position defined by servo reference signal is middle position. Since servo has a maximum rotate angle, the definition of middle position is from this position the maximum value and the minimum value are the same. Most importantly, different servo may have different maximum rotate angle but the impulse width of middle position is the same and that is 1.5ms.
Note: Micro:bit official has loaded servo control code into bricks. When using Makecode to do program, you don't have to take some complex information (e.g. the width of impulse)into consideration. Servo has many categories. However, all of servos have three cables connected externally. These cables usually have three different colors( brown, red, orange ) to differentiate each other. (Different servos brand may have different cable colors.) The brown cable is for connecting GND, red cable is for positive power cable and orange cable is for signal cable. Hardware Connection
Please complete hardware connection according to the picture below.
After connection, you will see: Programming
Open Microsoft Makecode, write your code in the edit area. I would like you to program by yourself first. Of course, you can see the whole code directly in the link below. Just click "Edit"on the top right corner of the interface, then click "Download" on the bottom right corner to download your code into micro:bit.
Servo Write Pin Write a value to the servo on the specified pin and control the shaft. This function will move the shaft of a standard servo to the specified angle, or set the speed of a continuous rotation servo. (0 specifies full speed in one direction, 180 specifies full speed in the other, and approximately 90 specifies no movement.)
We can see the servo rotates with angle range from 0 degree to 180 degree.
If we want to use temperature sensor and servo to make a dial thermometer, then how to design circuit and program? We look forward to your comments or further discussion with us.
Start Your Micro:bit Programming Trip Micro:bit Experiment 01: LED Scroller —— Elecfreaks Micro:bit Starter Kit Course Micro:bit Experiment 02: Button —— Elecfreaks Mirco:bit Starter Kit Course Micro:bit Experiment 03: Trimpot —— Elecfreaks Mirco:bit Starter Kit Course Micro:bit Experiment 04: Photocell —— Elecfreaks Mirco:bit Starter Kit Course Micro:bit Experiment 05: RGB LED —— Elecfreaks Mirco:bit Starter Kit Course Micro:bit Experiment 06: Self-lock Switch —— Elecfreaks Mirco:bit Starter Kit Course Micro:bit Experiment 07:Temperature Sensor —— Elecfreaks Mirco: bit Starter Kit Course