loading
In this instruct able, I will show you how to transform a normal hex bug spider, to an intelligent robot with sensors on it.




Step 1: Parts and Materials

Parts :

(1) a Hex bug spider
(2) A Ping ultrasonic distance sensor
(3) a prototyping Arduino shield 
(4) An Arduino uno
(5) 9 volt battery clip
(6) a 9 volt battery

Materials : 

(1) Hot glue gun
(2) Hot glue sticks
(3) Soldering iron
(4) solder
(5) Screw driver
(6) A computer
(7) a usb connection between Arduino and computer


Step 2: Step 1 : Connecting Wires

The first thing that you will have to do, will be unscrewing the top of the hex bug, taking the batteries out and cutting off the controller for the hex bug( the one with an IC on the back and in the front). You will be left with 4 wires, 2 white ones and 2 black ones. Solder a jumper wire to each of them. As you can see, each motor has two wires coming out of it ( white - positive and black - ground), make sure not to mix up the motor wires.

Step 3: Step 2 : Adding the Protoshield to the Arduino

Next, you will add the arduino uno, with its proto shield onto of it.

Step 4: Step 3 : Putting the Wires Into Place

Make sure to leave the wires from one motor hang on one side and wires from the other motor hang on the other.

Step 5: Step 4 : Hot Gluing

Next, you will hot glue the Arduino, together with its protoshield, to the hex bug. Make sure not to cover up the gears.

Step 6: Step 5 : Wiring Up the Pins to the Arduino

First, add power to both motors, to see which one is the one used to push the legs forward. When you have found out which one it is, plug the white one into 5v and the black one into ground( for a test walk without any sensors). 

Step 7: Step 6 : Knowing What to Do With the Other Two Wires

Now,  with the other two wires that you have remaining, the possibilities are limitless. You could add any sensor you wanted and just write the code for it, so that when it detects something, it rotates its head, causing the hex bug to move in a different direction. In the next step, I will show you how to incorporate an ultrasonic distance sensor as the input.

Step 8: Step 7 : the Wiring From Arduino to Sensor and Motor

Ping pin goes to pin 7, motor pin goes to pin 13

Step 9: Step : 8 Finally, the Code

const int pingPin =7 ;
const int ledPin = 13;

void setup() {
    Serial.begin(9600);
    pinMode(ledPin, OUTPUT);
}

void loop() {
    long duration, inches, cm;

    pinMode(pingPin,OUTPUT);
    digitalWrite(pingPin,LOW);
    delayMicroseconds(2);
    digitalWrite(pingPin,HIGH);
    delayMicroseconds(5);
    digitalWrite(pingPin,LOW);

    pinMode(pingPin,INPUT);
    duration =pulseIn(pingPin,HIGH);

    inches = microsecondsToInches(duration);
    cm = microsecondsToCentimeters(duration);

    Serial.print(inches);
    Serial.print("in, ");
    Serial.print(cm);
    Serial.print("cm");
    Serial.println();
    delay(100);

    
        if (inches <= 12) {
            digitalWrite(ledPin, HIGH);
            alarm();
        }
        else {
            digitalWrite(ledPin, LOW);
        }
    }


long microsecondsToInches(long microseconds)
{
    return microseconds /74/2;
}

long microsecondsToCentimeters(long microseconds)
{
    return microseconds /29/2;
}


void alarm() {
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);
  delay(500);
}

Step 10: The Finished Product

Now as you can see at the end, sometimes the motors make weird sounds, which means that it cannot support all of the weight so you might want think about putting  solar panel onto it or just switching to a lithium battery. 

Step 11: Have Fun

Have fun and start experimenting what would happen with different sensors.

About This Instructable

7,512views

52favorites

License:

More by arduino 123:Hex Bug spider with a brain (autonomous robot) Valentines Day Motion Activated LED Heart Light activated LED 
Add instructable to: