Page 115 - TCS ICT Book 8
P. 115

The City School  2021-2022




             Hardware of this project is made simpler for your handling and does not require any

             soldering or messy wiring. We will use the Pi Shield on the top of the GPIO pins of Pi as
             a stack and connect the SONAR sensor on the Pi shield. But this time we will power the

             Pi via power adapter or battery outlet available on the Pi Shield.

             Equipment needed

             Following componentes are required for this project:

             •  Sonar Sensor
             •  Pi Shield                                              Python is one of the official

             •  Raspberry Pi                                           programming languages at Google
                                                                       and YouTube is one of Google’s
             •  Power Adapter / Battery                                products that are powered by                 Programming Robots & Single-Board Computers
                                                                       Python.
             •  Keyboard, Mouse & LCD


             Hardware of this project is made simpler for your handling and does not require any

             soldering or messy wiring. We will use the Pi Shield on the top of the GPIO pins of Pi as
             a stack and connect the SONAR sensor on the Pi shield. But this time we will power the

             Pi via power adapter or battery outlet available on the Pi Shield.
             Interfacing code:

             import RPi.GPIO as gpio

             import time as t
             gpio.setmode(gpio.BCM)

             gpio.setwarnings(false)
             trigger=17

             echo=27
             gpio.setup(trigger, gpio.OUT)

             gpio.setup(echo, gpio.IN)
             def distance():

               gpio.output(trigger,True)
               t.sleep(0.0001)

               gpio.output(trigger,False)
               while gpio.input(Echo) == 0:

                  StartTime=t.time()
               while gpio.input(Echo) == 0:

                  StopTime=t.time()









                                                                                                                115
   110   111   112   113   114   115   116   117   118   119   120