Posted on

Robot 4WD Roboromania autonom ocolire obstacole realizat de MERS Robotica pentru copii – Mihai Dascăliuc – Constanţa

Robot 4WD Roboromania autonom ocolire obstacole realizat de MERS Robotica pentru copii – Mihai Dascăliuc

MERS Robotica pentru copii – Constanţa  https://www.facebook.com/roboticaconstanta/

default_comp26

3214wd2wd

Aveti nevoie de :
o Placă de dezvoltare tip Arduino UNO (oricare)
un Modul driver motoare L293D
un Senzor cu ultrasunete HCSR04
un Kit șasiu 4WD
cabluri Dupont

Modul driver motoare L293D este shield si nu aveți cum să greșiți pinii

Codul (sau download) :

// Robot 4WD autonom ocolire obstacole – „MERS Robotica pentru copii” – Mihai Dascaliuc

#include <AFMotor.h> //import your motor shield library
#define trigPin A0 // define the pins of your sensor
#define echoPin A1
AF_DCMotor motor1(1,MOTOR12_64KHZ); // set up motors.
AF_DCMotor motor2(2, MOTOR12_8KHZ);
AF_DCMotor motor3(3, MOTOR12_8KHZ);
AF_DCMotor motor4(4, MOTOR12_8KHZ);

void setup() {
Serial.begin(9600); // begin serial communitication
Serial.println(„Motor test!”);
pinMode(trigPin, OUTPUT);// set the trig pin to output (Send sound waves)
pinMode(echoPin, INPUT);// set the echo pin to input (recieve sound waves)
motor1.setSpeed(200); //set the speed of the motors, between 0-255
motor2.setSpeed (200);
motor3.setSpeed (200);
motor4.setSpeed (200);
}

void loop() {

long duration, distance; // start the scan
digitalWrite(trigPin, LOW);
delayMicroseconds(2); // delays are required for a succesful sensor operation.
digitalWrite(trigPin, HIGH);

delayMicroseconds(10); //this delay is required as well!
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;// convert the distance to centimeters.
if (distance < 40)/*if there’s an obstacle 25 centimers, ahead, do the following: */ {
Serial.println(„Close Obstacle detected!” );
Serial.println(„Obstacle Details:”);
Serial.print(„Distance From Robot is ” );
Serial.print( distance);
Serial.print( ” CM!”);// print out the distance in centimeters.

Serial.println(” The obstacle is declared a threat due to close distance. „);
Serial.println(” Turning !”);
motor1.run(FORWARD); // Turn as long as there’s an obstacle ahead.
motor2.run(FORWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
} else {
Serial.println(„No obstacle detected. going forward”);
delay (15);
motor1.run(FORWARD); //if there’s no obstacle ahead, Go Forward!
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
}
}

filmuleț realizat de MERS Robotica pentru copii – Constanţa

Succes!