OBSTACLE DETECTOR USING ARDUINO




Components Required:

1.Arduino Uno:-



2.HC-SR04:-



3.10 LEDs:-


ULTRASONIC SENSOR- It is an electronic device that measures the distance of an object by emitting an ultrasonic sound at frequency of 20KHz through transmitter section and then receive it back through receiving section. The time taken by sound wave to get received back, after being transmitted from transmitter section, is used to calculate distance by using a formula

speed= distance/time

Transmitter section:-

This section is directly dependent on the trig pin of the module. On receiving pulse from Arduino, it generates a sound wave whose frequency is greater then 20KHz.

Receiving section:-

This section is used to receive back our sound signal which then generates an electrical signal which further we receive from Echo pin.

    ULTRASONIC SENSOR PINOUT

1.VCC PIN:- connected to the VCC pin of Arduino.

2.TRIGGER PIN:- It is an input pin that transmitter section uses to produces a sound signal if valid pulse is detected.

3.ECHO PIN:- It is an output pin that helps in calculating the time by giving us an electrical signal on receiving transmitted sound wave.

4.GND PIN:- connected to the GND pin of Arduino.

Ultrasonic sensor interfacing Arduino



1.Connect VCC pin of ultrasonic sensor to the A0 pin of Arduino.

2. Connect TRIG pin of ultrasonic sensor to A1 pin of Arduino.

3. Connect ECHO pin of ultrasonic sensor to A2 pin of Arduino.

4.Connect GND pin of ultrasonic sensor to A3 pin of Arduino.

5.Then connect anode terminals of 10 LED’s individually to the 0 to 9 pins of Arduino.

6.Then common each LED’s cathode with each other and then ground them.

7.Then connect a buzzer whose positive terminal is connected with the 10th pin of Arduino and the negative terminal to the ground.

 ARDUINO CODE

_________________________________________________________

int vcc = A0, trigpin = A1, echopin = A2, gnd = A3, setpin = 4, buzzer = 10, duration, distance, makehigh,dutycycle;

void setup()

{

  pinMode(vcc, OUTPUT);

  pinMode(trigpin, OUTPUT);

  pinMode(echopin, INPUT);

  pinMode(gnd, OUTPUT);

  pinMode(buzzer, OUTPUT);

  for (setpin = 0; setpin <= 9; setpin++)

  {

    pinMode(setpin, OUTPUT);

  }

  digitalWrite(vcc, HIGH);

  digitalWrite(gnd, LOW);

}

 

void loop()

{

  digitalWrite(trigpin, LOW);

  delayMicroseconds(10);

  digitalWrite(trigpin, HIGH);

  delayMicroseconds(10);

  digitalWrite(trigpin, LOW);

  duration = pulseIn(echopin, HIGH);

  distance = duration * 0.034 / 2;

  if (distance > 50)

  {

    for (setpin = 0; setpin <=9; setpin++)

    {

      digitalWrite(setpin, LOW);

      digitalWrite(buzzer,LOW);

    }

  }

  else if (distance <= 50)

  {

    for(setpin=0;setpin<10;setpin++)

    {

      digitalWrite(setpin,LOW);

    }

    setpin = 10 - distance / 5;

    for(makehigh=0;makehigh<=setpin;makehigh++)

    {

      digitalWrite(makehigh,HIGH);

    }

    dutycycle=map(distance,0,50,255,0);

    analogWrite(buzzer,dutycycle);

  }

  delay(100);

}

___________________________________________________________________


To understand this project in detail, click here or on this image to watch tutorial on YouTube.




Comments