Page 1 of 1

ultrasonic sensor raspberry (Error)

Posted: Wed May 14, 2014 2:32 pm
by leeqicheng
Hi guys recently i have been testing out raspberry pi and i seems to have a problem reading data from ultrasonic sensor i followed this guide http://www.raspberrypi-spy.co.uk/2012/1 ... on-part-1/ but cant seems to get a value. When i run the python script it will just hang there and no respond to anything. Can anybody guide me or spot any mistake that i am facing thanks

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

Image

Re: ultrasonic sensor raspberry (Error)

Posted: Wed May 14, 2014 4:33 pm
by joan
You really shouldn't feed 5V into a Raspberry Pi gpio. They are 3.3V.

You may have killed the gpio, but as the echo is brief you are probably fine.

What sensor model have you got?

A listing of the software you are using is also useful (in

Code: Select all

 
quotes to preserve spacing).

Re: ultrasonic sensor raspberry (Error)

Posted: Thu May 15, 2014 1:06 am
by leeqicheng
i am using a 5 pin ultra sonic sensor which look like this. (Model SRF04)

Image

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()
Update
=======
i did receive some reading from the sensor but it was after i touch the resistor but i doubt it was accurate.
Its very slow in reading the value and print the value out
I believe the signal is kind of distorted i need to move the sensor to find for the signal to get a value

Re: ultrasonic sensor raspberry (Error)

Posted: Thu May 15, 2014 4:50 am
by joan
You should NOT be connecting the echo pin to a gpio unless you are using a voltage divider.

Could you cut & paste the program output?

Re: ultrasonic sensor raspberry (Error)

Posted: Thu May 15, 2014 7:20 am
by leeqicheng
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

Re: ultrasonic sensor raspberry (Error)

Posted: Thu May 15, 2014 7:24 am
by joan
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
Yes, you can use the SRF10. Could you say where you bought it or point to the specific model?

Re: ultrasonic sensor raspberry (Error)

Posted: Thu May 15, 2014 7:49 am
by BMS Doug
leeqicheng wrote:i am using a 5 pin ultra sonic sensor which look like this. (Model SRF04)

Image
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.
The label states that Pin 2 is the trigger while I can clearly read from the board that Pin 2 is the Echo.

Re: ultrasonic sensor raspberry (Error)

Posted: Thu May 15, 2014 8:25 am
by leeqicheng
BMS Doug wrote:
leeqicheng wrote:i am using a 5 pin ultra sonic sensor which look like this. (Model SRF04)

Image
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.
The label states that Pin 2 is the trigger while I can clearly read from the board that Pin 2 is the Echo.

Correction the actual image that i have is this

Image

Re: ultrasonic sensor raspberry (Error)

Posted: Thu May 15, 2014 8:27 am
by leeqicheng
joan wrote:
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
Yes, you can use the SRF10. Could you say where you bought it or point to the specific model?

Image

Above is the model i currently have but can i request a tutorial or some guides and also can it be written in python scripts ?

Re: ultrasonic sensor raspberry (Error)

Posted: Thu May 15, 2014 8:39 am
by joan
There are hundreds of similar modules. I haven't seen one with I2C in that configuration. Can you point to the specs?

Re: ultrasonic sensor raspberry (Error)

Posted: Thu May 15, 2014 9:04 am
by BMS Doug
leeqicheng wrote:

Correction the actual image that i have is this

Image
Connection to the Pi is simple:

5v from Pi (GPIO pin 2) goes to 5v on the board
SDA on Pi (GPIO pin 3) goes to SDA on Board
SCL on Pi (GPIO pin 4) goes to SCL on Board
Gnd on Pi (GPIO pin 6) goes to Gnd on board.

Image
pins

Re: ultrasonic sensor raspberry (Error)

Posted: Thu May 15, 2014 9:08 am
by BMS Doug
configure your i2c and find the address of your board.

this instructable seems to give a good guide to connecting and programming a Ultrasonic range finder, yours will probably work similarly in principle but some details may be different. to get the correct connection the exact description of your sensor is needed.


I can recommend using the adafruit WebIDE, its very good and comes with the adafruit library easily available to copy to your projects. (I think Adafruit has a i2c ultrasonic sensor example already).

you install the webIDE onto your pi and then you access it from another PC as a webpage (to your Pi's ip address). (it doesn't work very well with tablets or smartphones yet)

Re: ultrasonic sensor raspberry (Error)

Posted: Thu May 15, 2014 6:37 pm
by MattHawkinsUK
For anyone following my tutorial originally quoted at the start of this thread remember that the voltage divider bit is important! It ensures you don't feed the 5V echo signal into a GPIO pin that really wants 3.3V.