User manual

2
5
10t
h
Da
y
In the Advent calendar today
•1x butto
n
Displaying the push o
f
a butto
n
Toda
y
,
y
our IoT-board will react to a mechanical push o
f
a but-
ton and send a message to the wireless inter
f
ace.
C
omponents: 1x board, 1xbutton, 1xpotentiometer,
5xjumpers (different lengths)
Digita
l
pins can not on
l
y output
d
ata, e.g. via LEDs,
b
ut a
l
so
b
e
used to enter data. We use a button
f
or input in todays project
that is directly connected to the board. The button has
f
our
connection pins, with two opposite ones
(
large distance
)
being
connected to each other from case to case. While the button
is pushed, all four connections are connected to each other. In
contrast to a switc
h
, a
b
utton wi
ll
not
l
atc
h
. T
h
e connections
are
b
ro
k
en at once w
h
en t
h
e
b
utton is re
l
ease
d.
W
h
en a +5-V-signa
l
is pen
d
ing on a
d
igita
l
input, t
h
is is eva
l
uate
d
as
l
ogica
ll
y
t
rue
.
If the button were open, the input would not have any clearly defi ned condition. When a program
requests t
h
is pin, t
h
ere may
b
e ran
d
om resu
l
ts. In or
d
er to prevent t
h
is, a comparative
l
y very
h
ig
h
resis
-
tor is connected to the ground. This pull-down-resistor pulls the status of the input pin back down to 0
V
when the button is open. Since the resistance is very high, there is no danger of short circuit while the
b
utton is pus
h
e
d
eit
h
er. W
h
en t
h
e
b
utton is pus
h
e
d
, +5V an
d
t
h
e groun
d
l
ine are connecte
d
d
irect
l
y via
t
h
is resistor
.
T
he
Sketch
The program for this day is called
T
a
g
10.
i
n
o
an
d
l
ocate
d
in
d
irectory
T
a
g
1
0
.
d
i
g
ita
l
Rea
d
is ca
ll
e
d
to eva
l-
uate w
h
et
h
er t
h
e
b
utton
h
as
b
een pus
h
e
d
:
v
o
i
d l
o
o
p()
{
int reading = digitalRead
(
buttonPin
)
;
if
(
reading != lastButtonState
)
{
lastDebounceTime = millis
();
}
if
((
millis
()
– lastDebounceTime
)
> debounceDelay
)
{
if
(
reading != buttonState
)
{
buttonState = read
i
ng;
if
(
buttonState == HIGH
)
{
ledState = !ledState
;
}
}
}
d
i
g
i
talWrite
(
LedPin, ledState
);
If the button was been pushed, a messa
g
e will be sent throu
g
h the wireless interface:
if
(
readin
g
!= lastButtonState
)
{
HC05.print
(
“Button pushed\n”
);
}
Displayin
g
the reaction o
f
the IoT-boar
d
T
h
e App Seria
l
B
l
uetoot
h
Termina
l
that has been used be
f
ore is used
f
or displaying the push o
f
the button on the Smartphone. A
f
ter connectin
g
to the IoT-board, the messa
g
e Button
p
us
h
e
d
wi
ll
b
e
d
isp
l
a
y
e
d
w
h
en t
h
e
b
utton is pus
h
e
d
.
T
he IoT-board is very long; therefore, the button must be placed crosswise on the board, and
th
e jumpers must
b
e partia
ll
y p
l
ace
d
b
e
l
ow t
h
e connecte
d
USB ca
bl
e
.
Messages received are written in the terminal win
-
dow in green
.
1
0. Day
15007-3 Conrad Adventskalender Internet of Things 2017_en.indd 2515007-3 Conrad Adventskalender Internet of Things 2017_en.indd 25 13.08.2017 17:03:1113.08.2017 17:03:11