current setup
5v to 5v
Trigger to pin 23
Echo to 1k ohm resistor to pin 24
ground to ground

Code: Select all
Code: Select all
#!/usr/bin/python
#+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#|R|a|s|p|b|e|r|r|y|P|i|-|S|p|y|.|c|o|.|u|k|
#+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#
# ultrasonic_1.py
# Measure distance using an ultrasonic module
#
# Author : Matt Hawkins
# Date : 09/01/2013
# Import required Python libraries
import time
import RPi.GPIO as GPIO
# Use BCM GPIO references
# instead of physical pin numbers
GPIO.setmode(GPIO.BCM)
# Define GPIO to use on Pi
GPIO_TRIGGER = 23
GPIO_ECHO = 24
print "Ultrasonic Measurement"
# Set pins as output and input
GPIO.setup(GPIO_TRIGGER,GPIO.OUT) # Trigger
GPIO.setup(GPIO_ECHO,GPIO.IN) # Echo
# Set trigger to False (Low)
GPIO.output(GPIO_TRIGGER, False)
# Allow module to settle
time.sleep(0.5)
# Send 10us pulse to trigger
GPIO.output(GPIO_TRIGGER, True)
time.sleep(0.00001)
GPIO.output(GPIO_TRIGGER, False)
start = time.time()
while GPIO.input(GPIO_ECHO)==0:
start = time.time()
while GPIO.input(GPIO_ECHO)==1:
stop = time.time()
# Calculate pulse length
elapsed = stop-start
# Distance pulse travelled in that time is time
# multiplied by the speed of sound (cm/s)
distance = elapsed * 34300
# That was the distance there and back so halve the value
distance = distance / 2
print "Distance : %.1f" % distance
# Reset GPIO settings
GPIO.cleanup()
Yes, you can use the SRF10. Could you say where you bought it or point to the specific model?leeqicheng wrote:I just found out that my ultrasonic sensor is SRF10 using SDA and SCL is it still possible to use on raspberry pi ? If yes do u have any reference or source that i can take a look Thanks
I know that you have a different model but I thought I would comment on the fact that the pin labelling in this picture is incorrect.leeqicheng wrote:i am using a 5 pin ultra sonic sensor which look like this. (Model SRF04)
![]()
BMS Doug wrote:I know that you have a different model but I thought I would comment on the fact that the pin labelling in this picture is incorrect.leeqicheng wrote:i am using a 5 pin ultra sonic sensor which look like this. (Model SRF04)
![]()
The label states that Pin 2 is the trigger while I can clearly read from the board that Pin 2 is the Echo.
joan wrote:Yes, you can use the SRF10. Could you say where you bought it or point to the specific model?leeqicheng wrote:I just found out that my ultrasonic sensor is SRF10 using SDA and SCL is it still possible to use on raspberry pi ? If yes do u have any reference or source that i can take a look Thanks
Connection to the Pi is simple:leeqicheng wrote:
Correction the actual image that i have is this