long bacaJarak (int triggerPin, int echoPin)
{
 pinMode(triggerPin, OUTPUT); 
 digitalWrite(triggerPin, LOW); 
 digitalWrite(triggerPin, HIGH);
 delayMicroseconds(10); 
 digitalWrite(triggerPin, LOW); 
 pinMode(echoPin, INPUT);
 return pulseIn(echoPin, HIGH);
}

void setup()
{
 pinMode (A0,INPUT);
 Serial.begin(9600);
}

void loop()
{
 int cm = 0; //reset cm ke 0
 cm = (0.03446 * bacaJarak(7, 8))/2;
 int pot = analogRead(A0);
 Serial.print(cm); //menuliskan data jarak
 Serial.print (“,”); //tanda baca , untuk pindah ke kolom berikutnya
 Serial.print (pot); //membaca variable data int pot
 Serial.println (“”); //membuat baris baru pada sheet
 delay(1000);
}