Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Divyanshu Prakash
Published

Obstacle avoidance robot

This is a simple diagram of how a Obstacle avoidance robot works.

BeginnerShowcase (no instructions)1 hour124
Obstacle avoidance robot

Things used in this project

Hardware components

Breadboard (generic)
Breadboard (generic)
×1
Acutronic Robotics aurdino uno r3
×1
Micro Metal Gearmotor to LEGO® Axle Adaptor (pack of 4)
Pimoroni Micro Metal Gearmotor to LEGO® Axle Adaptor (pack of 4)
×2
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1

Software apps and online services

Tinkercad
Autodesk Tinkercad

Story

Read more

Schematics

Obstacle avoidance robot diagram

Follow the connections correctly

Code

Obstacle avoidance robot code

C/C++
// C++ code
//
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(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
}

void loop()
{
  if (0.01723 * readUltrasonicDistance(7, 6) < 10) {
    digitalWrite(8, LOW);
    digitalWrite(9, HIGH);
    digitalWrite(10, HIGH);
    digitalWrite(11, LOW);
  } else {
    digitalWrite(8, HIGH);
    digitalWrite(9, LOW);
    digitalWrite(10, HIGH);
    digitalWrite(11, LOW);
  }
  delay(10); // Delay a little bit to improve simulation performance
}

Credits

Divyanshu Prakash
1 project • 0 followers

Comments