際際滷

際際滷Share a Scribd company logo
1
Raspberry Tutorial #3
- Measuring the distance -
Dong Ho Son
POSTECH
Pohang, Korea
donghoson@postech.ac.kr
2
Measuring the distance - Overview
 Lets use the sensor
 Ultrasonic distance sensor
 A sensor that can measure the distance to an object by using sound waves
Source: education.rec.ri.cmu.edu/content/electronics/boe/ultrasonic_sensor/1.html
3
Measuring the distance - components
 Lets measure the distance
 Necessary Components
 1 x Raspberry Pi
 1 x Breadboard
 2 x Resistor
 1 x Ultrasonic sensor
 Jumper cables
4
Measuring the distance  Circuit Configuration
 VCC  5V pin
 Trig  the pin GPIO 18
 Echo  resistors
 GND  Ground pin
5
Measuring the distance - Python
6
Measuring the distance - Python
 GPIO.setup(GPIO_TRIGGER, GPIO.OUT)
 Select GPIO #18 as output pin
 To make ultrasonic signal
 GPIO.setup(GPIO_ECHO, GPIO.IN)
 Select GPIO #24 as input pin
 To receive the signal
 GPIO.output(GPIO_TRIGGER, True)
time.sleep(0.00001)
GPIO.output(GPIO_TRIGGER, False)
 Send the ultrasonic signal
7
Measuring the distance - Python
 GPIO.input(GPIO_ECHO)
 High while sending signal
 Low when signal is returned
 TimeElapsed = StopTime  StartTime
 Time difference between start and arrival
 distance = (TimeElapsed * 34300) / 2
 Multiply with the sonic speed 34300 cm/s
 Divide by 2, because there and back
8
Measuring the distance - Result
 Distance is measured!

More Related Content

Raspberry pi tutorial #3

  • 1. 1 Raspberry Tutorial #3 - Measuring the distance - Dong Ho Son POSTECH Pohang, Korea donghoson@postech.ac.kr
  • 2. 2 Measuring the distance - Overview Lets use the sensor Ultrasonic distance sensor A sensor that can measure the distance to an object by using sound waves Source: education.rec.ri.cmu.edu/content/electronics/boe/ultrasonic_sensor/1.html
  • 3. 3 Measuring the distance - components Lets measure the distance Necessary Components 1 x Raspberry Pi 1 x Breadboard 2 x Resistor 1 x Ultrasonic sensor Jumper cables
  • 4. 4 Measuring the distance Circuit Configuration VCC 5V pin Trig the pin GPIO 18 Echo resistors GND Ground pin
  • 6. 6 Measuring the distance - Python GPIO.setup(GPIO_TRIGGER, GPIO.OUT) Select GPIO #18 as output pin To make ultrasonic signal GPIO.setup(GPIO_ECHO, GPIO.IN) Select GPIO #24 as input pin To receive the signal GPIO.output(GPIO_TRIGGER, True) time.sleep(0.00001) GPIO.output(GPIO_TRIGGER, False) Send the ultrasonic signal
  • 7. 7 Measuring the distance - Python GPIO.input(GPIO_ECHO) High while sending signal Low when signal is returned TimeElapsed = StopTime StartTime Time difference between start and arrival distance = (TimeElapsed * 34300) / 2 Multiply with the sonic speed 34300 cm/s Divide by 2, because there and back
  • 8. 8 Measuring the distance - Result Distance is measured!