I’ve played with an SRF06 range finder this week. The SRF06 is an ultrasonic distance measuring module. They are ideal to sense objects, so I bought 2 to put on the front and back of a robot. The Arduino library for these modules gives you the detected distance in centimeters or inches.
You can find the library and a basic sketch that sends the distance to the serial monitor here. These kind of sensors are used in cars to help drivers when parking.
So I started by making a basic sketch that would detect an object and would light a bunch of leds as the object comes closer just like the parking help I have in my car.
/*
http://www.bajdi.com
SRF06 module detecting distance in cm. The closer we get to the object
the more leds start to burn.
The circuit:
* leds on pin 2,3,4,5
* SRF06 module: trig to pin 12, echo to pin 13
*/
#include "Ultrasonic.h"
const int TRIG = 9;
const int ECHO = 10;
const int led1 = 2;
const int led2 = 3;
const int led3 = 4;
const int led4 = 5;
Ultrasonic SRF06(TRIG, ECHO);
void setup()
{
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
}
void loop()
{
if (SRF06.Ranging(CM) >= 100)
{
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
}
if (SRF06.Ranging(CM) >= 80 && SRF06.Ranging(CM) < 100) { digitalWrite(led1, HIGH); digitalWrite(led2, LOW); digitalWrite(led3, LOW); digitalWrite(led4, LOW); } if (SRF06.Ranging(CM) >= 60 && SRF06.Ranging(CM) < 80) { digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, LOW); digitalWrite(led4, LOW); } if (SRF06.Ranging(CM) >= 40 && SRF06.Ranging(CM) < 60)
{
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
}
if (SRF06.Ranging(CM) < 40)
{
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
}
}
I’ve looked around on the internet to find the datasheet for the SRF06 but haven’t been able to find it. The SRF06 is an improved version of the SRF04, I wonder if they have the same specifications. Some info that I’ve found of the SRF06:
- power supply :5V
- DC quiescent current : less then 2mA
- effective angle: less then 15°
- ranging distance : 2cm – 500 cm
- resolution : 0.3 cm
