Pages: [1]   Go Down
Author Topic: SRF05 output  (Read 1456 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a SRF05 ultrasonic sensor mounted to a wireless robot. The signal from the SRF05 is run into a Arduino Duemilanove board. I am able to monitor the change is distance of a object from the serial monitor. My problem is that I would like to send this value to a the Java page so the distance can be monitored while the robot is in use. My problem is I am unsure of how to get the value out of the Duemilanove board? Here is a program that I am working with,

#include "WProgram.h"
void setup();
void loop();
int duration;                          // Stores duratiuon of pulse in
int distance;                          // Stores distance
int srfPin = 2;                        // Pin for SRF05
int outPin = 3;                        //  Output Pin for SRF05!!

void setup(){
pinMode(outPin, OUTPUT);               // Initialize pin 3 as output!!

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

int main(void)

   for (;smiley-wink
   return 0;

I added in the code for the output pin and labeled it with "!!".

Offline Offline
Shannon Member
Karma: 214
Posts: 12406
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You are outputting the values via the serial port - presume you need to interface Java to the serial port - try googling for 'java serial interface' and have a look at

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: