Go Down

Topic: Help on programing a 2wd smart car robot chassis obstacle avoidance sensor (Read 5651 times) previous topic - next topic

Arudino1901

Right now I had gotten the car to turn in a endless oval, but sometimes it bumps into things I would like it to avoid it and start the oval again somewhere else, and if it finds something in the way again, it avoids it and starts the oval again. Again I have already programed it in a endless oval, and I need to know how to program the sensors. Here is my coding so far, there is no errors in this code. I am using a hc-sr04 obstacle avoidance sensor.

Code: [Select]
// you need this so you can use the adafruit motor shield library:
#include <AFMotor.h>

// this created our first motor (called "motor") on port 3 of the motorshield:
AF_DCMotor motor(3);  

// we do it again, this time our second motor will be called "motor2" on port
// 4 of the motorshield:
AF_DCMotor motor2(4);
// so now we have 2 motors called "motor" and "motor2"

void setup() {
Serial.begin(9600);           // set up Serial library at 9600 bps
Serial.println("Motor test!");

}

void loop() {
{ Serial.print("tick");

motor.setSpeed(255);
motor2.setSpeed(255);


motor.run(FORWARD);      // turn it on going forward
motor2.run(BACKWARD);  // motor 2 goes forward as well
delay(2000);

}
motor.run(RELEASE);
motor2.run(RELEASE);
delay(500);
{
 motor.setSpeed(255);
 motor2.setSpeed(90);
 
 Serial.print("tack");
motor.run(FORWARD);  
motor2.run(BACKWARD);
delay(850);
}
motor.run(RELEASE);
motor2.run(RELEASE);
delay(500);


{Serial.print("tock");
motor.setSpeed(255);
motor2.setSpeed(255);

motor.run(FORWARD);     // the other way
motor2.run(BACKWARD);  //again for motor 2
delay(2000);
}
motor.run(RELEASE);
motor2.run(RELEASE);
delay(500);

{
motor.setSpeed(255);
motor2.setSpeed(90);
 
 Serial.print("tack");
motor.run(FORWARD);      // stopped
motor2.run(BACKWARD);  // command motor 2 to stop
delay(850);
}
motor.run(RELEASE);
motor2.run(RELEASE);
delay(500);
}

TomGeorge

Hi, could you read this please ,it will show you how to post your sketch in your post, using code tags, so it can be read easily.

http://forum.arduino.cc/index.php/topic,148850.0.html

Thanks..Tom........ :)
Everything runs on smoke, let the smoke out, it stops running....

PaulS

Quote
I need to know how to program the sensors.

You can't. What the sensors can do is designed into them at the hardware level.

What you can do is read the sensors. How you do that depends on the type of sensor.

Quote
I am using a sunfounder obstacle avoidance sensor

This is nonsense. You might have an obstacle detection sensor. You use the data from it to avoid obstacles.
The art of getting good answers lies in asking good questions.

TomGeorge

Hi

http://www.amazon.com/SunFounder-Obstacle-Avoidance-Arduino-Mega2560/dp/B00GD5426Y

Quote
Product Description
Parameter:

1. When the module detects an obstacle in front of the signal, the circuit board green indicator light levels while continuing output low signal OUT port, the module detects the distance 2 ~ 30cm, detection angle 35 °, the distance can detect potential control to adjust, adjust potentiometer clockwise, the detection distance increases; counterclockwise adjustment potentiometer, detection distance decreases.
2. the sensor active infrared reflection detection, target reflectivity and shape of the detection distance of the key. The minimum detection distance which black and white max; small area of the object distance is small, a large area from the Grand.
3. the sensor module output port OUT can be directly connected with the microcontroller IO port can also be driven directly to a 5V relay; Connection: VCC-VCC; GND-GND; OUT-IO
4. the comparator using LM393, job stability;
5. can be 3-5V DC power supply for the module. When the power is turned on, the red power indicator light;
6. with 3mm screw holes for easy mounting, installation;
7. the circuit board size: 3.2CM * 1.4CM
8. each module in the delivery has threshold comparator voltage adjustable via potentiometer, special circumstances, please do not adjust the potentiometer.


Looks like it is an IR reflective sensor, digital output, level adjustment on board.

Tom.... :)
Everything runs on smoke, let the smoke out, it stops running....

Arudino1901


Hi, could you read this please ,it will show you how to post your sketch in your post, using code tags, so it can be read easily.

http://forum.arduino.cc/index.php/topic,148850.0.html

Thanks..Tom........ :)


I have no error or coding problems in the code above

TomGeorge

Hi,1901, I'm not criticising your code, its that there is a specific way to present it in your post.
If you look at other subjects you will see that code has a special frame and scrolling.
Also in your IDE select TOOLS then AUTO FORMAT and it will indent the { and } to make it easier to follow.
As I said I'm not criticising your code, just how it is presented.

If you read this link it will tell you how.

http://forum.arduino.cc/index.php/topic,148850.0.html

Tom..... :)
Everything runs on smoke, let the smoke out, it stops running....

Arudino1901

Quote
I am using a sunfounder obstacle avoidance sensor

This is nonsense. You might have an obstacle detection sensor. You use the data from it to avoid obstacles.
[/quote]

I am sorry I had confusion with another sensor I used.
This is hc-sr04 obstacle avoidance sensor. Again sorry for the confusion

Arudino1901


Hi,1901, I'm not criticising your code, its that there is a specific way to present it in your post.
If you look at other subjects you will see that code has a special frame and scrolling.
Also in your IDE select TOOLS then AUTO FORMAT and it will indent the { and } to make it easier to follow.
As I said I'm not criticising your code, just how it is presented.

If you read this link it will tell you how.

http://forum.arduino.cc/index.php/topic,148850.0.html

Tom..... :)


There I had finished editing my code. I hope it is easier to understand and read now
Thanks

Go Up