Introduction: Obstacle Avoidance Car

About: just a dude who loves circuitry, astromomy and mechanical engineering

This is a simple, yet easy and fun to make robotics project. it features an Arduino connected to 2 little n20 motors, (they only draw between 15 t0 20ma, so it is safe) an ultrasonic sensor (HC-SR04) housed in a 3d printed body (u can use anything it doesn't matter :) . It is powered by 2 1200mah cells and the motors are connected to n20 wheels. you can also put on a castor wheel, as in this case i used an n20 castor wheel. it doesn't require a motor driver which might be a big relief to you since every other obstacle avoidance car uses a motor driver and 80% percent of the people dont have that.

Supplies

  1. n20 castor wheel
  2. ultrasonic sensor
  3. structure for robot
  4. 2x 3.7v li-ion cells (16046)
  5. li-ion cell holder with barrel jack
  6. Arduino uno
  7. n20 wheel
  8. n20 motor 6v 150 rpm (geared)

Step 1:

  1. connect the the vcc of the ultrasonic sensor to the 5v of arduino
  2. connect trig of the sensor to pin 2
  3. connect echo of the sensor to pin 3
  4. connect gnd of the sensor to gnd of the arduino

Step 2:

  1. connect the positive terminal of the left motor to pin 12
  2. connect the negative terminal of the left motor to pin 8
  3. connect the positive terminal of the right motor to A1
  4. connect the negative terminal of the right motor to A0

Step 3:

the code-




// C++ code

//

int distance = 0;


long readUltrasonicDistance(int triggerPin, int echoPin)

{

pinMode(triggerPin, OUTPUT); // Clear the trigger

digitalWrite(triggerPin, LOW);

delayMicroseconds(2);

// Sets the trigger pin to HIGH state for 10 microseconds

digitalWrite(triggerPin, HIGH);

delayMicroseconds(10);

digitalWrite(triggerPin, LOW);

pinMode(echoPin, INPUT);

// Reads the echo pin, and returns the sound wave travel time in microseconds

return pulseIn(echoPin, HIGH);

}


void setup()

{

pinMode(8, OUTPUT);

pinMode(12, OUTPUT);

pinMode(A0, OUTPUT);

pinMode(A1, OUTPUT);

}


void loop()

{

if (0.01723 * readUltrasonicDistance(2, 3) < 25) {

digitalWrite(8, LOW);

digitalWrite(12, LOW);

digitalWrite(A0, LOW);

digitalWrite(A1, LOW);

delay(1000); // Wait for 1000 millisecond(s)

digitalWrite(8, LOW);

digitalWrite(12, LOW);

digitalWrite(A0, LOW);

digitalWrite(A1, HIGH);

delay(2000); // Wait for 2000 millisecond(s)

} else {

digitalWrite(8, LOW);

digitalWrite(12, HIGH);

digitalWrite(A0, HIGH);

digitalWrite(A1, LOW);

delay(2000); // Wait for 2000 millisecond(s)

}

}








the file attachment is below:)

Attachments