Introduction: DIY Handmade Hexapod With Arduino (Hexdrake)

Hello, I'm David and in this instructable I'll show how I made this hexapod whose name is Hexdrake.

Since I was 16 I became interested in electronic and later in robotics. After getting some level and programming skills using arduino I decided to build a robot something more interesting than a simple robot with two wheels . I liked the idea of having a hexapod but did not have much money to buy one.

So I built a low cost 2DOF hexapod made with hand-cut wood and Sg90 servos.

Step 1: Parts Needed

Step 2: Designing the Parts and Making the Templates

I designed the pieces according to the size of SG90 servos. The CAD file is only for reference. I designed the templates before on paper. I used a sheet of wood about 3 mm of thick. After having the templates the next step is to pass them on to the wooden board.

According to the size of the servo the number of pieces are:

48x A part

6x B

12x C

12x D

12x E

12x F

12x G

12x H

6x I

2x J


Step 3: Time to Cut!!!

Tools for this Step:

Saw, lime, electric dril and a good hand.

Before cutting some pieces is easier to drill the holes using a 3mm drill. I advise to use a fine saw to cut all the pieces accurately. After cutting each piece file the edges to be soft.

Step 4: Glue Certain Parts Between Them

Tools for this step:

Glue(cyanoacrylate glue for more strength), tweezers, toilet paper (to clean the excess glue).

To make the main parts of each leg, where the servos are subject I needed to glue 4 A pieces. Then, for each leg glue a piece B with C. And the last thing to be done is to glue two H pieces together.

*Be careful to align the holes well of certain pieces or can also be done is glue before and then do drills the holes.

Step 5: Painting and Decorating

Materials and tools for this step:

EVA foam(red and black), glue, scissors, rule, pencil and black acrylic paint.

For a more professional finish I paint some of the pieces with black acrylic paint, and cover the body and legs with black and red EVA foam.

Step 6: Attaching the Servos to the Legs and Body

Materials for this step:

A lot of screws, screwdriver and 12 SG-90 servos.

Step 7: Add Electronics and Connect.

Electronic:

An arduino. USC 16-channel servo controller, UBEC 8A hobbywing, lipo battery.

Power supply:

The servo controller needs two power supplies: servo power supply and chip power supply.

-Servo power supply (+): VS (left of the blue connecting terminal at Position 3 in the figure)
-Servo power supply (‐): GND (middle of the blue connecting terminal at Position 3 in the figure)

Servo power supply’s parameters depend on the parameters of the attached servo. For example, if the SG-90 servo has a power supply of 4V‐5V, the servo power supply can use the power source of 4‐5V.

-Chip power supply (+): VSS (right of the blue connecting terminal at Position 3 in the figure)

-Chip power supply (‐): GND (middle of the blue connecting terminal at Position 3 in the figure)

There is a VSS requirement of 6.5‐12V. If the chip power is input through the VSS port, the power supply has to range from 6.5 to 12V.

Connecting Arduino, USC and servos:

What is marked red in the figure are the servo’s connectors for signal wires (be careful about the direction when
connecting to the servo).

To connect the USC controller simply connect the rx of the USC to the tx of arduino and the tx pin with the rx pin of the USC. And connect GND pin of USC with arduino.


Step 8: Programming

Software for this step:

Arduino IDE, USC sofware.

Before programming with arduino it's necessary to know the limits of all the servos and know the limits values. For example using the mouse to drag the slider in the servo panel (drag the servo panel corresponding to the channel with which the servo is connected). So connecting the USC inside the hexapod with the usb to the program I get all de max and min values of each servo.

Now is time to program the arduino to control the USC. The servo controller is a slave device, meaning that it can either accept commands or execute preset commands. It cannot think at all. Communication protocol: serial communication (TTL level), baud rate 9600, no check bit, 8 data bits, 1 stop bit To control the servo through the servo controller. The Command format are:

-Control one single servo:

#1P1500T100\r\n

Data 1 refers to the servo’s channel.

Data 1500 refers to the servo’ location, in the range 500‐2500.

Data 100 refers to the time of execution and represents the speed, in the range 100‐9999

-Control multiple servos:

#1P600#2P900#8P2500T100\r\n

Data 1, 2, and 8 refer to the servo’s channels

Data 600, 900, and 2500 refer to the locations of the servos that correspond to three channels

Data 100 refers to the time of execution and represents the speed of three servos. Regardless of the number of servos, there is only one time, or one T. The command is executed at the same time; that is, all servos operate simultaneously.

Within the limits of each servo is necessary to calculate the maximum range or "step" of all horizontal servos to find the smallest of them and convert it as the maximum of one step. And this variable enter into the equations of all movements. The same would have to make with the vertical servos.

*Sorry for the poor quality of the first three movies. I record them with an old mobile phone with poor video quality.

New video:

Step 9: Adding Some Personality

I was thinking about things I could add to my hexapod and one of the things that came to me were adding good eyes. I decided to add the eyes to hexapod to give more expression to the moves or express actions. I designed some sketches on paper of various shapes of eyes. In the end I decided on the design that you can see in the photos.

It's consists of a strip of 32 blue LEDs around the edge and a matrix of 5 rows and 9 columns of red LEDs. Thus the matrix can display various kinds of pupil and it's can move throughout the matrix.

Step 10: Eyes Controller Board

To control both eyes I designed a simple first version control board using Inkscape. It's based on two atmega8 controlling both matrix directly. In future versions i will do an improved more effective board for complete control of the matrix and the strip of blue LEDs.

The first step is cut a piece of copper pcb the size of the design. Later cut the drilling template and place it in the copper pcb. This template marks the place where you have to make the holes for the components.
Now it's time to draw the tracks. I used a a sticker to mark the tracks. The next step is put the PCB in the acid and when done thoroughly clean the PCB. And the final step is solder the joystick and the resistor and put the decorative stickers.

*Sorry for the poor quality of this videos. I record them with an old mobile phone.

Step 11: Adding a Jaw

To make the jaw I did some previous designs in cardboard to find the most correct form for the hexapod. When I found the form, I made the jaw in a small block of aluminum from a heat sink. It is driven by two servos moving together. Later I added inside it a strip of rubber to increase it's grip, and paint and decorate as the same style of the hexapod.

Step 12: Transport Box

Step 13: Final Result of the Hexapod

This is the final result of the hexapod. Now in the next step I will esplain how I mount the remote controller for Hexdrake. :)

Step 14: Making the Joysticks Boards:

Tools for this step:

Saw, lime. drill.

I designed these boards using Inkscape. These boards have the appropriate size for the original joysticks of the PS2 controllers. The main reason I designed these small boards is to simplify the connections between terminals of the potentiometers and the button incorporated with the arduino boards. The board includes a 10k ohm resistor, making the connection between the button and the arduino only needs a cable.

The first step is cut a piece of copper pcb the size of the design. Later cut the drilling template and place it in the copper pcb. This template marks the place where you have to make the holes for the components.

Now it's time to draw the tracks. I used a a sticker to mark the tracks. The next step is put the PCB in the acid and when done thoroughly clean the PCB. And the final step is solder the joystick and the resistor and put the decorative stickers.

The screw terminal blocks conections are:

GND ---> GND of arduino

Vin ------> 5V of arduino

X ------> The x-axis potentiometer to an analog pin of arduino(for example A0)

Y ------> The y-axis potentiometer to an analog pin of arduino(for example A1)

B ------> Connect the button to a digital pin of arduino.(For example D8)

Step 15: How to Use the 2.4GHz Modules?:

I use two nRF24L01 2.4GHz Radio/Wireless Transceivers to comunicate the two arduinos. The range of this modules are from 50 feet to 2000 feet distances. These 2.4 GHz Radio modules are based on the Nordic Semiconductor nRF24L01+ chip. The Nordic nRF24L01+ integrates a complete 2.4GHz RF transceiver, RF synthesizer, and baseband logic including the Enhanced ShockBurst hardware protocol accelerator supporting a high-speed SPI interface. These low-power short-range modude have a built-in Antenna.

These transcevers use the 2.4 GHz unlicensed band like many WiFi routers, some cordless phones etc.These module send and receive data in 'packets' of several bytes at a time. There is built-in error correction and resending, and it is possible to have one unit communicate with up to 6 other similar units at the same time. The pinout as shown in diagram tha you can see in the photos and a table with the coneections to diferent models of arduinos.

*IMPORTANT* :These modules VCC connection must go to 3.3V not 5.0V

I will show an example of transmit and receive software below for one joystick:

Transmiter:

<p>/* <br>- WHAT IT DOES: Reads Analog values on A0, A1 and transmits
them over a nRF24L01 Radio Link to another transceiver.
1 - GND
2 - VCC 3.3V !!! NOT 5V
3 - CE to Arduino pin 9
4 - CSN to Arduino pin 10
5 - SCK to Arduino pin 13
6 - MOSI to Arduino pin 11
7 - MISO to Arduino pin 12
8 - UNUSED
- Analog Joystick:</p><p>GND to Arduino GND<br>VCC to Arduino +5V
X Pot to Arduino A0
Y Pot to Arduino A1
*/
/*-----( Import needed libraries )-----*/
#include <SPI.h></p><p>#include <nRF24L01.h></p><p>#include <RF24.h></p><p>/*-----( Declare Constants and Pin Numbers )-----*/<br>#define CE_PIN 9
#define CSN_PIN 10
#define JOYSTICK_X A0
#define JOYSTICK_Y A1</p><p>
// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
<br></p><p>/*-----( Declare objects )-----*/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
/*-----( Declare Variables )-----*/
int joystick[2]; // 2 element array holding Joystick readings</p><p>
void setup() /****** SETUP: RUNS ONCE ******/
{
     Serial.begin(9600);
     radio.begin();
      radio.openWritingPipe(pipe);
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
       joystick[0] = analogRead(JOYSTICK_X);
       joystick[1] = analogRead(JOYSTICK_Y);
       radio.write( joystick, sizeof(joystick) );
}//--(end main loop )--</p>

Receiver:

<p>/*<br>- WHAT IT DOES: Receives data from another transceiver with
2 Analog values from a Joystick
Displays received values on Serial Monitor
1 - GND
2 - VCC 3.3V !!! NOT 5V
3 - CE to Arduino pin 9
4 - CSN to Arduino pin 10
5 - SCK to Arduino pin 13
6 - MOSI to Arduino pin 11
7 - MISO to Arduino pin 12
8 - UNUSED</p><p>
/*-----( Import needed libraries )-----*/
#include <SPI.h></p><p>#include <nRF24L01.h></p><p>#include <RF24.h></p><p>/*-----( Declare Constants and Pin Numbers )-----*/<br>#define CE_PIN 9
#define CSN_PIN 10</p><p>
// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe</p><p>
/*-----( Declare objects )-----*/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio</p><p>
/*-----( Declare Variables )-----*/
int joystick[2]; // 2 element array holding Joystick readings</p><p>
void setup() /****** SETUP: RUNS ONCE ******/
{
    Serial.begin(9600);
    delay(1000);
    Serial.println("Nrf24L01 Receiver Starting");
    radio.begin();
    radio.openReadingPipe(1,pipe);
    radio.startListening();;
}//--(end setup )---</p><p>
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
   if ( radio.available() )
   { // Read the data payload until we've received everything
       bool done = false;
      while (!done)
      { // Fetch the data payload
           done = radio.read( joystick, sizeof(joystick) );
          Serial.print("X = ");
          Serial.print(joystick[0]);
          Serial.print(" Y = ");
          Serial.println(joystick[1]);
      }
  }
  else </p><p>  { </p><p>       Serial.println("No radio available");
  }
}//--(end main loop )---</p>

Step 16: Connecting the Joystick and the Linear Potentiometer:

To make the prototype of the controller I use a breadboard to connect everything. I have attached the boards of the joysticks and the linear potentiometer elastic bands jaja. I first thought of making a prototype with all elements before modifying a PS2 controller adding them the accelerometer, linear potentiometer, etc..

Simply connect the x,y GND and Vin terminals of both joystick to de 5v, GND, A0 and A1 pins of arduino. And the linear pot in the same way.

Step 17: How to Use the MMA7361 Accelerometer?:

It's a breakout board for Freescale’s MMA7361L three-axis analog MEMS accelerometer. The sensor requires a very low amount of power and has a g-select input which switches the accelerometer between ±1.5g and ±6g measurement ranges. Other features include a sleep mode, signal conditioning, a 1-pole low pass filter, temperature compensation, self test, and 0g-detect which detects linear freefall. Zero-g offset and sensitivity are factory set and require no external devices.

It's specifications are:

  • Supports 2.2V ~ 3.6V or 5V voltage input.
  • Two selectable measuring ranges (±1.5g, ±6g)
  • Breadboard friendly - 0.1" pitch header
  • Low current consumption: 400 µA
  • Sleep mode: 3 µA
  • Low voltage operation: 2.2 V - 3.6 V
  • High sensitivity (800 mV/g at 1.5g)
  • Fast turn on time (0.5 ms enable response time)
  • Self test for freefall detect diagnosis
  • 0g-Detect for freefall protection
  • Signal conditioning with low pass filter
  • Robust design, high shocks survivability

With the AcceleroMMA7361 library it's so easy to use this tiny module. The commands you can use with this library are:

  • void begin ()
  • void begin (int sleepPin, int selfTestPin, int zeroGPin, int gSelectPin, int xPin, int yPin, int zPin)
  • int getXRaw ()
    • getXRaw(): Returns the raw data from the X-axis analog I/O port of the Arduino as an integer
  • int getYRaw ()
    • getYRaw(): Returns the raw data from the Y-axis analog I/O port of the Arduino as an integer
  • int getZRaw ()
    • getZRaw(): Returns the raw data from the Z-axis analog I/O port of the Arduino as an integer
  • int getXVolt ()
    • getXVolt(): Returns the voltage in mV from the X-axis analog I/O port of the Arduino as a integer
  • int getYVolt ()
    • getYVolt(): Returns the voltage in mV from the Y-axis analog I/O port of the Arduino as a integer
  • int getZVolt ()
    • getZVolt(): Returns the voltage in mV from the Z-axis analog I/O port of the Arduino as a integer
  • int getXAccel ()
    • getXAccel(): Returns the acceleration of the X-axis as a int (1 G = 100.00)
  • int getYAccel ()
    • getYAccel(): Returns the acceleration of the Y-axis as a int (1 G = 100.00)
  • int getZAccel ()
    • getZAccel(): Returns the acceleration of the Z-axis as a int (1 G = 100.00)
  • void getAccelXYZ (int _XAxis, int _YAxis, int _ZAxis)
    • getAccelXYZ(int _XAxis, int _YAxis, int _ZAxis) returns all axis at once as pointers
  • int getTotalVector ()
    • getTotalVector returns the magnitude of the total acceleration vector as an integer
  • void setOffSets (int xOffSet, int yOffSet, int zOffSet)
  • void calibrate ()
  • void setARefVoltage (double _refV)
  • void setAveraging (int avg)
    • setAveraging(int avg): Sets how many samples have to be averaged in getAccel default is 10.
  • int getOrientation ()
  • void setSensitivity (boolean sensi)
    • setSensitivity sets the sensitivity to +/-1.5 G (HIGH) or +/-6 G (LOW) using a boolean HIGH (1.5 G) or LOW (6 G)
  • void sleep ()
    • sleep lets the device sleep (when device is sleeping already this does nothing)
  • void wake ()
    • wake enables the device after sleep (when device is not sleeping this does nothing) there is a 2 ms delay, due to enable response time (datasheet: typ 0.5 ms, max 2 ms)

The library have 3 simple examples. One gets the accelerations in each axis, the second gets the angle and the third the voltage. I used the "RawData" to get the angle of each axis othe controller to control the inclination:

<p>#include <AcceleroMMA7361.h></p><p>AcceleroMMA7361 accelero;
int x;
int y;
int z;
void setup()
{
    Serial.begin(9600);
    accelero.begin(8, 7, 6, 5, A5, A6, A7);
    accelero.setSensitivity(HIGH);//sets the sensitivity to +/-6G
    accelero.calibrate();
}</p><p>
void loop()
{
    x = accelero.getXRaw();
    y = accelero.getYRaw();
    z = accelero.getZRaw();
   Serial.print("\nx: ");
   Serial.print(x);
   Serial.print("\ty: ");
   Serial.print(y);
   Serial.print("\tz: ");
   Serial.print(z);
   delay(500); //(make it readable)
}</p>

Step 18: Put All Together:

All that remains is to place the accelerometer on the remote controller and connect it to the arduino nano as in the previous step.

Now it's time to program!!!

Step 19: Programming the Remote Controller:

Using all prior learning of each module only need to adapt the programs to the characteristics of the remote control by linking in two programs: one for the arduino remote control works as a transmitter and another program for arduino hexapod operates as a receiver.

According to the motion limits of the servos, that I got from my previous instructable, you must use the map command arduino to convert the values of the potentiometers and the accelerometer within the minimum limit range values of motion of the servos. Being as follows:

<p>values[0] = map(values[0], 23, 1000, 900, 1500); //Value from slider pot<br>values[1] = map(values[1], 23, 1000, 2100, 1540); //Value from slider pot
values[3] = map(values[3], 1, 1033, -295, 295); //Value from y-axis of right joystick
values[4] = map(values[4], 1, 1023, -295, 295); //Value from y-axis of left joystick
values[5] = map(values[5], 1, 1023, -360, 360); //Value from x-axis of left joystick
values[6] = map(values[6], 170, 500, -360, 360); //Value from x-axis of the accelerometer
values[7] = map(values[7], 170, 510, -360, 360); //Value from y-axis of the accelerometer</p>

Using one of the buttons on one of the joysticks I wanted to use the example shown on arduino page that consists in counting the number of times that a button is pressed to create various modes in which the hexapod will move.
http://arduino.cc/en/Tutorial/ButtonStateChange

<p>/* State change detection (edge detection)<br>This example shows how to detect when a button or button changes from off to on
and on to off.
*/
// this constant won't change:
const int buttonPin = 2; // the pin that the pushbutton is attached to
const int ledPin = 13; // the pin that the LED is attached to</p><p>// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button</p><p>void setup() {
   // initialize the button pin as a input:
   pinMode(buttonPin, INPUT);
   // initialize the LED as an output:
   pinMode(ledPin, OUTPUT);
   // initialize serial communication:
   Serial.begin(9600);
}</p><p>void loop() {
   // read the pushbutton input pin:
   buttonState = digitalRead(buttonPin);
   // compare the buttonState to its previous state
   if (buttonState != lastButtonState) {
   // if the state has changed, increment the counter
   if (buttonState == HIGH) {
   // if the current state is HIGH then the button
   // wend from off to on:
   buttonPushCounter++;
   Serial.println("on");
   Serial.print("number of button pushes: ");
   Serial.println(buttonPushCounter);
}
else {
   // if the current state is LOW then the button
   // wend from on to off:
   Serial.println("off");
 }
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
// turns on the LED every four button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (buttonPushCounter % 4 == 0) {
digitalWrite(ledPin, HIGH);
  } else {
   digitalWrite(ledPin, LOW);
  }
}</p>

I convert this example and adapt to my sketchs of the remote controller and to the receptor. So
So I create three modes of movements:

  • The first one allows the linear potentiometer and joysticks move the hexapod
  • The second allows joysticks, the potentiometer and accelerometer move the hexapod
  • And the last mode let move hte hexapod walk, walk backwards,etc moving the two joystick simultaneously