Creating Movement with Motors (Python)

The Hummingbird kit works with three different kinds of motors: vibration motors, servo motors, and gear motors.

Vibration Motors

A vibration motor can be attached to one of the two ports labeled “VIBRATION” on the Hummingbird board. It does not matter which wire is attached to ‘+’ and which is attached to ‘-.’

The set_vibration_motor() method is used to control the vibration motor. This block requires two parameters. The first is the port attached to the vibration motor (1 or 2), and the second is the intensity of the vibration from 0 to 255. 0 means no vibration, and 255 means maximum vibration. The code below turns a vibration motor in port 1 on for 2 seconds.

Exercise: What do you think the script below will do? After you make a hypothesis, try it and find out. Modify this program to enable the user to control a tri-color LED as well.

Building Tip: Small bells can be attached to the vibration motor. Activating the motor will cause the bell to ring. Also, googly eyes can be attached to a vibration motor so that they move when the motor vibrates.

Servo Motors

A servo motor is a motor that moves to a particular angle. The Hummingbird servo motor can rotate to any angle from 0° to 180°. When using the servo motor, you must also use the AC power adapter (or a battery pack). Otherwise, the Hummingbird board will not have enough power to run the motor.

The servo motor has a small plug. This plug should be placed on one of the four male servo connectors on the Hummingbird board. The black wire should be connected to the ‘-’ pin, the red wire to the ‘+,’ and the yellow wire to the ‘S.’

Use hot glue to attach a popsicle stick to the white plastic circle on the servo motor. This will help you to see the movement of the servo motor more easily.

The set_servo() method is used to move the servo motor. It requires two parameters. The first is the port attached to the servo (1-4), and the second is the angle (0° to 180°). The command below will move a servo motor attached to port 1 to 0°.

Try out the script shown below. What problem do you observe? How can you fix this problem?

Exercise: Write a program to make the servo motor “dance” to a variety of different positions.

Gear Motors

The gear motor can be attached to either of the ports labeled “MOTORS” on the Hummingbird board. It does not matter which wire is attached to ‘+’ and which is attached to ‘-.’ When using the gear motor, you must also use the AC power adapter (or a battery pack). 

The set_motor() method is used to control the gear motor. This method requires two parameters. The first is the port attached to the motor, and the second is the speed of the motor. The speed can be any number from -1.0 to 1.0. The code below turns a motor on for three seconds.

Exercise: Use a small screwdriver to attach a wheel to the motor so that you can see it move more easily. Try several speeds between 0 and 1.0. Describe how the speed affects the motor. Try several negative speeds. What does it mean for the speed to be negative?