Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
498 B
4
Indexable
Never
#define trig 10
#define echo 11 
int duration,distance;
void setup() 
{
  Serial.begin(9600);
  pinMode(trig,OUTPUT);    // sets trig as an output
  pinMode(echo,INPUT); //sets echo as an input
  digitalWrite(trig,LOW);
}

void loop() 
{
  digitalWrite(trig,HIGH);
  delayMicroseconds(10);
  digitalWrite(trig,LOW);
   duration = pulseIn(echo,HIGH);
   distance = (duration/58);
  Serial.print("Distance=");
  Serial.print(distance);
  Serial.println("(cm)");
  delay(3000);
}