Lesson 08 Servo
Introduction
Servo is a kind of driver for position (angle) servo. It is suitable to control systems with constant angle change and can remain in its position. In this experiment, we are going to use the micro:bit to make a servo rotate circularly within a travel range.
What you need
- micro:bit board
- Micro USB Cable
- micro:bit breadboard adaptor
- Breadboard
- TowerPro Servo motor
- Male to male jumper wires
Servo Motor
Servo is a set of automatic control system, which consists of a DC motor, reduction gear unit, potentiometer and control circuit. It can define rotation angle of output shaft by sending signals. Usually, a servo has a maximum rotation angle(e.g. 180 degrees). Compared with ordinary DC motor, servo rotates within a certain angle range only while ordinary a 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 motors can not give us feedback about the rotation angle but servo can do this. Their usage are different too. DC motors use a whole circle rotation as power, while servo’s uses a certain angle of an object it controls, such as robot arm.
The servo system can be controlled by pulses, which can change its width. We use control cable to transmit this pulse. The parameter of pulse signal 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 servos may have different maximum rotate angle but the pulse width of middle position is the same and that is 1.5ms.
Note: micro:bit official has loaded servo control code into blocks, when using Makecode to program. You don’t have to take some complex information (e.g. the width of impulse) into consideration.
Servos have many applications. 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 breadboard diagram below:
After connecting the circuit, you should see the following:
Programming
Open Microsoft Makecode, write your code in the edit area.
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.
Link of the whole program: https://makecode.microbit.org/_Yd7X6x1dKfgv
Code Explanation
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.)
Results
We can see the servo rotates with angle range from 0 degree to 180 degree.
Taking it further
If we want to use temperature sensor and servo to make a dial thermometer, then how would you design the circuit and program it?
micro:bit Starter Kit Lessons
- Lesson 01 – LED
- Lesson 02 – Button
- Lesson 03 – Trimpot
- Lesson 04 – Photocell
- Lesson 05 – RGB LED
- Lesson 06 – Self-lock Switch
- Lesson 07 – Temperature Sensor
- Lesson 08 – Servo
- Lesson 09 – Buzzer
- Lesson 10 – Motor
- Lesson 11 – Rainbow LED
- Lesson 12 – Accelerometer
- Lesson 13 – Compass
- Lesson 14 – Ambient Light