//Mayra Ascencio Calderón //Fab Academy 2021 //Code const int TriggerPin = 8; //Trig pin const int EchoPin = 9; //Echo pin long Duration = 0; void setup() { // put your setup code here, to run once: pinMode(TriggerPin,OUTPUT); //Trigger is an output pin pinMode(EchoPin,INPUT); //Echo is an input pin Serial.begin(9600); //Serial output } void loop() { // put your main code here, to run repeatedly: digitalWrite(TriggerPin, LOW); delayMicroseconds(2); digitalWrite(TriggerPin, HIGH); delayMicroseconds(10); digitalWrite(TriggerPin, LOW); Duration = pulseIn(EchoPin,HIGH); long Distance_cm = Distance(Duration); Serial.print("Distance = "); Serial.print(Distance_cm); Serial.println(" cm"); delay(10); } long Distance(long time) { long DistanceCalc; DistanceCalc = ((time * 0.034)/2); //DistanceCalc = time / 74 / 2; return DistanceCalc; }