Skip to main content

Ultrasonic sensor in aurdino with code

                   Ultrasonic sensor in aurdino with code


Connection
       *vcc of ultrasonic sonsor to +5v
       *Gnd pin to Gnd pin of aurdino
       *trigpin to pin no 13
       *echopin to pin no 12
       *led 1 to pin no 7
       *led 2 to pin no 8
       *Gnd of led to gnd pin of aurdino
 
Circuit Diagram


Procedure
        *connect the circuit as shown in figure
        *copy and paste the code given below
        *upload the code
        *then check it
Code
/*
  connect ultrasonic sensor +vcc to 5v
  connect echopin to pin no 12
  connect trigpin to pin no 13
 */
#define trigPin 13
#define echoPin 12
#define led 7
#define led2 8

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
}

void loop() {
  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  if (distance < 4) {
    digitalWrite(led,HIGH);
  digitalWrite(led2,LOW);
}
  else {
    digitalWrite(led,LOW);
    digitalWrite(led2,HIGH);
  }
  if (distance >= 200 || distance <= 0){
    Serial.println("Out of range");
  }
  else {
    Serial.print(distance);
    Serial.println(" cm");
  }
  delay(500);
}


Lets check how is it work;

    

Comments

  1. This comment has been removed by a blog administrator.

    ReplyDelete

Post a Comment

Popular posts from this blog

What if you could control the Internet

At present situation internet is the basic need for us, we are using the internet for many purposes from medicine to aerospace internet is used and helps in day to day life activates. Internet is spread out in all the areas and we could say it is the most powerful tool in the world, if you got a chance to control the internet what will you do.                                                Image Credit : Internet In general, more than 5 billion google searches are done all over the world and millions of hours videos are watches in facebook and YouTube daily. What if you got a chance to control the internet, whether it is possible to control the internet, the internet is actually controlled with the help of 7 keys and by 14 peoples all around the world. They maintain the DNS which helps in accessing the internet all around the world. The DNS helps in accessing ...

Corona Virus

In present situation our entire world is under a high alert due to the spread of the corona virus. Many lives have been lost due to this virus breakthrough. This corona virus was found on humans in 2019 and before that this is not identified in humans. It is a zoonotic, which means a virus which is spread from the animals to humans is termed as the zoonotic. Corona is not only the first zoonotic disease already Rabies, Swine flu, etc are categorized as zoonotic diseases. Why Corona Virus is so Dangerous \Till now there is no proper medicine for the corona virus, this is because we cannot find from which animal this corona virus came from, according to the report of World Health Organization this Corona virus are spread from the Civet Cat and this is an new type of virus human ever seen, so time required to find medicine for this corona virus. Symptoms of Corona Virus & Precautions The major symptoms of the corona virus are Fever, Cough, Shortness of ...

Creating Artificial Planet

Already our Earth is loosing the habitable tendency due to the deforestation, Climate changes, etc. These all causes our Earth as inhabitable planet, for life better we should move into another planet to move into another planet we could create our own planet. But, it is possible to build a planet as like Earth with Atmosphere, Air, Water, Moderate Temperature, Gravity, etc. Theoretically, it is said we could build a planet like Earth. We could build our own planet right in our solar system for constant temperature as we get in our planet “Earth”. We could probably use asteroids in our solar system to build our artificial planet, but we are having only lower amount of asteroids in our solar system so we cannot build a planet as we expected so we are going to use OORT CLOUD to build our Artificial Planet but problem with this OORT CLOUD is it is so far from our Earth, we haven’t still invented that fast vehicle to bring that materials here, so this case could not help us. We have ...