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

Figure 6.13 Reading temperature from the Photon.




        Measuring Distance Using an HC-SR04 Sensor


        This  experiment  includes  the  use  of  an  HC-SR04  ultrasonic  range  finder  to  detect  the
        distance  from  certain  objects,  as  well  as  being  used  as  a  motion  detector  to  determine
        when something gets too close. These sensors are more commonly used in robotics to stop

        the robot from bashing into objects. The ultrasonic sensor sends out pulses every so often
        using one sensor, and the other sensor reads the feedback of those pulses and determines,
        based  on  the  timings  in  between,  how  far  away  an  object  is.  This  works  on  the  same
        principle as echolocation, which is how bats are able to see at night or how dolphins can

        detect their surroundings. For this experiment we are going to use the components listed in
        Table 6.4.



            Schematic Reference                       Description                           Appendix


          M1                             Photon board                              M1


                                         Breadboard                                H1


                                         Jumper wires                              H2



          H1                             HC-SR04                                   M2



        Table 6.4 Components and Hardware

             The ultrasonic range finder used for this experiment has four pins. Two of the pins are
        for  5-V  power  and  ground;  the  other  two  pins  are  labeled  trigger  and  echo.  When  the
        trigger pin is activated for a very short period, it sends out pulses of ultrasound. When the
        pulse is returned to the range finder the echo pin will indicate this. The breadboard layout
   132   133   134   135   136   137   138   139   140   141   142