#include

const byte rxPin = PA1;
const byte txPin = PA0;

// set up a new serial object
SoftwareSerial mySerial (rxPin, txPin);

// this constant won't change. It's the pin number of the sensor's output:
const int pingPin = 9;

void setup() {
// initialize serial communication:
mySerial.begin(4800);
}
void loop() {

// establish variables for duration of the ping, and the distance result
// in inches and centimeters:
long duration, cm;

// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(500);
digitalWrite(pingPin, HIGH);
delayMicroseconds(500);
digitalWrite(pingPin, LOW);

// The same pin is used to read the signal from the PING))): a HIGH pulse
// whose duration is the time (in microseconds) from the sending of the ping
// to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);

// convert the time into a distance
cm = microsecondsToCentimeters(duration);

if(cm < 5){
mySerial.write('0');
delay(3000);
}


if((cm > 5) && (cm < 10)){
mySerial.write('1');
delay(3000);
}


if(cm > 10){
mySerial.write ('2');
delay(3000);
}

}

long microsecondsToCentimeters(long microseconds) {
return microseconds / 29 / 2;
}