#include const int RX=-1; const int TX=2; SoftwareSerial mySerial(RX, TX); #define TRIG_PIN 3 #define ECHO_PIN 4 // defines variables long duration; int distance; void setup() { pinMode(TRIG_PIN, OUTPUT); // Sets the trigPin as an Output pinMode(ECHO_PIN, INPUT); mySerial.begin(9600); mySerial.println("Hello, world?"); } void loop() { // Clears the trigPin digitalWrite(TRIG_PIN, LOW); delayMicroseconds(2); // Sets the trigPin on HIGH state for 10 micro seconds digitalWrite(TRIG_PIN, HIGH); delayMicroseconds(10); digitalWrite(TRIG_PIN, LOW); // Reads the echoPin, returns the sound wave travel time in microseconds duration = pulseIn(ECHO_PIN, HIGH); // Calculating the distance distance= duration*0.034/2; // Prints the distance on the Serial Monitor mySerial.print("Distance: "); mySerial.println(distance); }