import time import RPi.GPIO as IO #calling for header file which helps in using GPIOs of PI string_of_characters = 0 IO.setwarnings(False) #do not show any warnings IO.setmode (IO.BCM) #programming the GPIO by BCM pin numbers. (like PIN29 as GPIO5) IO.setup(17,IO.OUT) #initialize GPIO17,27,24,23,18,26,5,6,13,19,21 as an output IO.setup(27,IO.OUT) IO.setup(24,IO.OUT) IO.setup(23,IO.OUT) IO.setup(18,IO.OUT) IO.setup(26,IO.OUT) IO.setup(5,IO.OUT) IO.setup(6,IO.OUT) IO.setup(13,IO.OUT) IO.setup(19,IO.OUT) IO.setup(21,IO.OUT) IO.setup(16,IO.IN) #initialize GPIO16 as an input def send_a_command (command): #steps for sending a command to 16x2 LCD pin=command PORT(pin); IO.output(17,0) #PORTD&= ~(1<400): #If distance is more than 400cm, just print 400+ on LCD send_a_command(0x80 + 0); send_a_string ("Dist= 400+ cm"); time.sleep(0.15)