Go Down

Topic: roaming tank (Read 822 times) previous topic - next topic

invad8er

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

oric_dan

What needs to be modified?

invad8er

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?

codlink

#3
Nov 12, 2012, 03:51 am Last Edit: Nov 12, 2012, 03:55 am by codlink Reason: 1

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: [Select]
#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);
}
//LiNK

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy