Go Down

Topic: Line Follower-Gate Pass (Read 289 times) previous topic - next topic

HalilSenn

Hi guys. I'm working on an Arduino Car project that can follow line and detect obstacles. My car can follow the line, there is no problem up to here. But I have some problem about detect obstacle. Because the obstacles are always moving periodically up and down, non stop. Here is my codes;

#define SensorSol 4 //left sensor

#define echoPin 12

#define trigPin 11

#define SensorSag 2 //right sensor

long sure, uzaklik; //duration, distance

#define MotorR1 9

#define MotorR2 8

#define MotorRE 10

#define MotorL1 7

#define MotorL2 6

#define MotorLE 5

void setup() {

pinMode(echoPin, INPUT);

pinMode(trigPin, OUTPUT);

pinMode(SensorSol, INPUT);

pinMode(SensorSag, INPUT);

pinMode(MotorR1, OUTPUT);

pinMode(MotorR2, OUTPUT);

pinMode(MotorRE, OUTPUT);

pinMode(MotorL1, OUTPUT);

pinMode(MotorL2, OUTPUT);

pinMode(MotorLE, OUTPUT);

Serial.begin(9600);

}

void loop() {

digitalWrite(trigPin, LOW);

delayMicroseconds(5);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

sure = pulseIn(echoPin, HIGH);

uzaklik = (sure / 2) / 29.1 ;

Serial.print("uzaklik: ");

Serial.println(uzaklik);

if (uzaklik > 5 ) {

if(digitalRead(SensorSol) == 0 && digitalRead(SensorSag) == 0){

ileri();

}

if(digitalRead(SensorSol) == 0 && digitalRead(SensorSag) == 1){

sag();

}

if(digitalRead(SensorSol) == 0 && digitalRead(SensorSag) == 0){

ileri();

}

if(digitalRead(SensorSol) == 1 && digitalRead(SensorSag) == 0){

sol();

}

if(digitalRead(SensorSol) == 0 && digitalRead(SensorSag) == 0){

ileri();

}

}

if (uzaklik < 5){

dur();

delay(500);

//HERE IS THE PROBLEM??? HOW CAN I DO??

//check the distance (the moment when the distance>5 suddenly);

//void pass;

//delay(1000);

//void stop

//delay(500);

//turn back void move forward;

}

}

void ileri(){ // move forward

digitalWrite(MotorR1, HIGH);

digitalWrite(MotorR2, LOW);

analogWrite(MotorRE, 60);

digitalWrite(MotorL1, HIGH);

digitalWrite(MotorL2, LOW);

analogWrite(MotorLE, 80);

}

void sag(){ //right

digitalWrite(MotorR1, HIGH);

digitalWrite(MotorR2, LOW);

analogWrite(MotorRE, 0);

digitalWrite(MotorL1, HIGH);

digitalWrite(MotorL2, LOW);

analogWrite(MotorLE, 80);

}

void sol(){ //left

digitalWrite(MotorR1, HIGH);

digitalWrite(MotorR2, LOW);

analogWrite(MotorRE, 80);

digitalWrite(MotorL1, HIGH);

digitalWrite(MotorL2, LOW);

analogWrite(MotorLE, 0);

}

void dur(){ // stop

digitalWrite(MotorR1, HIGH);

digitalWrite(MotorR2, LOW);

analogWrite(MotorRE, 0);

digitalWrite(MotorL1, HIGH);

digitalWrite(MotorL2, LOW);

analogWrite(MotorLE, 0);

}

void gec(){ //pass obstacle

digitalWrite(MotorR1, HIGH);

digitalWrite(MotorR2, LOW);

analogWrite(MotorRE, 250);

digitalWrite(MotorL1, HIGH);

digitalWrite(MotorL2, LOW);

analogWrite(MotorLE, 250);

}

Or can I do this with MZ80? Which one is better, Mz80 or HCSR04 to pass the moving gates?
Because my car must pass the gate at the first moment when there is no obstacle. Is it possible to count the close and open gate numbers and after last one, passing the gate with Mz80?

Here is the video about my project.
https://www.youtube.com/watch?v=ZllwboOxNFE

LightuC

#1
Apr 14, 2019, 01:49 pm Last Edit: Apr 14, 2019, 03:16 pm by LightuC
First of, when you post code use code-tags. It is the </> button in the top left corner.

Hi guys. I'm working on an Arduino Car project that can follow line and detect obstacles. My car can follow the line, there is no problem up to here. But I have some problem about detect obstacle. Because the obstacles are always moving periodically up and down, non stop. Here is my codes;
What kind of problems do you have? Describe them, along with everything you tried so far.

Or can I do this with MZ80? Which one is better, Mz80 or HCSR04 to pass the moving gates?
Because my car must pass the gate at the first moment when there is no obstacle. Is it possible to count the close and open gate numbers and after last one, passing the gate with Mz80?
I couldn't find any information about the MZ80 sensor, but the HC-SR04 should do. You could drive near the gate everytime your sensor detects the gate. If nothing is detected you don't move. If you have reached a good distance to the gate (during the time it is closed) you can wait for the next time it closes. As soon as it opens again you drive through the gate, done.

Go Up