Implementing SRF05

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download

Implementing SRF05

Postby snow-man-01 » Mon Aug 01, 2016 8:22 am


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()

void loop()
pinMode(sensorpin, OUTPUT);
digitalWrite(sensorpin, LOW); // Make sure pin is low before sending a short high to trigger ranging
digitalWrite(sensorpin, HIGH); // Send a short 10 microsecond high burst on pin to start ranging
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
Posts: 18
Joined: Mon Jul 18, 2016 9:50 am

Re: Implementing SRF05

Postby gregd72002 » Mon Aug 01, 2016 12:05 pm

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.
Posts: 103
Joined: Fri Dec 12, 2014 5:16 pm

Postby Zviki » Mon Aug 01, 2016 11:59 pm

Maybe this can help... MultiWii • View topic - Attemp to integrate sonar (ultrasonic sensor)

Sent from my SM-N910C using Tapatalk
Posts: 25
Joined: Sat May 28, 2016 7:39 pm

Return to Software development

Who is online

Users browsing this forum: No registered users and 1 guest