EasyManuals Logo

Arduino Pro Mini User Manual

Arduino Pro Mini
311 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #100 background imageLoading...
Page #100 background image
With a digital pin, you have only a few options to transmit information. You
can set the pin to
HIGH
or
LOW
, and you can control how long it remains in a
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
LOW
when it receives the echo. That
is, the signal pin remains in a
HIGH
state for exactly the time it takes the sound
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
HIGH
state manually, but
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.
pulseIn
accepts three
parameters:
pin: Number of the pin to read the pulse from.
type: Type of the pulse that should be read. It can be
HIGH
or
LOW
.
timeout: Timeout measured in microseconds. If no pulse could be detected
within the timeout period,
pulseIn
returns 0. This parameter is optional
and defaults to one second.
Note that in the whole process, only one pin is used to communicate with the
PING))). Sooner or later, youll realize that IO pins are a scarce resource on
the Arduino, so its 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
microseconds_to_cm
method performs the calculation.
Chapter 5. Sensing the World Around Us 82
report erratum discuss
www.it-ebooks.info

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

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

Arduino Pro Mini Specifications

General IconGeneral
BrandArduino
ModelPro Mini
CategoryMotherboard
LanguageEnglish

Related product manuals