Pages: [1]   Go Down
Author Topic: roaming tank  (Read 649 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK so i am kind of new to this ,
so far i have constructed the tank in the pic below
components:
Audrino mega
motor shield (added heat sync)
4 ping (parallax)
servo
2 motors (3V i think)

I looked over several sketches for Wandering with ping but still confused on how to modify for current hardware


* Picture 1.jpg (95.32 KB, 640x480 - viewed 22 times.)
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What needs to be modified?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can  get it  to  spit out  ranges  from the sensors
however i  am unsure of how to  get  it  to  change directions based on ranges
or is it that i should us  IF statements?
Logged

USA, FL
Offline Offline
God Member
*****
Karma: 14
Posts: 686
A life? Where can I download one of those?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can  get it  to  spit out  ranges  from the sensors
however i  am unsure of how to  get  it  to  change directions based on ranges
or is it that i should us  IF statements?

"if" statements are the easiest way.  Take a look at a sketch that I did with Ping sensor and servos.

I also recommend the "NewPing" library.
Download  
Documentation

Code:
#include <Servo.h>

#define trigPin 8
#define echoPin 9
Servo righteyelid;
Servo lefteyelid;
int pos = 0;

void setup() {
  Serial.begin (9600);
  righteyelid.attach(50);
  lefteyelid.attach(52);
  pinMode(trigPin,OUTPUT);
}

void loop() {
  int duration, distance;
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  if (distance <= 10)
  {
    //Serial.print(distance);
    Serial.println("servo on");
    righteyelid.write(65);
    lefteyelid.write(135);
  }
  
  else {
    Serial.print(distance);
    Serial.println(" cm");
    righteyelid.write(95);
    lefteyelid.write(96);
    
  }
  delay(5);
}
« Last Edit: November 11, 2012, 09:55:54 pm by codlink » Logged

//LiNK

Pages: [1]   Go Up
Jump to: