Examples - Sensorboard - Supersonic

Supersonic

This Example shows the use of an ultrasonic sensor.


Presentation: Supersonic.pdf
Datasheet: SRF05Datasheet.pdf





/**************************************************************************************************
*
*  Supersonic SRF05
*
*   Version:      1.0.0 - Oktober 2008
*   Author:       Etienne Ribeiro    / tutorial assistant caad      /  eribeiro[at]ethz.ch
*   Supervisor:   Christoph Wartmann / chair for caad - ETH Zürich  /  wartmann[at].arch.ethz.ch
*
*   Desc:         Shows the use of the SRF05 Supersonic Sensor  on digital pin.
*
***************************************************************************************************/





// Const

static int digitalPin = 0;



// Setup

void setup() {

        //LED (2 * blink)
        pinMode(48, OUTPUT);
        digitalWrite(48, HIGH);
        delay(200);
        digitalWrite(48, LOW);
        delay(200);
        digitalWrite(48, HIGH);


        // Initialize Serial
        Serial.begin(9600);


        // Set Pin-Mode for digital Pin
        pinMode(digitalPin, INPUT);

}




// Loop

void loop() {

        // Trigger pulse
        digitalWrite(digitalPin, HIGH);
        delayMicroseconds(10);
        digitalWrite(digitalPin, LOW);


        // Mesure echo pulse
        int imp = pulseIn(digitalPin, HIGH);


        // Serial
        Serial.print(imp);
        Serial.print(" -> ");
        Serial.print(imp / 58);
        Serial.print(".");
        Serial.print(imp % 58 * 100 / 58);
        Serial.println("cm");


        // Wait
        delay(50);

}

This website has been archived and is no longer maintained.