High Performance Ultrasonic Rangefinder Arduino - DFRobot




INTRODUCTION

The XL-MaxSonar-AE0 offers a wide and sensitive beam pattern for indoor use. This makes the XL-MaxSonar-AE0 an excellent choice wherever wide beam detection, reliable people detection, or reliable small obstacle detection are required.

The sensor is small in size, yet the high output acoustic power combined with continuously variable gain, real-time background automatic calibration, real-time waveform signature analysis, and real-time noise rejection algorithms results in virtually noise free distance readings for most users. This holds true even in the presence of many of the various acoustic or electrical noise sources. The XL-MaxSonar-AE0 sensor line is factory calibrated to match the sensor beam patterns and provides a long range detection zone.


SPECIFICATION


  • Operates from 3.3-5.5V
  • Low 3.4mA average current requirement
  • 42kHz Ultrasonic sensor measures distance to objects
  • RoHS Compliant
  • Read from all 3 sensor outputs: Analog Voltage, Serial, Analog Envelope
  • Virtually no dead zone, objects closer than 20 cm(2.87") range as 20 cm(2.87")
  • Resolution of 1 cm(0.39")
  • 10Hz reading rate
  • Small, light weight module
  • Designed for easy integration into your project or product
  • Operational Temperature from -40℃ to +70℃ (-40℉to +160℉)
  • Real-time automatic calibration (voltage, humidity, ambient noise)
  • Firmware filtering for better noise tolerance and clutter rejection
  • 200,000+ Hours Mean Time Between Failure
  • Widest and most sensitive beam of our XL-MaxSonar-AE sensors
  • Maximum range of 765 cm (300 inches)
  • Hardware gain of 4000
  • Long range, wide detection zone for small targets
  • Size: 22x20x25mm(0.87"x0.79"x0.98")


How to with Arduino

1 Analog Interface



float Inch=0.00;
float cm=0.00;
int SonarPin=A0;
int sensorValue;
void setup(){
pinMode(SonarPin,INPUT);
Serial.begin(9600);
}
void loop(){
sensorValue=analogRead(SonarPin);
delay(50);
Inch= (sensorValue*0.497);
cm=Inch*2.54;
Serial.println(sensorValue);
Serial.print(Inch);
Serial.println("inch");
Serial.print(cm);
Serial.println("cm");
delay(100);
}

2. Pulse Width "PW" Interface

This code without Library and with Median/Mode filter :
//...........................................................
// this code Based on : http://playground.arduino.cc/Main/MaxSonar
int pw_pin=7;
int arraysize = 9;
int array[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0};
long inch;
int exact_cm_value;
void setup() {
// put your setup code here, to run once:
pinMode(pw_pin, INPUT);
Serial.begin(9600);
}
void sensorRead(){
for(int i = 0; i < arraysize; i++)

inch = pulseIn(pw_pin, HIGH);
array[i] = inch/58;
delay(10);
}
}
void array_arrangment(int *a,int n){
// Author: Bill Gentles, Nov. 12, 2010)
for (int i = 1; i < n; ++i)
{
int j = a[i];
int k;
for (k = i - 1; (k >= 0) && (j < a[k]); k--)
{
a[k + 1] = a[k];
}
a[k + 1] = j;
}
}

int filter(int *a,int n){
int i = 0;
int count = 0;
int maxCount = 0;
int filter = 0;
int median;
int prevCount = 0;
while(i<(n-1)){
prevCount=count;
count=0;
while(a[i]==a[i+1]){
count++;
i++;
}
if(count>prevCount && count>maxCount){
filter=a[i];
maxCount=count;
median=0;
}
if(count==0){
i++;
}
if(count==maxCount){//If the dataset has 2 or more modes.
median=1;
}
if(filter==0||median==1){//Return the median if there is no mode.
filter=a[(n/2)];
}

return filter;


}
void loop() {
// put your main code here, to run repeatedly:
sensorRead();
array_arrangment(array,arraysize);
exact_cm_value= filter(array,arraysize);
Serial.print("The distance = ");
Serial.print(exact_cm_value);
Serial.println(" cm ");
delay(100);

}

Library code :
//......................................................
#include "SonarEZ0pw.h"
SonarEZ0pw Sonar(7); // pin D7
float cm_dis=0.00;
float Inch_dis=0.00;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
cm_dis= Sonar.Distance(cm); // To calculate the distance in cm
Inch_dis=Sonar.Distance(inch);// To calculate the distance in Inch
Serial.println("Distance " );
Serial.print(Inch_dis);
Serial.println(" inch ");
Serial.print(cm_dis);
Serial.println(" cm ");
delay(250);
}

Download file from Instructables

ความคิดเห็น