Hondo's Cabin
http://www.hondosackett.com/yabb/YaBB.pl The Cabin >> Raspberry and Other Pies >> Using an Ultrasonic sensor on the Raspberry Pi. http://www.hondosackett.com/yabb/YaBB.pl?num=1485547386 Message started by Fernando on Jan 27th, 2017, 3:03pm |
Title: Using an Ultrasonic sensor on the Raspberry Pi. Post by Fernando on Jan 27th, 2017, 3:03pm I have always thought that this sensor (the HC-SR04) was a bit more accurate in its resolution and thought it would be useful for ultra-sonic hi-res work. It is however still useful in many apps one needs to measure the distance of things with. And, according to one of the videos, has a range of 500cm, which is 5 meters or about 16ft with a +/- .3cm or 3mm (about an 1/8th of an inch) resolution. The HC-SR04 is very cheap on ebay, like $2 to $3 each and as low as $1.50 if you buy in bulk. Unfortunately, my walk-in & buy source for many parts - Tinkersphere, has them for over $9 a piece. Thing is how to connect it to a R-Pi or Arduino? And how to collect the information it receives? Connecting it is a bit tricky as it is a 5V sensor with 5V data, which can burnout your R-Pi. Thus you need to connect a couple of resistors to it to lower the 5V data to around 3v for the R-Pi to handle safely. so double check your wiring before turning on the R-Pi. It only uses 4 wires and 2 resistors on a bread board. You will need 2 GPIO pins for this, one to transmit the pulse and another to read the echo; the difference in time is your distance. this takes some math to do. Here is 2 videos that shows how to do it. The first one says to "go to Github and get my software for this" while the second shows you the python scrip on how to do it. The second is better for the programming while the first shows how to wire it up. Video 1: https://www.youtube.com/watch?v=ShnzQSFwVXQ Video 2: https://www.youtube.com/watch?v=xACy8l3LsXI Personal note: From the looks of it, you can have more than one sensor and all use the same trigger GPIO pin, but each echo read needs its own GPIO Pin. So you can have a robot or device that measures front, back and the sides with 4 sensors. You just need to add about 4 lines of code per sensor to get each own measurements calculated and printed. If you are interested in the Arduino version of connecting this sensor to it, see this video: https://www.youtube.com/watch?v=ZejQOX69K5M I recommend you should see this Arduino video as it explains the principles behind it and how things work mathematically. |
Title: Re: Using an Ultrasonic sensor on the Raspberry Pi Post by Hondo I. Sackett on Jan 27th, 2017, 7:54pm Neat! |
Hondo's Cabin » Powered by YaBB 2.1! YaBB © 2000-2005. All Rights Reserved. |