Adruino Prgramming (Robotics)

Obstruction Sensor using Ultrasonic Sound





Circuit diagram:



















Arduino Source Code
long duration;
int distance;
const int buzzer=13,echoPin=2,trigPin=3;
void setup() 
{
  pinMode (buzzer,OUTPUT);
  pinMode (trigPin,OUTPUT);
  pinMode (echoPin,INPUT);
}
void loop() 
{
  int i;
  //Clears the trig pin condition
  digitalWrite(trigPin,LOW);
  delayMicroseconds(2);
  //Set trigpin to high for 10 microseconds
  digitalWrite(trigPin,HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin,LOW);
  //gets the time taken by the sound wave to travel in echo pin
  duration=pulseIn(echoPin,HIGH);
  distance=duration*0.034/2;
  if (distance<=10)
  {
   for (i=0;i<100 div="" i="">
   {
    digitalWrite(buzzer,HIGH);
    delay(1);
    digitalWrite(buzzer,LOW);
    delay(1);
   }
  }
  
}

No comments:

Post a Comment

  Source Code for :   Displaying all possible fangs of a Vampire Number in Java import java.util.*; class Number {     public static void ma...