loading

Step 6: Arduino Sketch and Mohawk

The mohawk: Take the 3" in. paint brush and crazyglue, pour it at about 1 1/4" in. from the end of the brush. Soak both sides (wear some gloves) and let it dry for 20 min.. Once dried cut 1 1/2" off the end of the brush, now take that piece and glue it to the head using a pvc cement or any other plastic glue.

Plug your Arduino to your computer download the sketch below. Congratulations you have finish building the TurtleDuino.

// TurtleDuino Obstacles Avoiding Robot By:RobDavinci
#include <Servo.h> //include Servo library
const int RForward = 0;
const int RBackward = 180;
const int LForward = RBackward;
const int LBackward = RForward;
const int RNeutral = 90;
const int LNeutral = 90; //constants for motor speed
const int pingPin = 7;
const int irPin = 0;  //Sharp infrared sensor pin
const int dangerThresh = 10; //threshold for obstacles (in cm)
int leftDistance, rightDistance; //distances on either side
Servo panMotor; 
Servo leftMotor;
Servo rightMotor; //declare motors
long duration; //time it takes to recieve PING))) signal

void setup()
{
  rightMotor.attach(11);
  leftMotor.attach(10);
  panMotor.attach(6); //attach motors to proper pins
  panMotor.write(90); //set PING))) pan to center
}

void loop()
{
  int distanceFwd = ping();
  if (distanceFwd>dangerThresh) //if path is clear
  {
    leftMotor.write(LForward);
    rightMotor.write(RForward); //move forward
  }
  else //if path is blocked
  {
    leftMotor.write(LNeutral);
    rightMotor.write(RNeutral);
    panMotor.write(0);
    delay(500);
    rightDistance = ping(); //scan to the right
    delay(500);
    panMotor.write(180);
    delay(700);
    leftDistance = ping(); //scan to the left
    delay(500);
    panMotor.write(90); //return to center
    delay(100);
    compareDistance();
  }
}
 
void compareDistance()
{
  if (leftDistance>rightDistance) //if left is less obstructed
  {
    leftMotor.write(LBackward);
    rightMotor.write(RForward); //turn left
    delay(2000);
  }
  else if (rightDistance>leftDistance) //if right is less obstructed
  {
    leftMotor.write(LForward);
    rightMotor.write(RBackward); //turn right
    delay(2000);
  }
   else //if they are equally obstructed
  {
    leftMotor.write(LForward);
    rightMotor.write(RBackward); //turn 180 degrees
    delay(2000);
  }
}

long ping()
{
  // Send out PING))) signal pulse
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);
 
  //Get duration it takes to receive echo
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);
 
  //Convert duration into distance
  return duration / 29 / 2;
}

I hope this instructable was fun to you as it was for me while building it. If you need additional help let me know and I'll be more than happy to help you build your robot.
 

Hi I know this is very late but in your sketch you showed an ir sensor and you used a 4-pin ultrasonic sensor. Does this make a difference?
<p>Hy! Is there any problem if instead of arduino uno I use Due? Thanks in advance.</p>
I noticed you modified the front suspension. I'm assuming that was due to turning issues from the original design. I'm building a similar robot with my son. We are still in the initial design phase and I'm foreseeing turning issues once we begin production. What did you do to fix this issue?
Hi, I wanted to make turtleduino, how much does it cost I mean details.
$70.00 in electronic components. And at about $20 in material.
Hi, I started on a project using IR sensors but for some reason my servos only keep moving forward even if the sensor detects an object ahead. I checked the code and it seems to be fine. the connections are according to the codes. so im not quite sure whats going on there. any ideas? <br>Here is the code if anyone can see anything wrong please let me know. <br> <br> <br>#include // Include servo library <br> <br>Servo servoLeft; // Declare left and right servos <br>Servo servoRight; <br> <br>void setup() // Built-in initialization block <br>{ <br> pinMode(10, INPUT); pinMode(9, OUTPUT); // Left IR LED &amp; Receiver <br> pinMode(3, INPUT); pinMode(2, OUTPUT); // Right IR LED &amp; Receiver <br> <br> tone(4, 3000, 1000); // Play tone for 1 second <br> delay(1000); // Delay to finish tone <br> <br> servoLeft.attach(13); // Attach left signal to pin 13 <br> servoRight.attach(12); // Attach right signal to pin 12 <br>} <br> <br>void loop() // Main loop auto-repeats <br>{ <br> <br> int irLeft = irDetect(9, 10, 38000); // Check for object on left <br> int irRight = irDetect(2, 3, 38000); // Check for object on right <br> <br> if((irLeft == 0) &amp;&amp; (irRight == 0)) // If both sides detect <br> { <br> maneuver(-200, -200, 20); // Backward 20 milliseconds <br> } <br> else if(irLeft == 0) // If only left side detects <br> { <br> maneuver(200, -200, 20); // Right for 20 ms <br> } <br> else if(irRight == 0) // If only right side detects <br> { <br> maneuver(-200, 200, 20); // Left for 20 ms <br> } <br> else // Otherwise, no IR detects <br> { <br> maneuver(200, 200, 20); // Forward 20 ms <br> } <br>} <br> <br>int irDetect(int irLedPin, int irReceiverPin, long frequency) <br>{ <br> tone(irLedPin, frequency, 8); // IRLED 38 kHz for at least 1 ms <br> delay(1); // Wait 1 ms <br> int ir = digitalRead(irReceiverPin); // IR receiver -&gt; ir variable <br> delay(1); // Down time before recheck <br> return ir; // Return 1 no detect, 0 detect <br>} <br> <br>void maneuver(int speedLeft, int speedRight, int msTime) <br>{ <br> // speedLeft, speedRight ranges: Backward Linear Stop Linear Forward <br> // -200 -100......0......100 200 <br> servoLeft.writeMicroseconds(1500 + speedLeft); // Set left servo speed <br> servoRight.writeMicroseconds(1500 - speedRight); // Set right servo speed <br> if(msTime==-1) // if msTime = -1 <br> { <br> servoLeft.detach(); // Stop servo signals <br> servoRight.detach(); <br> } <br> delay(msTime); // Delay for msTime <br>}
Is there a circuit diagram for this project?
Hello timgordon, here is a Fritzing diagram, I hope it helps. (step8)
No, but I'll upload one soon.
i can hear the electricity from motor but it doesn't drive. <br>the servo motor also just repeat turn left and right and forward.
Check all your ground wires. All ground wires should be connected together, including the one from the arduino ground pin. Also, use another power source to drive your motors do not use the arduino.Two power source one for the Arduino and one for your motors.
the codes are not completed, right?
The code is complete.
i have try the codes but seems that the motor doesn't work as expect.
I am going to load the code to a similar project I'm working on and see what happens. what happens to the motor? and which motor? Do they (motors) turn to the same direction?
i have try the codes but seems that the motor doesn't work as expect.
That is freaking adorable.
I'm glad you find it adorable, I had a hard time deciding whether the mohawk will make it look good or kind of cheesy. But like Megaduty wrote the mohawk gave the Turtlrduino some style.
the drive wheels been in the middle with a little stump at back and front to allow a little bit of tipping would work much better
That's a good idea, that would it make it more interesting.
That bot's got style! Voted for ya!
Thank you for voting.
I once made a codpeice out of the part you used for the shell! nice job! :)
thank you!
Yeah only a couple hundred dollars
Yes, Marvin The Martian. I got the idea from Dan M. in letsmakerobot.com blog. <br>Don't foget to vote for TurtleDuino in the Arduino contest. Thank you.
WOW!!! Great project! The Mohawk brush on top adds a comical flare to the TurtleDuino. It reminds me of a robot type that &quot;Marvin The Martian&quot; would have takes me back to by childhood and Bugs Bunny.

About This Instructable

22,771views

113favorites

License:

More by robdavinci:R/C Car Drag Racing Lights Motorized Evil Shield Powered Breadboard Workstation 
Add instructable to: