#include const int RX = 1; // NO RX for Sonar application const int TX = 2; // RX (data sent by the ATTiny85) SoftwareSerial serial(RX, TX);//rx pin of ftdi header as receiver and mosi as tx const int trigPin = A3; // defines pins numbers const int echoPin = A2; // defines pins numbers long duration; // defines variables int distance; // defines variables void setup() { pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output pinMode(echoPin, INPUT); // Sets the echoPin as an Input pinMode(TX,OUTPUT); // TX serial.begin(9600); // Starts the serial communication } void loop() { serial.println("Hello"); digitalWrite(trigPin, 0);// Clears the trigPin delayMicroseconds(2000); digitalWrite(trigPin, 1); delayMicroseconds(5); // Sets the trigPin on HIGH state for 5 micro seconds digitalWrite(trigPin, 0); duration = pulseIn(echoPin, 1); // Reads the echoPin, returns the sound wave travel time in microseconds distance = duration * 0.034 / 2; // Calculating the distance if (distance > 100) { serial.println("out of range"); } else { serial.print("Distance: "); // Prints the distance on the Serial Monitor serial.print(distance);// Prints the distance on the Serial Monitor serial.println(" Cm");// Prints the distance on the Serial Monitor } delay(2000); }