living with the lab - Louisiana Tech University

Download Report

Transcript living with the lab - Louisiana Tech University

Maxbotix Ultrasonic Distance Sensor
The distance sensor emits short bursts of sound and listens for this sound to echo off
of nearby objects. The frequency of the sound is too high for humans to hear (it is
ultrasonic). The sensor measures the time of flight of the sound burst and
determines distance using the time of flight and the speed of sound (1,126 ft/s).
DISCLAIMER & USAGE
The content of this presentation is for informational purposes only and is intended only for students
attending Louisiana Tech University.
The author of this information does not make any claims as to the validity or accuracy of the information
or methods presented.
Any procedures demonstrated here are potentially dangerous and could result in injury or damage.
Louisiana Tech University and the State of Louisiana, their officers, employees, agents or volunteers, are
not liable or responsible for any injuries, illness, damage or losses which may result from your using the
materials or ideas, or from your performing the experiments or procedures depicted in this presentation.
If you do not agree, then do not view this content.
The copyright label, the Louisiana Tech logo, and the β€œliving with the lab” identifier should not be removed
from this presentation.
You may modify this work for your own purposes as long as attribution is clearly provided.
2
computing distance
The Maxbotix sensor measures the time required for the burst of sound to travel to the target
𝑓𝑑
and back. The speed of sound is 1,126 in dry air at 68°F, which means that sound can travel
𝑠
1 inch in 74 ΞΌs:
𝑠𝑝𝑒𝑒𝑑 π‘œπ‘“ π‘ π‘œπ‘’π‘›π‘‘ = 1,126
𝑓𝑑 12 𝑖𝑛
𝑠
1 𝑖𝑛
βˆ™
βˆ™
=
𝑠
𝑓𝑑 1,000,000 πœ‡π‘ 
74 πœ‡π‘ 
Since the sound wave must travel out to the target and back again, a factor of 2 must be
incorporated into distance calculations. If a variable β€œduration” records the time of flight of the
sound wave, then the distance to the target in inches is computed as follows:
π‘–π‘›π‘β„Žπ‘’π‘  = π‘‘π‘’π‘Ÿπ‘Žπ‘‘π‘–π‘œπ‘› (πœ‡π‘ ) βˆ™
π‘Ÿπ‘œπ‘’π‘›π‘‘ π‘‘π‘Ÿπ‘–π‘
1 𝑖𝑛
βˆ™
2 π‘œπ‘›π‘’ π‘€π‘Žπ‘¦ π‘‘π‘Ÿπ‘–π‘π‘  74 πœ‡π‘ 
3
specifications for MB1261
β€’
β€’
β€’
β€’
β€’
reliable measurement range: 50cm to 10m (20 inches to 35 feet)
supply voltage: 3.3V to 5V (we will use 5V)
frequency: 42kHz (human hearing = 20Hz to 20kHz)
10 readings can be taken per second (10Hz sampling)
analog voltage output of Vcc/1024 for every 2cm (for Vcc=5V and a 10-bit ADC, an output change of 1 = 2cm)
MB
1261
4
11-inch
wide board
beam pattern
sensor can see a 0.25-inch diameter dowel 6-feet away if it is straight ahead
3.5-inch
diameter dowel
1-inch
diameter dowel
0.25-inch
diameter dowel
can’t see me 
5
POWER
0
1
2
3
4
5
RESET
3V3
5V
GND
GND
Vin
AREF
GND
13
12
PMW 11
PMW 10
PMW 9
8
7
PMW 6
PMW 5
4
PMW 3
2
TX 1
RX 0
connection to an Arduino
MB
1261
DIGITAL
ANALOG
6
connection to an Arduino
7
Arduino sketch
void setup() {
Serial.begin(9600);
}
void loop() {
int output = analogRead(0);
int
distanceCM = output * 2;
float distanceIN = distanceCM / 2.54;
float distanceFT = distanceIN / 12.0;
Serial.println(distanceCM);
delay(1000);
// use a baud rate of 9600 bps when printing to the monitor
//
//
//
//
read the voltage
compute distance
compute distance
compute distance
at
in
in
in
analog pin 0
centimeters
inches
feet
// print out distance in centimeters on LCD
// wait 1000ms between readings
}
8
example application
A piezospeaker is installed on the breadboard to allow the device to output an irritating noise whose
frequency is proportional to the distance from the sensor to a target.
void setup() {
Serial.begin(9600);
pinMode(12,OUTPUT);
}
void loop() {
int output = analogRead(0);
int
distanceCM = output * 2;
float distanceIN = distanceCM / 2.54;
float distanceFT = distanceIN / 12.0;
int tone_freq = distanceCM*40;
tone(12,tone_freq);
// use a baud rate of 9600 bps when printing to the monitor
// declare pin 12 as an output for speaker
//
//
//
//
read the voltage
compute distance
compute distance
compute distance
at
in
in
in
analog pin 0
centimeters
inches
feet
// a freq of 40*cm is good
// send a tone out of pin 12
}
digital
output
(pin 12)
9