Page 97 - Programming the Photon Getting Started With the Internet of Things
P. 97

Figure 5.1 A push-button switch.


             You  are  going  to  use  a  small  push-button  switch  to  make  or  break  a  connection
        between 3V3 and one of the digital pins on the Photon, which you will configure in your
        firmware  program  that  you  will  upload  to  the  Photon.  If  you  just  connect  the  switch

        directly to the Photon board, this creates a problem when the switch is not closed, as the
        input pin is not connected to anything. This is referred to as floating, and could easily give
        you false readings when reading the state of the switch. When creating a switch circuit,
        you need your readings to more precise, and the way to do this is using what is called a

        pull-down resistor.

             Now  think  about  what  happens  when  the  button  is  not  pressed  with  the  pull-down
        resistor in the circuit. The input pin will be connected through a 10-K resistor to ground.
        Although the resistor will restrict the flow of current, there is still enough to ensure that

        the input pin will read a LOW logic value. 10 K is a common pull-down resistor value.
        The  value  of  the  resistor  must  be  low  enough  to  make  it  resistant  to  any  electrical
        interference, but also at the same time it must be high enough so that it prevents excessive
        current  drain  when  the  switch  is  closed.  When  the  button  is  pressed,  the  input  pin  is
        directly connected to 3V3 through the button. In this circuit the current has two options:


               It can flow through a zero resistance path to 3V3.

               It can flow through a high-resistant path to ground.
   92   93   94   95   96   97   98   99   100   101   102