today I'm tinkering with these little electronic distance sensors they're
cheap and all over the place for Arduino and yeah I thought they'd be useful for
a future project that I'm working on let's just give you a hint as to what
that project might be anyway if if all goes well and I want to mount one of
these on it so that I can tell how far it is away from you no walls dogs tables
things like that so I need to figure out how to use it I try to start on the
front here on the front there's too little they look like speakers or
microphones and actually they kind of work like either one but in really high
frequencies one one actually transmits on one receives as you can tell by the T
and they are there on the back there's three chips
this one over here says says RC W 9006 one of the middle says RC Dobby l nine
one nine zero and this one over here he's gonna tweak lis anonymous no idea
and just a double check gets also scrubbed off this one so I don't know
what kind of secrets are hiding in there but whatever anyway hey I did a bunch of
googling on these two part numbers and I came up with absolutely nothing except
for things pointing back to this module so yeah let's uh take a quick peek at
what kind of information we can find on this thing with some googling for the
part number
manual for it it's this one looks slightly different it's got regatta go
crystal on there the one that I've got doesn't not only doesn't it have a
crystal it doesn't have anything that looks like a crystal on it but the part
number the board's the same the pins are the same so this give us some
information anyway there are some good useful information right there five
volts less than two milliamps when it's not doing anything fifteen when it is
the sensing beam is it less than fifteen degrees which is nice so you're not
gonna get a lot of extraneous crud you're getting just what's right in
front of it claims to be good between two centimeters and four meters or 20
and thirteen feet for those of you in that country resolution up to a third of
a centimeter it's not bad now measuring angle thirty degrees say it's just plus
and minus fifteen from the front of it the trigger input pulse that's important
when you when we come to the software leader ten microseconds and then the
dimensions and there's just showing the the beam width I'm assuming that's
horizontal and vertical because these things aren't really don't have any kind
of pattern they're just a circle so you know we didn't see this before 40
kilohertz which is about twice what the limits of human hearing are human
hearing normally tops out well for young and who haven't been exposed to lots of
loud rock and roll people top out about 20 kilohertz so that's twice what I'm a
normal person can hear dog might notice it so it looks like there's some special
signaling and a little bit of timing you have to do so on the on the signal pin
you have to give it a quick wake up pulse of 10 microseconds and then
a pulse-width dude okay ultrasonic transducer will send out 840
kilohertz pulses bbbbb dig and then as an echo back comes back to you
I guess the pulse would okay pulse of course must a distance fine it's gonna
be some math involved hardware interface power ground trigger and echo okay and
it's got some sample code it's using a library but the library isn't included
with it with this document anywhere that I found it so the arduino ide comes with
this ping sketch here which is freezing the ultrasonic rangefinder in returning
a distance which is just what we're doing so you connect be pushed to the Y
volt ground to the ground and signal of the two pin seven here's my first
problem this one is assuming an older-style unit a 3-pin unit but mine
is a four pin unit hannelius
yeah there's that three pin unit that's the one that it's assuming which isn't
the one I've got and if you go googling around pretty much everyone is
a four pin unit that one's a five weird but most of them are four pin you can
find online and that's indeed what I ended up buying so what I've done with
looking around online and finding various other people's ideas is I have
gone in and mutated this sketch look at that in a minute
first of all we'll go and hook it up I've just chosen these arbitrarily it
doesn't really matter the echo pin being input pin 11 the trigger pin being the
output pin 12 and of course voltage and ground so let's do this ground is over
there I mean yeah this is zooming here so ground is over there but VCC there
and echo and get in there you trigger and then on the arduino do the same
things
echo my sketch said echo goes to pin 11 eight nine ten
no ever echo is the first one right yeah and then pin twill so crap what's going
on here cheap DuPont where's Neil Evans and
twelve and just do a quick upload so no quick upload there we go
my serial print is so three-setter for 9600
okay here we go and it's showing something about 16 centimeters away
which let's just see here that's about 15 that's good let's back
it off to 15 and 5 there's about 20
that's pretty damn close let's move it a little bit closer 15 20 all right let's
put something actually I set the ruler down right there so we can see it let's
go on here
why is it reading you that like that
command quit twisting there okay 18 19 centimeters and put something about
halfway in between six centimeters so perfect and let's point it up at the
ceiling perfect I don't know if that's 120
centimeters away but we'll say it is for good measure so that was fairly
straightforward just actually yeah let's go and look at the code shall we so what
I've done on the code instead of using one pin for both I've split it so I'm
gonna echo pin in a trigger pin in a note syrup in blah blah two pins trigger
mold make the output to note the input in the input
that's just left over define the the variables that's completely left over
from the old one this I just in the old one it had you changing on the original
head changing the pin mode between here and here to between the output and input
but since I'm using two pins it on half to accept put those up there and we
write to the trigger pin now then here is this this stuff from number the
timing in the datasheet there needs that to microsecond low and then go high and
then come low again so that's what causes the firmware in the little thing
to send out it's 840 kilohertz pulses and then as soon as that's happened we
set this duration variable to be to use the pulse in function which is something
I've never used and I just copied again it's straight
from the demo sketch so I'm not entirely sure how it works
feel free to explain it if you're if you're a guru or just go and look in the
Arduino documentation and if you're good at coding and things like that you
should be able to figure it out anyway so that returns a microseconds number
for the actual duration it took from between when the last thing happened
here which is when we told it to send out its pulse and here when it received
the pulse back on the receiver microphone transducer thingy some math
this actually calls some functions that are down below here and then we just
print them out the original sketch just hitting shows in centimeters I added
duration just cuz so here is the actual math explained and again that's just
straight out of the demo sketch I didn't do any of that myself I just trusted
them to be correct and as you saw on the bench it was pretty damn close so after
that and being all proud of myself that it actually works I decided to see if I
could find any other ways of doing this remember in the datasheet it was talking
about using a library so I wandered off and found a or is it a library called
new ping where is it down here new ping and it came with these demo sketches so
I grabbed that one and here is that demo sketch and I've already modified it for
my pins that I'm already connected to because why wouldn't I
and actually let's set this to 9600
because that's what I'm using does it compile it does upload that uploading
done uploading okay let's serial monitor that one
why is that all over the map
okay so I just wiggled the transducer a little bit so that it's actually aiming
there and not up into the yonder and up into all the well actually let's just so
up above it on the wall there there's all kinds of crap so that would probably
create all kinds of weird echoes but I've got it
aiming pretty much at my sign here so know that 17 centimeters and again if I
move something in between it 78 centimeters
yeah hooey its aim it up at the ceiling under mm that's bouncing around but yeah
that's pretty close to what it was before wasn't it and get it back into
here again there we go so that's another way of doing it and that code was even
simpler really library define your pins maximum distance sense is rated for 400
yeah the data sheets at 400 this says 4 to 500 but the the library lets you set
the max distance of 2 meters in this case and then there is the command that
does all the magic for setting it up send it with 2 pins and the maximum
distance and then I should do that instead that'll make it a little bit
easier to deal with make that a bit short a bit longer so you serial.print
the pin and then this is what's returned from the library you could also like yes
I know the library documentation actually I wonder if there's a serial
ping inches
maybe there is
yes there is in the new ping library here's the different keywords that are
possible ping ping inches ping centimeters median ping time I checked
I'm wiping result time Marie microsecond millisecond and converts okay so if for
whatever reason you wanted it to be in inches you would just do that no not
that that there you go and that would turn it into inches I don't want to do
that why would I want to do that okay so there's that so that's I mean that's
nothing earth-shattering but I just spent some some time tinkering with this
so that I can figure out how to use it I've got to do some more as always I've
got to figure out coding a lot better so I can make use of that number the
distance number in a sketch for collision avoidance or something like
that I mean there are other ways to do collision avoidance of course these
things these things are actually designed for collision avoidance I'm
using them for detecting trains mostly but we could also put one of these on
the front of our mobile vehical the jessica thing to prevent crashing into
stuff but this has a lot more range these things are only good for you know
kind of that sort of range this thing you know as we've seen it's good for
over a meter which is excellent so there's I mean there's lots of other
things to do I just wanted to get to playing with this and get a little bit
comfortable with it so I know what I can do with it when I get around to it that
was a little bit interesting for you um informative maybe some of you haven't
seen these things before I don't know a huge amount more yet than
what I've talked about here I did find a few web pages and stuff and I found that
manual and just simple googling should find that stuff for YouTube but for what
it's worth there it is a nice simple little module oh thanks for watching um
as always if you got any comments or questions please submit them down below
for the discussion of our peers oh yeah somebody's gonna ask the beer is
pioneer harvest stout from farmer e estate Brewing Company in nepo Manitoba
it's not nearly as heavy a stout is as a lot of them it's quite wait it's a
little bit hoppy not quite as roasty but it's definitely
a drinkable beer and of course you gotta wake local beer anyway now I think
that's everything I wanted to talk about today I'm probably more rambling than I
wanted to do so uh yeah thanks for watching comments questions complaints
criticisms bad jokes whatever they're in the comments I'll talk to you later
No comments:
Post a Comment