![Thames & Kosmos Code Gamer Скачать руководство пользователя страница 34](http://html1.mh-extra.com/html/thames-and-kosmos/code-gamer/code-gamer_experiment-manual_1099224034.webp)
Temperature
sensor
Motion
sensor
Sound
sensor
Light
sensor
Sensors
So far, you have learned how
your KosmoDuino can react to
the push of a button. In this
experiment kit, though,
you will also find a
lot of sensors that
can be used to
help your
microcontroller
respond to its
environment. These
are the KosmoBits
modules!
Your controller can use the
temperature sensor to monitor
the temperature, while the light
sensor monitors brightness. The
motion sensor lets you record even the
slightest movements of the KosmoDuino,
and the sound sensor lets you listen for
noises.
But how does the KosmoDuino get the
information from the sensors? How does it learn
how warm or how bright it is?
Simple: The sensors relay their measurement readings to
the microcontroller in the form of electrical voltage. The
microcontroller can then read this voltage through one of
the pins. A lot of the pins can do a lot more than distinguish
“on” from “off.” They can also measures different voltage
levels. That’s what is handled by the order
analogRead()
,
which lets you determine the voltage at a pin. The result is
a numerical value from 0 to 1023. The higher the voltage
arriving at a pin, the greater the numerical value. 0
indicates no voltage at all, while 1023 indicates 5 volts.
Of course, you will also have to tell
analogRead()
which
pin to read. In general, it will be the
KOSMOBITS_SENSOR_PIN
, which is defined in the
KosmoBits_Pins.h
file. So you should always link this
file with
#include <KosmoBits_Pins.h>
if you want to
access the KosmoBits sensor modules.
You have already learned about the serial monitor. It’s an
important tool for working with the sensors. See the next
projects to find out why.
32
SENSORS
CodeGamer manual inside english.indd 32
7/19/16 12:32 PM