info@maverickden.com
+91 9867381971 (India)

EDGE DETECTOR ROBOT

ltrasonic Sensor HC-SR04 Connection of Ultrasonic to Arduino The HC-SR04 ultrasonic sensor uses sonar to determine distance to an object like bats do. It offers excellent non-contact range detection with high accuracy and stable readings in an easy-touse package. From 2cm tp 400cm or 1” to 13 feet. It operation is not affected by sunlight or black material like sharp rangefinders are (although acoustically soft materials like cloth can be difficult to detect). It comes complete with ultrasonic transmitter and receiver module.

HC-SR04 Specifications:

    • Working Voltage: DC 5V
    • Working Current: 15mA
    • Working Frequency: 40Hz
    • Max Range: 4m
    • Min Range: 2cm
    • Measuring Angle: 15 degree
    • Trigger Input Signal: 10µS TTL pulse
    • Echo Output Signal Input TTL lever signal and the range in proportion
    • Dimension 45 * 20 * 15mm
ultrasonic sensor image

Ultrasonic Sensor

working of ultrasonic waves

Signal Echo and Signal Trigger

COMPONENTS USED :

SR NO COMPONENT NAME QUANTITY
1 Arduino Board(Uno or Nano) 1
2 Mini BreadBoard 1
3 Motor Driver(L293D)- 1
4 Battery Holder 1
5 BO motor 2
6 Ultrasonic Sensor 1
7 Caster wheel 1
8 Wheels 2
9 Jumper cables (M to F and M to M) 1 set of each


Schematic Diagram :

Code :

#define echopin 8

#define trigpin 9

long duration,distance;

void setup(){

  Serial.begin(9600);

  pinMode(2,OUTPUT);

  pinMode(3,OUTPUT);

  pinMode(4,OUTPUT);

  pinMode(5,OUTPUT);

  pinMode(trigpin,OUTPUT);

  pinMode(echopin,INPUT);

}

void loop()

{

  digitalWrite(trigpin,LOW);

  delayMicroseconds(2);

  digitalWrite(trigpin,HIGH);

  delayMicroseconds(10);

  duration=pulseIn(echopin,HIGH);

  distance=duration/58.2;

  delay (50);

  Serial.println(distance);

  if (distance<=6)

  {

    digitalWrite(2,HIGH);

    digitalWrite(3,LOW);

    digitalWrite(4,HIGH);

    digitalWrite(5,LOW);

    delay (200);

    }

  else if (distance >6)

  {

    digitalWrite (2, LOW);

    digitalWrite (3, HIGH);

    digitalWrite (4, LOW);

    digitalWrite (5, HIGH);

    delay (1000);

    digitalWrite (2,LOW);

    digitalWrite (3,LOW);

    digitalWrite (4,HIGH);

    digitalWrite (5,LOW);

    delay (1000);

  }

}

 

Comments are closed.