Arduino + Processing – Make a Radar Screen to Visualise Sensor Data from SRF-05 – Part 1: Setting up the Circuit and Outputting Values

arduino servo SRF05

First things first, we need to build our circuit. This is the easy bit! We’ll be using the Arduino to control a servo that will rotate our sensor around 180 degrees. The Arduino will then send the value from the distance sensor along with the current angle of the servo to the serial port.

Before proceeding please take a moment to check out some of my other work with the SRF-05 and servos if you’re unfamiliar with either.
Arduino SRF-05 Tutorials
Arduino Servo Tutorials

I’m building this with the SRF-05 ultrasonic range finder/ distance sensor, but because this has a fairly wide field of detection it’s not very precise – I think I’ll end up trying a different range finder maybe an IR one as the SRF-05 works best as a static sensor/ detector, anyway…

Arduino Radar Parts list

SRF05 Ultrasonic range finder
Arduino Deumilanove w/ ATMEGA328
Breadboard / Prototyping board
Jumper/ Connector wires
1x Servo (has to need no more than 5v supply)
You’ll also need some way to mount the sensor to the servo.

Arduino Radar Servo Circuit

Straight forward, we have the Arduino providing power to the breadboard and we have the servo and the SRF-05 sharing this power. Then we have the servo output pin going to Arduino digital pin 9 and the SRF-05 pins going to digital pin 2 and 3. You’ll notice that in my pictures I have 2 servos – I’m just using the bottom one of the pair to rotate the sensor round. On your servo you’ll need to figure out a way to mount the sensor on to the servo wheel – I used a lot of blu-tac! You’ll also see I’ve mounted my sensor vertically so that the when the servo moves there’ll be less interference with recieving values – placing the sensor horisontally seemed to give differences of up to and sometimes over 5cm between the first and second readings.

My servos do tend to move a bit so I’ve used more blu-tak/ modelling clay to hold them down and in place – if the servos move other than the way they’re meant to then it means dodgy readings.

SRF05 pin layout
Simple rig to rotate sensor 180 degrees

Arduino SRF05 Radar Sketch

The hardest bit – rotate the servo from left to right, then right to left and for every degree of movement take a series of readings and send them to the serial port. We’ll want to produce an average reading value for consistancy. Unfortunately with this ultrasound sensor we have to be quite slow to make sure we’re getting accurate values and we have to allow time for the signal to come back each time and register in order to produce the average value.

We do the rotation using a for loop to count to 180 and for each iteration we move the servo by +1 or -1 depending on which way we’re going – if you’ve hacked your servos then you can do a full 360 loop. During this loop we do another FOR loop to count to 10/ numReadings and for each iteration we add the distance measured to the total and after 10 readings we get our average by dividing the total by the number of readings. Then reset the total and the counter to start again for the next servo position. Finally before finishing the  the FOR loop for the servo we output the servo position and average reading to the serial port each with a preceeding character for us to later use to identify the values when reading the serial port in Processing. The last line is using println which will start a new line for the next set of values – each reading has its own line in the serial buffer makign it much easier to get our values back out.

Radar Screen Visualisation for SRF-05
Sends sensor readings for every degree moved by the servo
values sent to serial port to be picked up by Processing
#include             // include the standard servo library
Servo leftRightServo;         // set a variable to map the servo
int leftRightPos = 0;         // set a variable to store the servo position
const int numReadings = 10;   // set a variable for the number of readings to take
int index = 0;                // the index of the current reading
int total = 0;                // the total of all readings
int average = 0;              // the average
int echoPin = 2;              // the SRF05's echo pin
int initPin = 3;              // the SRF05's init pin
unsigned long pulseTime = 0;  // variable for reading the pulse
unsigned long distance = 0;   // variable for storing distance

/* setup the pins, servo and serial port */
void setup() {
  // make the init pin an output:
  pinMode(initPin, OUTPUT);
  // make the echo pin an input:
  pinMode(echoPin, INPUT);
  // initialize the serial port:

/* begin rotating the servo and getting sensor values */
void loop() {
  for(leftRightPos = 0; leftRightPos < 180; leftRightPos++) {  // going left to right.
      for (index = 0; index<=numReadings;index++) {            // take x number of readings from the sensor and average them
        digitalWrite(initPin, LOW);
        digitalWrite(initPin, HIGH);                           // send signal
        delayMicroseconds(50);                                 // wait 50 microseconds for it to return
        digitalWrite(initPin, LOW);                            // close signal
        pulseTime = pulseIn(echoPin, HIGH);                    // calculate time for signal to return
        distance = pulseTime/58;                               // convert to centimetres
        total = total + distance;                              // update total
    average = total/numReadings;                               // create average reading

    if (index >= numReadings)  {                               // reset the counts when at the last item of the array
      index = 0;
      total = 0;
    Serial.print("X");                                         // print leading X to mark the following value as degrees
    Serial.print(leftRightPos);                                // current servo position
    Serial.print("V");                                         // preceeding character to separate values
    Serial.println(average);                                   // average of sensor readings
  start going right to left after we got to 180 degrees
  same code as above
  for(leftRightPos = 180; leftRightPos > 0; leftRightPos--) {  // going right to left
    for (index = 0; index<=numReadings;index++) {
      digitalWrite(initPin, LOW);
      digitalWrite(initPin, HIGH);
      digitalWrite(initPin, LOW);
      pulseTime = pulseIn(echoPin, HIGH);
      distance = pulseTime/58;
      total = total + distance;
    average = total/numReadings;
    if (index >= numReadings)  {
      index = 0;
      total = 0;

[ad#Google Ad in content]

Part 2: Visualising the Data
Part 3: Visualising the Data from Sharp Infrared Range Finder


  • Very good work! I had this idea to time but not had the opportunity to implement!

    • thanks! took me a while to get it working in Processing – in the end I found that the SRF-05 sonar sensor isn’t actually that accurate at detecting small objects in its path at least not when being rotated anyway. :)

    • hey larry..good idea..but i want to ask if i can make the same project with a dc motor in the place of the servo! and if that’s not a problem for the radar chart ? thanks ! i want to do it for my school final project please help me!

  • Very cool. Your project makes me wonder about using Arduino to help an ARM do localization and mapping simultaneously.
    Congratulations !!
    AVR,Arduino & ARM

  • nice can this program also use the ping sensor from parallax? if so how

    • You can use the Parallax ping sensor its basically the same thing, in fact any distance sensor/ range finder will work. With the parallax ping you just need to find some info on wiring it up and there’ll be plenty of code out there. Try here: then you just need to alter my code with the exmple above once you got that working.

  • This is really a great application of the arduino.


  • Hey larry, think this will work under water?



    • If you sheilded the unit from water I guess, but not sure about the ultrasound getting through an enclosure.

  • […] LuckyLarry has developed a sonar system based on the Arduino and an SRF-05 ultrasonic range finder. A servo sweeps the range finder across the target field, with the pingbacks processed and displayed on the desktop with Processing. [via] […]

  • Hats off to you larry. first i thank you for the support you are doing for beginners like me. is it possible to pin point an object in the water with this radar? if so could you give an idea?

    • Never tried it, I am intrigues to know if it would work – though dont get the circuits wet!! let me know. :)

  • The posted code needs the include line for the servo changed (mising the Servo.h) or else it won’t compile in Arduino. Simple fix.

    #include // include the standard servo library

    • it must be the carrots at the ends that hide the line-so for those who are challenged, it should be #include space less than sign space Servo.h space greater than sign. I know this is a dumb way to represent it, but this would have helped me have this running yesterday.

  • Larry, have you worked with the SFR10? I have had little luck getting it to reliably read distances of a person moving from 15-20 feet to about 2 Feet. I have built two projects around this sensor one using a Basic Stamp and now one with an Arduino but still can’t get the measurements to read reliably. I need to set 4 zones that when a person moves from one to another it will trigger different segments of the sketch to run. Any suggestions or code examples? If I can’t get it to work I will next try the Sharp IR R316-GP2Y0A710YK sensor.

    Thanks for any help to can offer.

  • Good implementation…I’ve been tinkering with this off and on with similar frustrations. From using shipborne radar, usually radar displays image the range of the reflecting surface rather than the extended polar trace of the complete signal as you’ve done, giving a result of objects/surfaces only. Either works, but the former is more intuitive to interpret (and may be easier to interface with robotics).

  • Hey Larry,

    First of all, good work on this project!
    Okay, I am doing this as a project at college, but using PICAXE Programming software. I have a working code and circuit and everything that can find distance in it’s registry. I was just wondering how I would go about creating a radar screen like yours here? and also, do you know how to input data from the PICAXE chip to the PC so it can use the data to map out distance on the radar screen?


  • Great tutorial. I’m currently working on a similar project with Parallax PING sensors (3 total), where one is mounted on a server and rotating 180deg at 15deg intervals (11 total), just like you’ve done. The problem I’ve run into seems to be a buffer overflow and automatic reset of the Arduino Duemilanove when I write the 11 sensor values to an array. I’ve been playing with adding delays after each servo movement, which does improve the result but adding some different code eventually causes more problems. With that said, make sure you have enough memory in your board to do what you want or else it’ll crash and reset itself.

  • GREAT JOB & thanks so much!! i´ve been searching something clear about this kind of works !! really helpfull !!

    greathings from México

  • I’m rather new to using arduino and i was hoping you could tell me how to include the servo library in the program.

  • Hi,

    I use a Arduino Duemilanove with a PING))) Ultrasonic Sensor and a Standard Servo. I implemented your code and I think everything is working but the servo rotation is very very slow. And sometimes it completely stucks for 2-5 seconds.

    Any ideas how to solve this problem?


    • I had the same issue, so I wrote my own code for the arduino side of things:


      Servo servo; // create servo object to control a servo
      // a maximum of eight servo objects can be created

      int pos = 90; // variable to store the servo position
      const int pingPin = 7;
      long duration, inches, cm;

      void setup()
      servo.attach(9); // attaches the servo on pin 9 to the servo object

      void loop()
      for(pos = 0; pos = 1; pos -= 1)

      void ping()
      pinMode(pingPin, OUTPUT);|
      digitalWrite(pingPin, LOW);
      digitalWrite(pingPin, HIGH);
      digitalWrite(pingPin, LOW);

      pinMode(pingPin, INPUT);
      duration = pulseIn(pingPin, HIGH);
      cm = microsecondsToCentimeters(duration);


      long microsecondsToCentimeters(long microseconds)
      return microseconds / 29 / 2;

      Obviously this removes the averaging as well, but works for me :) Still can be improved a lot though.
      The other thing that can help as well is also connecting an external PSU depending on the type of servo used.

  • Hi Larry,
    I commented that I have ridden all according to this page and everything seems to work fine, but Processing does not seem to receive data through the serial port and nothing moves on green screen. I can assure that the port works well, because with hyperterminal received X12V22 like sequences that are correctly generated by Arduino, Processing recognizes perfectly the serial port, but it seems not to process the data if you arrive. Tested on multiple PCs with negative results in all cases. I see more people have this problem. Please indicate if there is any solution for this. I have several sleepless nights … Health.

  • This is a very nice project. I did a SRF-05 which worked great. Next, I tried my WiiDar (WiiCamera/ Laser) and it was even better. A really great display.

    The serial thing by the way is pretty simple. Processing seems to think the Arduino is sending a CR (13) instead of a LF(10) with the println() command. I changed these:

    myPort.bufferUntil(13); //In setup

    myPort.readStringUntil(13); //Down in the serial routine

    Works a treat now.

Join the Discussion

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>