yatin_7
Published © GPL3+

Obstacle avoiding robot(without motor driver)

The most common project using Arduino but in a complicated way by not using any sort of motor drivers!!!.

BeginnerFull instructions provided1,438
Obstacle avoiding robot(without motor driver)

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
MOSFET Transistor, Switching
MOSFET Transistor, Switching
2 nos- for each motors
×2
Rover setup
×1
Jumper wires (generic)
Jumper wires (generic)
×1
9V battery (generic)
9V battery (generic)
×2

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Soldering iron (generic)
Soldering iron (generic)
Cardboad
For holding ultrasonic sensor in place and to make room for the UNO and breadboard

Story

Read more

Schematics

Rover Schematics

Code

Rover.ino

C/C++
/*pin config
    d7 - MOsfet left motor
    d6 - Mosfet right motor

    d12 - Ultrasonic sensor input
    d11 - Ultrasonic sensor output

    d10 - Servo
*/

int distancel;
int distancer;
long duration;
int distance;
int defaultDis;
int disturn;
#include<Servo.h>
Servo eye;
void setup() {
  Serial.begin(9600);
  eye.attach(10);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, INPUT);
  eye.write(90);



}

void loop() {
  looks();
  if (distance < 500) {

    Serial.println(distance);
    if (distance < 25) {
      stopp();
      delay(500);
      distancel = lookl();
      delay(500);
      distancer = lookr();
      delay(500);
      if (distancel > distancer) {
        tLeft();
              }
      else {
        tRight(); 
      }
    }
    else{
      str();
    }
    
    


  }

}
int lookl() {
  eye.write(160);
  delay(1000);
  ping();
  eye.write(90);
  return distance;

}
int lookr() {
  eye.write(20);
  delay(1000);
  ping();
  eye.write(90);
  return distance;

}
int looks() {
  eye.write(90);
  ping();
  return distance;


}
int ping() {
  digitalWrite(11, LOW);
  delayMicroseconds(2);
  // Sets the 8 HIGH (ACTIVE) for 10 microseconds
  digitalWrite(11, HIGH);
  delayMicroseconds(10);
  digitalWrite(11, LOW);
  // Reads the 9, returns the sound wave travel time in microseconds
  duration = pulseIn(12, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2;
  return distance;
}
void tLeft() {
  digitalWrite(7, HIGH);
  digitalWrite(6, LOW);
  delay(500);
  digitalWrite(7, HIGH);
  digitalWrite(6, HIGH);
  
}
void tRight() {
  digitalWrite(6, HIGH);
  digitalWrite(7, LOW);
  delay(500);
  digitalWrite(7, HIGH);
  digitalWrite(6, HIGH);
}
void str() {
  digitalWrite(7, HIGH);
  digitalWrite(6, HIGH);
}
void stopp() {
  digitalWrite(7, LOW);
  digitalWrite(6, LOW);
}

Credits

yatin_7

yatin_7

0 projects • 1 follower

Comments