Examples - Modules - Supersonic
Supersonic SRF05 Sensors
This Module can be used to plug several Supersonic SRF05 sensors into your project. Connect your sensors to any digital pin on your board.
Download the source file
Table of contents
(top)
Source - modSupersonicSRF05
/************************************************************************************************** * * Supersonic SRF05 - Module * * Version: 1.0.0 - January 2009 * 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: This Module can be used to plug severel Supersonic SRF05 Sensors to your * project. Connect your sensors to any digital pin on your board. * * Methode: int SRF05_getDistance (int digitalPin) * digitalPin: Pin where your Supersonic Sensor is connected. * void SRF05_getDistanceInCM (int digitalPin, int *ret1, int *ret2) * digitalPin: Pin where your Supersonic Sensor is connected. * *ret1: Return Value (upper). Access this value by &var * *ret2: Return Value (lower). Access this value by &var * void SRF05_toCM (int imp, int *ret1, int *ret2) * imp: impules you mesured with SRF05_getDistance * *ret1: Return Value (upper). Access this value by &var * *ret2: Return Value (lower). Access this value by &var * ***************************************************************************************************/ // // Functions int SRF05_getDistance (int digitalPin) { // Trigger pulse pinMode(digitalPin, OUTPUT); digitalWrite(digitalPin, LOW); delayMicroseconds(2); digitalWrite(digitalPin, HIGH); delayMicroseconds(10); digitalWrite(digitalPin, LOW); // Mesure echo pulse pinMode(digitalPin, INPUT); return pulseIn(digitalPin, HIGH); //, 1000); } void SRF05_getDistanceInCM (int digitalPin, int *ret1, int *ret2) { int val = SRF05_getDistance (digitalPin); SRF05_toCM (val, ret1, ret2); } void SRF05_toCM (int imp, int *ret1, int *ret2) { *ret1 = imp / 58; *ret2 = imp % 58 * 100 / 58; }
(top)
Source - Main
/************************************************************************************************** * * Supersonic SRF05 * * Version: 1.0.0 - January 2009 * 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: This Module can be used to plug severel Supersonic SRF05 Sensors to your * project. Connect your sensors to any digital pin on your board. * ***************************************************************************************************/ // Const static int digitalPin1 = 0; static int digitalPin2 = 24; // 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); Serial.println("Wiring Started"); } // Loop void loop() { // Mesure Distance: int ret1; int ret2; SRF05_getDistanceInCM (digitalPin1, &ret1, &ret2); // int ret3; int ret4; SRF05_getDistanceInCM (digitalPin2, &ret3, &ret4); // Print Serial.print(ret1); Serial.print("."); Serial.print(ret2); Serial.print(" -- "); Serial.print(ret3); Serial.print("."); Serial.println(ret4); // Wait delay(50); }