Let's Make Robots!

mini tank


hello everyone im in the middle of making a robot which uses an arduino and an ultra sonic sensor (clone of ping so it has the same pinouts) ive got the robot and i have a code but the code has servos an one of my servos just broke so i was wondering if it was possible to convert this code to a code that uses dc motors ive tried this a couple times but i havent had any luck heres i tried pasting my current code but i just ended landscape format?? first is this code even correct and can i change it to one that uses dc motors?also might i need a motor shield im pretty sure mines busted. and one last thing which pins on the arduino do i connect the motors to? ive looked online with no useful information thanks alot

hello again heres a little update since chuckcrunch is making a robot like mine but his has a servo i put one on mine too also ive got my motor shield

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

This is a very cool looking, tidy little bot!

I like how it looks! :D Looking forward to see a video and more pics!

/*
 //R293D2
 
 
 this is the code is to run a little rodot it just has 2 sensers
 
 This example code is in the public domain.
 
 */
 #include <Servo.h>
 Servo myservo; 
               
 
int pos = 0;    // variable to store the servo position
 
 const int pingPin = 6;
int val = 0;    //  l293d
int val2 = 0;
int val3 = 0;
int val4 = 0;
int val5 = 0;
int val6 =0;
int bob = 0;
int bob2 =0;
void setup() 
{
  // output's for 293d
  myservo.attach(9);
  pinMode(11,OUTPUT);// enable pin left
  pinMode(10,OUTPUT);// enable pin  right
  pinMode(8,OUTPUT);//left REV
  pinMode(7, OUTPUT);//left Fwd
  pinMode(2, OUTPUT);//right rev
  pinMode(4, OUTPUT);//right fwd
  Serial.begin(9600);

}
//MAIN LOOP TRY TO KEEP SIMPLE
void loop(){
  long duration, inches, cm;
  for(pos = 0; pos < 20; pos += 2){
  myservo.write(50);              // tell servo to go to position in variable 'pos'
    delay(20);                       // waits 15ms for the servo to reach the position
  }
 
  PING();
   val = val4;
    for(pos = 0; pos<=20; pos+=2){
     myservo.write(90);              // tell servo to go to position in variable 'pos'
  delay(20);  
}

PING();
val2 = val4;
  for(pos = 0; pos<=20; pos+=2){
    myservo.write(130);              // tell servo to go to position in variable 'pos'
   delay(20);  


PING();
val3 = val4;
 for(pos = 0; pos<=20; pos+=2){
    myservo.write(90);              // tell servo to go to position in variable 'pos'
 delay(20);  
}
PING();
val2 = val4;


// waits // waits 15ms for the servo to reach the position
if (val < 10 ){
  FWD_R(200);
  REV_L(255);
     } else{ if (val3 < 10   ){
              FWD_L(200);
              REV_R(255);
              }else{ if (val2 < 10 ){
                         REV_L(200);
                         REV_R(200);
                       }else{if (val2>  10 ){FWD_R(255);FWD_L(255);}}}}
             
 

}




 void PING()
 {
    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);

  // convert the time into a distance
  cm = microsecondsToCentimeters(duration);
  val4 = cm;
 }
  
long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}





void YELD_LR()
{
  digitalWrite(2,LOW);
  digitalWrite(4,LOW);
  digitalWrite(7,LOW);
  digitalWrite(8,LOW);
}

void REV_L(uint8_t rsp)
{
  analogWrite(10,rsp);
  digitalWrite(2,LOW);
  digitalWrite(4,HIGH);
}

void FWD_L(uint8_t rsp)
{
  analogWrite(10,rsp);
  digitalWrite(4,LOW);
  digitalWrite(2,HIGH);
}

void REV_R(uint8_t rsp)
{
  analogWrite(11,rsp);
  digitalWrite(8,LOW);
  digitalWrite(7,HIGH);
}

void FWD_R(uint8_t rsp)
{
  analogWrite(11,rsp);
  digitalWrite(7,LOW);
  digitalWrite(8,HIGH);
}

last time i checked i couldnt find any ill just look harder also one more thing what batteries should i use voltage wise. im going to use i was thinking 2 AA for the arduino and a 10v rechargable for the motors i want this robot to  have moderate speed ive seen really cool robots on this site but there all pretty slow so any suggestions?

the ardunio needs at least 6 volts up to 12v the power reg requiers it

i should be done by wendesday if i dont get a lot of homework also i would like more of your code thanks you can email me or just post it here

i put up a snipit of my coad if you need more of it just ask most of the coad is cut and pasted out of the examples on the arduino program my coading is not the best

as well as mounting the arduino do you know if theres a place i can get standoffs without ordering online? i would have this robot up and runnning but im really bad at writing code so im waitng to see chuckcrunch's version and ask him for his code. once i have this robot up and running im going to buy some recharbale batteries i hope this will be the first robot tthat accualy works :)

on how i can mount my arduino to the robot? maybe how did you do yours?