Object Detection by ultra sonic

Download Report

Transcript Object Detection by ultra sonic

EURLAB
Object Detection
Object Detection
by Ultrasonic
How to install and program a ultra
sonic sensor with Arduino Board
Istituto Tecnico Industriale
A.Monaco
EURLAB
Object Detection
Needed Parts
• Arduino (e.g. Arduino Uno)
• Sensor (HC-SR04)
• Cabling
– 1 x USB PC-Arduino
– 10 x Cable 0,75 mm² (length approx. 10 cm)
•
•
•
•
1 x Computer / Laptop
1 x Breadboard
2 x LEDs (green, red)
2 x Resistor 220 Ω
Istituto Tecnico Industriale
A.Monaco
EURLAB
Object Detection
Module Specification
•
•
•
•
•
•
•
Distance: Detection between 2cm and 3m
Resolution: approx. 3mm
Voltage: 5V Current: < 2mA
Triggering: Falling edge (TTL - level)
Self measuring after sending a trigger (input)
PWM Signal will be returned (output)
Duration Measurement (Interval): 20ms
– 50 Measurements/Second
Istituto Tecnico Industriale
A.Monaco
EURLAB
Object Detection
Area of Application
Obstacle Detection
Distance Measurement
Level Indicators
Industrial Applications
Istituto Tecnico Industriale
A.Monaco
EURLAB
Object Detection
HW Setup on Breadboard
Pins (Sensor)
1: VCC, Voltage 5V
2: Trigger input, TTL-Level
3: Echo, output Measurement
result, TTL-Level
4: GND, 0V
Istituto Tecnico Industriale
A.Monaco
EURLAB
Object Detection
Schematic
Istituto Tecnico Industriale
A.Monaco
EURLAB
Object Detection
Programming Rules
Start Measurement
-> Arduino set a digital signal to 1
-> Sensor will watch that signal at pin2
-> After 10μs Arduino can set signal to 0
-> Measurement started
Send out ultra sonic
-> After 200μs, a 40 kHz Burst-Signal,
the ultra sonic sound wave will be send out by the sensor
-> Duration: 200μs
-> Sensor sets the output to high
Waiting for echo
-> If echo will be detected, the
-> Output falls to L-Level.
-> Time between high and low signal can be read out by Arduino
-> Time which the ultrasonic needs forth and
Get the measurement
-> The Arduino can directly fetch the measurement result (duration)
Istituto Tecnico Industriale
A.Monaco
EURLAB
Object Detection
Physics Ultrasound
•
•
•
•
•
Ultrasounds are sound waves
Frequencies higher of limit of human hearing.
Ultrasound is not different from 'normal‘ sound
Frequencies from 20 kHz up to several gigahertz.
Speed of ultrasound is 343,2 m/s
– in dry air,
– at 20 °C
Istituto Tecnico Industriale
A.Monaco
EURLAB
Object Detection
Physics Ultrasound
The sensor returns the duration of the echo in µs.
How can we calculate the correct distance?
An Example! – We want to calculate the distance in [mm]
1. We need to convert the speed of sound in [mm/us]
cair(20°)= 343,2
𝑚
𝑠
∗
1000𝑚𝑚
1𝑚
∗
1𝑠
𝑚𝑚
=0,3432
1000000µ𝑠
µ𝑠
2. Get the return value – let’s assume a time t of 100µs
3. Calculate the distance: s = v*t
s=cair*t = 0,3432
𝑚𝑚
µ𝑠
* 100 µs = 34,32 mm
4. Divide by 2 due to the signal goes forth and back
s = 34,32mm/2 = 17,16 mm
Istituto Tecnico Industriale
A.Monaco
EURLAB
Object Detection
Programming Sample
#define trigPin 12 // Trigger Pin
#define echoPin 6 // Echo Pin
#define REDLED 8
#define GREENLED 10
#define SpeedOfSound 0 // Constant – at defined temperature – see physics
long duration, distance; // duration used to calculate distance
void setup() {
pinMode(trigPin, OUTPUT); //Define Output Port
pinMode(echoPin, INPUT); //Define Input Port
pinMode(REDLED, OUTPUT);
pinMode(GREENLED, OUTPUT);
}
void loop() {
digitalWrite(trigPin, LOW); // Set Trigger Port to Low Signal – just to be sure
delayMicroseconds(2);
digitalWrite(trigPin, HIGH); // Set Trigger Port to high
delayMicroseconds(10);
// Be sure that signal is high for 10 ms
digitalWrite(trigPin, LOW); // Start measurement
duration = pulseIn(echoPin, HIGH);
// Get result in µs
distance = duration*SpeedOfSound/2; //Calculate distance based on the speed of sound /2 due to back and forth
if (distance < 5) digitalWrite(REDLED, HIGH);
// Handle distance - E.g. switch on RED LED
if (distance < 30) digitalWrite(GREENLED, HIGH); // Handle distance - E.g. switch on GREEN LED
delay(50); //Delay 50ms before next reading
digitalWrite(REDLED, LOW);
digitalWrite(GREENLED, LOW);
}
Istituto Tecnico Industriale
A.Monaco
EURLAB
Object Detection
Sensor Accuracy
• The system-conditioned measuring exactness
amounts to approx. 3 mm and is combined with
the internal sample rate of the module.
• Another factor is the temperature dependence of
the sonic speed in air.
• Approximately the sonic speed in relation of the
temperature in the area of -20°C till +40°C can be
calcutated with fomular:
Cair ≈(331,5 +0,6 * ϑ/°C) m/s
ϑ = Surrounding temperature in °C
Istituto Tecnico Industriale
A.Monaco
EURLAB
Object Detection
Best Practise
• The best measurement results are obtained by
reflection on smooth, flat surfaces.
• For distances up to 1m, the material of surface is rather
uncritically.
• Over short distances, of less than 1m, the angle to the
object can reach up to 45 °.
• Even quite thin objects are reliably detected. A normal
pen, for example, can be safely detect at a distance of
about 30cm.
• At maximum distance (3m) the object must be exact
targeted and there should be no other object in the
area (similar distance) in a emission cone of 15 °.
Istituto Tecnico Industriale
A.Monaco