Monday, 18 March 2019

Obstacle Detection System Using Arduino and Ultrasonic Sensor || techtalksgroup ||


Things used in the project:

1. Test Board

2. Ultrasonic sensor

3. Arduino cable

4. +5V buzzer

5. Male to male pins

6. Arduino uno board

Connect the Components as shown in the circuit:




Connect the Buzzer positive terminal to the Arduino pin 2 and the negative terminal to the Gnd. Connect the VCC pin of ultrasonic to +5v pin and the Gnd to the ground.

Connect trig pin to pin 10 and echo pin to pin 9.

Upload the code in the Arduino:


// Define pins for ultrasonic and buzzer
int const trigPin = 10;
int const echoPin = 9;
int const buzzPin = 2;
void setup()
{
pinMode(trigPin, OUTPUT); // trig pin will have pulses output
pinMode(echoPin, INPUT); // echo pin should be input to get pulse width
pinMode(buzzPin, OUTPUT); // buzz pin is output to control buzzering
}
void loop()
{
// Duration will be the input pulse width and distance will be the distance to the obstacle in centimeters
int duration, distance;
// Output pulse with 1ms width on trigPin
digitalWrite(trigPin, HIGH);
delay(1);
digitalWrite(trigPin, LOW);
// Measure the pulse input in echo pin
duration = pulseIn(echoPin, HIGH);
// Distance is half the duration devided by 29.1 (from datasheet)
distance = (duration/2) / 29.1;
// if distance less than 0.5 meter and more than 0 (0 or less means over range)
    if (distance <= 50 && distance >= 0) {
    // Buzz
    digitalWrite(buzzPin, HIGH);
    } else {
    // Don't buzz
    digitalWrite(buzzPin, LOW);
    }
    // Waiting 60 ms won't hurt any one
    delay(60);
}

So that's it. Hope you guys like it. If yes then please .. comment down below and do not forget to like follow and share our social media platforms.

Related Posts:

  • Switching from Android to iPhone. -By Emily Ferron- Have you decided to drop your Android in favor of an iPhone? Here's how to switch phones and operating systems without losing your data (or mind) in the process. Things to know before you start:… Read More
  • Why Hackers prefer Linux over other Operating System. Today we look at the reason why hackers always prefer Linux over Mac, Windows, and other operating systems. You may have your own reasons for choosing Linux but what do hackers really look forward to while working … Read More
  • Apple giving up Intel Processors working on new Mac chip. Apple giving up on Intel processors, said to be working on new Mac chip to help improve battery life in the company’s laptops.   After powering Apple Macs for nearly three decades, Apple is giving up on Intel… Read More
  • An African Boy Invented A Sim Card Free Phone. The invention of a secondary school student has gotten Namibia’s social media abuzz for the right reasons. Simon Petrus has created a mobile phone that works with radio frequencies, no sim card nor airtime credi… Read More
  • How To Spot Fake News On Facebook. The Pope has endorsed Donald Trump for president.A Washington, DC, pizzeria is a front for a child sex abuse ring. George Soros will "bring down'' the US by funding "black hate groups.'' These are just some examples of vi… Read More

0 comments:

Post a Comment