Summary of Arduino & Processing – Getting values from SRF05 ultrasound sensor & serial port
This article guides users on interfacing Arduino with Processing to visualize data, specifically addressing challenges with the SRF05 ultrasonic sensor. It highlights issues with Firmata limitations and serial port data conversion, offering a custom solution using separate echo and trigger pins. The text provides an Arduino sketch to read distance values and send them via serial communication for graphical display in Processing.
Parts used in the SRF05 Sensor Interfacing Project:
- SRF05 ultrasonic sensor
- Arduino board
- Processing software
- Echo pin (Pin 2)
- Init pin (Pin 3)
I’ve started to delve into Processing and passing values between Processing and Arduino. If you’re wondering what Processing is, basically its an open source programming language for vizualising data that can interface with Arduino either by reading values/ pins or by setting them. Just remember that they are 2 very different things and require 2 different sketches!
This is very cool if you want to display information from Arduino in a graphical way, or if you want to have a physical input device for your computer, for instance a Flash application that takes inputs from switches and potentiometers.
So anyway, it’s really very easy to get this installed and working, just do the following steps here: http://www.arduino.cc/playground/Interfacing/Processing
Now, I’ve had a bit of an issue getting values from my SRF05 from Arduino to Processing. In Arduino it works fine and the serial port shows the values correctly but in Processing I couldn’t get the values. Some people suggest using Firmata but the trouble with this is that it has very few of the functions that I need for example delayMicroseconds() is not available when using Firmata.
Also I saw alot of people trying to get this working using different mode settings for the SRF05 but to be honest I like my code so I want to use that – I use separate echo and trigger pins rather than a singular pin. I reckon this may also help you out should you be having problems getting other values.
Another issue I ran across was converting serial port output to an integer, it just didn’t like this at all so I found a quick solution into fixing this. Although this introduces another error which we have to catch but now I think I have a set of code that works pretty well for what I need.
So first of all take a look at my Arduino SRF05 tutorial.
Arduino SRF05 Sketch
Now you’ve got the circuit and parts use the following sketch on the Arduino board:
const int numReadings = 10;
int readings[numReadings]; // the readings from the analog input
int index = 0; // the index of the current reading
int total = 0; // the running total
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 the distance
void setup() {
// make the init pin an output:
pinMode(initPin, OUTPUT);
// make the echo pin an input:
pinMode(echoPin, INPUT);
// initialize the serial port:
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings[thisReading] = 0;
}
// set the serial port to begin logging values which Processing will later read.
Serial.begin(9600);
}
For more detail: Arduino & Processing – Getting values from SRF05 ultrasound sensor & serial port
- What is Processing?
It is an open source programming language for visualizing data that can interface with Arduino by reading or setting values. - How do I get values from my SRF05 from Arduino to Processing?
You must use separate sketches for each platform and follow specific steps at the Arduino Playground website. - Why should I avoid using Firmata for this project?
Firmata has very few functions available, such as lacking support for delayMicroseconds(). - Can I use different mode settings for the SRF05?
The author prefers using their own code with separate echo and trigger pins rather than changing mode settings. - What issue arises when converting serial port output to an integer?
The system does not like converting serial port output to an integer directly, requiring a specific quick solution. - Which pins are configured in the provided Arduino sketch?
The sketch configures Pin 2 as the echo pin and Pin 3 as the init pin. - What serial port speed is initialized in the setup function?
The serial port is set to begin logging values at 9600 baud. - How many readings are stored in the array defined in the sketch?
The sketch defines an array named readings with a size of 10.

