Arduino Uno Quick Start Manual page 100

Hide thumbs Also See for Arduino Uno:
Table of Contents

Advertisement

With a digital pin, you have only a few options to transmit information. You
can set the pin to
HIGH
particular state. For many purposes, this is absolutely sufficient, and in our
case it is, too. When the PING))) sensor sends out its 40-kHz chirp, it sets the
signal pin to
HIGH
and then sets it back to
is, the signal pin remains in a
to travel to an object and back to the sensor. Loosely speaking, we are using
a digital pin for measuring an analog signal. In the following figure, you can
see a diagram showing typical activity on a digital pin connected to a PING)))
sensor.
We could measure the duration the pin remains in
the
pulseIn
method already does all the dirty work for us. So, we use it in line
18 after we have set the signal pin into input mode again.
parameters:
• pin: Number of the pin to read the pulse from.
• type: Type of the pulse that should be read. It can be
• timeout: Timeout measured in microseconds. If no pulse could be detected
within the timeout period,
and defaults to one second.
Note that in the whole process, only one pin is used to communicate with the
PING))). Sooner or later, you ll realize that IO pins are a scarce resource on
the Arduino, so it s really a nice feature that the PING))) uses only one digital
pin. When you can choose between different parts performing the same task,
try to use as few pins as possible.
We have only one thing left to do: convert the duration we have measured
into a length. Sound travels at 343 meters per second, which means it needs
29.155 microseconds per centimeter. So, we have to divide the duration by
29 and then by 2, because the sound has to travel the distance twice. It
travels to the object and then back to the PING))) sensor. The
method performs the calculation.
Chapter 5. Sensing the World Around Us
or
LOW
, and you can control how long it remains in a
LOW
HIGH
state for exactly the time it takes the sound
pulseIn
returns 0. This parameter is optional
www.it-ebooks.info
when it receives the echo. That
HIGH
state manually, but
pulseIn
accepts three
HIGH
or
LOW
microseconds_to_cm
82
.
report erratum
discuss

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the Arduino Uno and is the answer not in the manual?

Subscribe to Our Youtube Channel

Table of Contents