Page 1 of 1

Implementing SRF05

Posted: Mon Aug 01, 2016 8:22 am
by snow-man-01
Hello,

I want to implement the ultrasonic SRF05 in the Software Multiwii 2.4.

Can anyone tell me how I can do it? I have the code for the SRF05:

// Community of Robots//

//SRF05 sample code//

int duration; //Stores duration of pulse in
int distance; // Stores distance
int sensorpin = 7; // Pin for SRF05

void setup()
{
Serial.begin(9600);
}

void loop()
{
pinMode(sensorpin, OUTPUT);
digitalWrite(sensorpin, LOW); // Make sure pin is low before sending a short high to trigger ranging
delayMicroseconds(2);
digitalWrite(sensorpin, HIGH); // Send a short 10 microsecond high burst on pin to start ranging
delayMicroseconds(10);
digitalWrite(sensorpin, LOW); // Send pin low again before waiting for pulse back in
pinMode(sensorpin, INPUT);
duration = pulseIn(sensorpin, HIGH); // Reads echo pulse in from SRF05 in micro seconds
distance = duration/58; // Dividing this by 58 gives us a distance in cm
Serial.println(distance); // Wait before looping to do it again
delay(100);
}

Re: Implementing SRF05

Posted: Mon Aug 01, 2016 12:05 pm
by gregd72002
you cannot use pulseIn as this might introduce unexpected delay and the whole timing in MultiWii will be out of sync.

A potential way around it would be to read by undersampling - read it in a loop and apply LPF. But there might be other ways to do it too.

Posted: Mon Aug 01, 2016 11:59 pm
by Zviki
Maybe this can help... MultiWii • View topic - Attemp to integrate sonar (ultrasonic sensor)
viewtopic.php?f=7&t=1033&start=200

Sent from my SM-N910C using Tapatalk