Code And Circuit Diagram For Ultrasonic Sensor Arduino

** if you want to buy the entire package with a re-programmable Arduino Click Here **

#include <Mouse.h>

const int trigpin= 8;

const int echopin= 7;

long duration;

int distance;

void setup()

{

pinMode(trigpin,OUTPUT);

pinMode(echopin,INPUT);

Serial.begin(9600);

}

void loop()

{

digitalWrite(trigpin,HIGH);

delayMicroseconds(10);

digitalWrite(trigpin,LOW);

duration=pulseIn(echopin,HIGH);

distance = duration*0.034/2;

Serial.println(distance);

}

 

IF YOU ARE GETTING A STRAY ERROR THEN COPY OR DOWNLOAD THE CODE FROM HERE

 



One Comment on “Code And Circuit Diagram For Ultrasonic Sensor Arduino”

Leave a Reply

Your email address will not be published. Required fields are marked *