Internet Connected Fistbump: The hardware

The circuit for this project is trivial, consisting only of a hobby servo motor. You will also need a solderless breadboard and some jumper wires1.

In Driving Bigger Loads (Motors, Lamps, and the Like) in Ch. 5, you learned how to control a simple DC motor. This type of motor is designed to turn continuously rather quickly, which is exactly what you want in a fan. However, if you need to move something a specific distance these motors are not very good. Hobby servo motors were created to move the control surfaces of model airplanes, and they are quite precise. They do this by incorporating feedback: inside the hobby servo motor is a sensor which detects the rotational position of the shaft, and a circuit which moves the motor in the appropriate direction to move it to the destination you have indicated. Hobby servo motors also include gears, reducing the high speed of the internal DC motor to a more useful speed, while at the same time increasing the torque proportionally. Hobby motors do not rotate continuously, but rather rotate only through 180 degrees. While this might seem strange, remember they were designed to move the control surfaces on model airplanes, for example the tail rudder. The rudder doesn’t rotate more than 180 degrees.

Hobby servo motors are incredibly useful even if you’re not building model airplanes. Imagine that you want to build an animatronic puppet, where the eyes might move left and right, eyelids might open and close, and the head might rotate towards the left and right. None of these motions require more than 180 degrees of rotation, and many animatronic puppets use hobby servo motors extensively.

Hobby servo motors are different from DC motors from an electrical point of view also: DC motors have two wires: when a suitable voltage is applied between those two wires, the motor turns. Hobby servo motors have three wires: a voltage of 5-6 volts is applied between two of them, and a control signal is sent on the third. The control signal is a pulse of a certain duration, where the pulse duration tells the servo motor what angle (between 0 and 180 degrees) to go to. 

Hobby servo motors are usually terminated with a plastic connector housing the three terminals. The wires are color coded as follows:

Wire ColorArduino Connection
BlackGround
Red or Brown5V
White or YellowControl signal (any Arduino pin)

To build the circuit, insert a wire or wire jumper into the connector and then connect to your Arduino. Ideally, us the same colors to avoid making mistakes later. Use a solderless breadboard to make the connections. For the servo control signal, you can use any pin number. I used pin 9 because it matches the built-in examples. Visit the Product page for Arduino MKR WiFi 1010 and click on the Documentation tab to see the pin names.

Micro Servo

Once you have the wires connected, test that the servo motor works properly with the “sweep” built-in example (File->Examples->Servo->Sweep). Once you load this program, the motor shaft should rotate from its zero position to 180 degrees and then back to zero continuously.

We will use the hobby servo motor to move a picture of a fist towards or away from you. You can draw a picture of a fist or print out the fist emoji. To make it easier to attach the emoji to the motor hub, use one of the horns included with your servo motor. I used a bit of hot glue to attach the fist to a cardboard “arm” and then to the servo horn:

n GSWA3E cardboard arm with drawing of fist glued to a servo horn handrawn

Finally, make a cardboard stand to hold the servo motor. Before you attach the arm, use the following code to determine which angle will correspond to the fist being withdrawn, and which will correspond to the fist being “bumped”:

Example 10-1.  
#include <Servo.h>

Servo myservo;  

void setup() {
  myservo.attach(9);  
  myservo.write(45); // move to position 45 degrees
}

void loop() {          
}

Note the position of the motor shaft, then change the number 45 to 135 and see which direction the shaft moved. In my case 10 degrees was a good position for the fist being withdrawn and 170 degrees for “bumped”. You need to do this before attaching the arm to avoid damaging the arm by accidentally slamming it into the ground.

Change the number to move the arm back to the withdrawn position, and then attach the arm at the appropriate angle for the withdrawn position:

n GSWA3E Arm Attached Withdrawn handrawn

Now we are ready to get our project on the internet!


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *