I would like to know has anyone tried to use the HY-SRF05 ultrasonic sensor http://www.ultest.com/index.php?route=product/product&product_id=142 to read the reading using the one pin method ?
I have tried using the ping sample code in the Arduino IDE and have connect the trigger pin to digital pin 7 and echo pin to GND and all I get from the serial terminal is 0. Is this HY-SRF05 different from the SRF05 sensor SRF05 Technical Documentation?
It says it is compatible with the SRF04 .
EDIT: if you leave the mode pin unconnected this code will work, if you tie it to ground, the ping sensor code will work
const int trigPin = 53; //Change to pin you use
const int echoPin = 50; //Here too
void setup() {
// initialize serial communication:
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
digitalWrite(trigPin, LOW);
}
void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(500);
}
long microsecondsToInches(long microseconds)
{
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}
I have tried both method but it only seems that the two pin method which uses separate pin work but not the single pin method.Currently, I am trying to use the one pin method to read the value from the sensor but failed.
It looks like the description is wrong, the OUT pin is apparently not a mode pin. But a proximity warning output. I think you would use it to trigger an interrupt to tell device to start pinging. But other people have said not to connect it.
Unless you can confirm that this is not a knockoff sensor. I would say its safe to assume it only supports two pins.
Hello im working too with SRF05 Ultrasonic Sensor . Here is the code im using for
Dont forget to change return( (unsigned int) (pulse_length / 148) ); 148 to 58 from inch to cm
#define SONAR_TRIGGER_PIN 2
#define SONAR_ECHO_PIN 3
unsigned int measure_distance()
{
// Trigger the SRF05:
digitalWrite(SONAR_TRIGGER_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(SONAR_TRIGGER_PIN, LOW);
// Wait for Echo Pulse
unsigned long pulse_length = pulseIn(SONAR_ECHO_PIN, HIGH);
// Ensure the ultrasonic "beep" has faded away
delay(50);
// Convert Pulse to Distance (inches)
// pulse_length/58 = cm or pulse_length/148 = inches
return( (unsigned int) (pulse_length / 148) );
}
void setup()
{
pinMode(SONAR_TRIGGER_PIN, OUTPUT);
pinMode(SONAR_ECHO_PIN, INPUT);
Serial.begin(9600);
}
void loop()
{
unsigned int current_distance = measure_distance();
Serial.println(current_distance);
delay(125);
}
Orven:
Hello im working too with SRF05 Ultrasonic Sensor . Here is the code im using for
Dont forget to change return( (unsigned int) (pulse_length / 148) ); 148 to 58 from inch to cm#define SONAR_TRIGGER_PIN 2
#define SONAR_ECHO_PIN 3unsigned int measure_distance()
{
// Trigger the SRF05:
digitalWrite(SONAR_TRIGGER_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(SONAR_TRIGGER_PIN, LOW);// Wait for Echo Pulse
unsigned long pulse_length = pulseIn(SONAR_ECHO_PIN, HIGH);// Ensure the ultrasonic "beep" has faded away
delay(50);// Convert Pulse to Distance (inches)
// pulse_length/58 = cm or pulse_length/148 = inches
return( (unsigned int) (pulse_length / 148) );
}void setup()
{
pinMode(SONAR_TRIGGER_PIN, OUTPUT);
pinMode(SONAR_ECHO_PIN, INPUT);
Serial.begin(9600);
}void loop()
{
unsigned int current_distance = measure_distance();
Serial.println(current_distance);
delay(125);
}
Hi.
Thanks for the code and I will give it a try.
Thanks.
I am studying the same component using this specs:
http://www.robot-electronics.co.uk/htm/srf05tech.htm
With this I find the code of Orven pretty enough which corresponds to specs.
I am pointing out:
// Ensure the ultrasonic "beep" has faded away
delay(50);
// pulse_length/58 = cm or pulse_length/148 = inches
return( (unsigned int) (pulse_length / 148) );
But the main feature of SRF05 is to use it in MODE2.
Meaning same PIN for TRIGGER and ECHO.
I think you can modify that code to use only a single PIN.
After the following code:
// Trigger the SRF05:
digitalWrite(SONAR_TRIGGER_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(SONAR_TRIGGER_PIN, LOW);
Add this as specified on specs:
The SRF05 will not raise the echo line until 700uS after the end of the trigger signal. You have that long to turn the trigger pin around and make it an input and to have your pulse measuring code ready.
Based on my understanding, after setting to LOW, you should put a delay of 700us.
After that, set the PIN as INPUT.
Then you can proceed to the next code:
// Wait for Echo Pulse
unsigned long pulse_length = pulseIn(PIN, HIGH);
I am not sure if Baudrate should also be included.
BTW, I am newbie to arduino but not with this field.
kuxz:
I have tried both method but it only seems that the two pin method which uses separate pin work but not the single pin method.Currently, I am trying to use the one pin method to read the value from the sensor but failed.
The "one pin method" is a feature of the NewPing library. The HY-SRF05 works great with my NewPing library with standard 2 pin control and with 1 pin.
If you have a problem, please post to my support thread which I monitor:
NewPing library support forum thread
Tim
Hi Teckel,
Thanks for the info.
I will definitely try that library.
Hi Tim,
NewPing.h
#define ONE_PIN_ENABLED true // Set to "false" to disable one pin mode which saves around 14-26 bytes of binary size. Default=true
Based on the above, I need to change the library to use the MODE2 of SRF05?
I am not in favor of changing a library value.
The constructor also has input pins for both TRIGGER and ECHO.
This is confusing, implementing MODE2(1 pin mode) and yet needs input for 2pins?
steiryx:
Hi Tim,NewPing.h
#define ONE_PIN_ENABLED true // Set to "false" to disable one pin mode which saves around 14-26 bytes of binary size. Default=true
Based on the above, I need to change the library to use the MODE2 of SRF05?
I am not in favor of changing a library value.The constructor also has input pins for both TRIGGER and ECHO.
This is confusing, implementing MODE2(1 pin mode) and yet needs input for 2pins?
You can define both Trigger and Echo the same pin like this (pin 2 is my setup, change to yours)
#define TRIGGER_PIN 2 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 2 // Arduino pin tied to echo pin on the ultrasonic sensor.
in Loop just use original example code of NEW PING
unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
int distance = uS / US_ROUNDTRIP_CM;
Serial.print(distance);
teckel:
The "one pin method" is a feature of the NewPing library. The HY-SRF05 works great with my NewPing library with standard 2 pin control and with 1 pin.If you have a problem, please post to my support thread which I monitor:
NewPing library support forum thread
Tim
The latest library of New Ping is great, but still have problem with HC-SR04 when out of range and does not reset echo after that. (the version up to this moment). Frankly im not sure why since I use 1 pin only.
Confirm working with Attiny85 Single pin mode, both SR04 and SR05.
im from indonesia any question : how to display the distance on lcd 16x2 with arduino uno
Haay Can we connect Sharp ir sensor and ultrasonic srf5 on one arduino what type of arduino mega or uno