Skip to content
WenYang-Lin edited this page Dec 4, 2017 · 19 revisions

1. Introduction

In this project, we will build a robot that can dance. Here's how it looks like:

Here's a glimpse of the dance moves it can do:


2. Understanding how it works

Before we start talking about what we need and how we need to assemble the components, let's take a moment to notice how does it work. Specifically, notice

  • which parts of the robot move and which parts don't Is it just the legs that move? Does the entire leg move in the same direction or can it bend (around a knee, for example)?
  • in how many dimensions do these parts move? Do they move in one dimension (along a line or along an axis in case of rotation)? Or do they move in two dimensions?
  • how does the robot maintain its balance? Do you need to programmatically ensure it doesn't topple or is it taken care of by how it's designed?

Once you have answers to these questions, let's think about which tasks do we need to implement and how do we implement them.

2.1 Movement of robot legs: degrees of freedom

Let's notice how each leg of the robot moves. Any object in space can move in the following ways:

  • it can translate to another point in space. Does any leg of our robot move to another point in space while the rest of the body remains stationary? Nope!

  • it can rotate around any axis in space. Does any leg of our robot rotate around an axis? Yes it does! At how many points does it move independently? Note that it can move at its hip and at its knee around two different axes.

You can calculate the precise location of a leg if you know the angles of rotation around the two axes. The minimum number of parameters required to find out the precise location of a system is known as degrees of freedom of that system. In our case, each robot leg has two degrees of freedom.

2.2 Moving robot legs

If you want to rotate an object around an axis, what can you use to do so? A motor. We will be using a servo motor for each rotation. Note that a motor rotates around one axis only. Since each leg of our robot can rotate around two different axes, we need two motors for each leg. Hence, for two legs, we need four motors in total.

2.3 Programming dance moves

Now that we have the motors in place, we need to control those motors programmatically. Note that the motors are attached to legs and control the movement of legs. By controlling how the motors run with a piece of code, we can control how a robot moves its legs. Hence, we need to write a program to make the robot dance.

How do we allow a piece of code to control a servo motor? By using Arduino Nano. Arduino Nano acts as an interface between hardware and software.

This is pretty much all we need to understand to build our robot.


3. List of items required to build Otto

Below is the list of items we need to build Otto.

Item What do we need it for
Arduino Nano (x1) Will enable program to interact with servo motors
Arduino Nano Shield (x1) A Shield simply provides more pins connected to Arduino Nano. We need more pins because the number of pins on Arduino Nano might not be enough to connect with four Servo motors and other sensors.
HC-SR04 Ultrasound sensor (x1) We can use this sensor to detect anything in front of the robot. We can then move the robot away from the obstacle or make it kick the obstacle or do anything else we want with it.
Mini servo SG90 9g (x4) Will be attached to legs of the robot
5V Buzzer (x1) In case we want Otto to sing
Female to Female breadboard connectors cable (x6) To make connections between pins and motors
4 AA Battery case (x1) To hold the batteries in the future
Mini to USB cable (x1) To give OTTO power

Soldering Arduino Nano like this:

We need to put all the above items inside the body of the robot. How do we create the body of the robot? We will 3D-print these body parts. The complete list of body parts to be printed out is:

  • Head
  • Torso
  • Upper legs (x2)
  • Left lower leg
  • Right lower leg

You can find six .stl files under the folder 3D print in this repo. You can use them to take a 3D printout.


4. Connecting servo motors with Arduino Nano

The image below shows how the four servo motors needs to be connected to Arduino Nano:

Source: https://www.hackster.io/cparrapa/otto-build-your-own-robot-in-one-hour-5f2a1c

Read full steps from source.

Here, each "connection to servo motor" consists of three wires connected to three pins: G (ground), V (voltage) and S (signal). By convention, wire of darkest color is G and red colored wire is V. Each of the slots 2,3,4 and 5 has three pins - G, V and S respectively. Make sure the darkest wire is connected to G, red wire to V and yellow wire to S respectively.

For now we will only connect the servo motors to Arduino. You can connect HC-SR04 and 5V Buzzer to Arduino Nano yourself as an exercise. The pins to connect to are shown in the same image above.


5. Talking to motors with Arduino code

Now that we have setup the connections, we can start programming to communicate with the motors. We need to be able to instruct motors with rotate with our program. Arduino provides a standard library Servo.h that contains the functions we need to do so. Let's have a look at the library: https://www.arduino.cc/en/Reference/Servo

Before uploading, you need to notice choosing "Board" and "Port":

First of all, we need to tell our program which pins are connected to the motors. Remember that we connected pins 2,3,4 and 5 to the motors. We can do so using the attach() function like so:

#define PIN_RR 5
#define PIN_RL 4
#define PIN_YR 3
#define PIN_YL 2

void setup(){
  ...
  ...

  servo[0].attach(PIN_RR);
  servo[1].attach(PIN_RL);
  servo[2].attach(PIN_YR);
  servo[3].attach(PIN_YL);
  ...
  ...
}

5.1 Rotating motors programmatically

Now that our program knows which pins to use to communicate with the motors, we can rotate the motors by using the write() function like so:

servo[0].write(80)

Refer to the documentation for more details.

5.2 Creating first dance steps

Using the above two functions, let's create our first program. We will rotate the motor by a certain angle and then pause the program so as to allow the motor to complete the rotation. You can pause the entire program by t milliseconds typing delay(t).

In order to know what does zero degree correspond to, we turn the lower two motors by angles of 0 and 180 degrees respectively. We then reset the angle to mid-position (90 degrees):

//setup() function
servo[0].write(0);
servo[1].write(180);
delay(5000);
servo[0].write(90);
servo[1].write(90);

To create a continuous dance motion, we will write the below code inside the loop() function:

for(int i=0;i<2;i++) servo[i].write(i*30+30);
delay(1000);
for(int i=0;i<2;i++) servo[i].write(90);
delay(1000);

You can see the entire code here.

6. smooth_criminal & Import libraries

The file smooth_criminal contains more dance moves. Feel free to go through that code and modify or write your own steps.

But when using smooth_criminal you'll need more libraries otherwise smooth_criminal can't compile. So you need to move folders from OTTO to Arduino libraries' folder.

After importing libraries, you need to reboot Arduino.

Run the code and see your robot dance to your own code. Congratulations! You just created your first dancing robot.