Sensors - Thames & Kosmos Code Gamer Experiment Manual

Coding workshop ? game with kosmobits
Table of Contents

Advertisement

SENSORS

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
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.
32
CodeGamer manual inside english.indd 32
Motion
sensor
analogRead()
,
Of course, you will also have to tell
pin to read. In general, it will be the
KOSMOBITS_SENSOR_PIN
KosmoBits_Pins.h
file with
#include <KosmoBits_Pins.h>
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.
Temperature
sensor
Light
sensor
analogRead()
, which is defined in the
file. So you should always link this
Sound
sensor
which
if you want to
7/19/16 12:32 PM

Advertisement

Table of Contents
loading

Table of Contents