I am learning raspberry pi and somewhere i found the tutorial of turning the bulb on when clap is heard and off the bulb when clapped again. The following code was written for this to work
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
# telling pi we are not using the pin but BCM standard GPIO names for the pins
GPIO.setmode(GPIO.BCM)
BULB_OUTPUT_PIN = 4
SOUND_INPUT_PIN = 17
GPIO.setup(BULB_OUTPUT_PIN, GPIO.OUT)
# why high is given initially?
GPIO.output(BULB_OUTPUT_PIN, GPIO.HIGH)
# for sound sensor
GPIO.setup(SOUND_INPUT_PIN, GPIO.IN)
SleepTime = 6
# main loop
try:
while 1:
print('#######GPIO INPUT PIN##### ', GPIO.input(SOUND_INPUT_PIN))
if GPIO.input(SOUND_INPUT_PIN) == GPIO.LOW:
print("##########Sound is sensed############")
time.sleep(SleepTime)
# GPIO.LOW is used to switch on
GPIO.output(BULB_OUTPUT_PIN, GPIO.LOW)
print("#Relay is triggered in the switch 1########")
time.sleep(SleepTime)
GPIO.cleanup()
print("Good bye!")
# End program cleanly with keyboard
except KeyboardInterrupt:
print("Quit")
# Reset GPIO settings
GPIO.cleanup()
In the code above you can see, GPIO.HIGH is used initially and I dont know why it is done at the very start because in my understanding HIGH means to turn on/switch on but here the thing is opposite. Why is that so? Can anyone explain the use of GPIO.HIGH and GPIO.LOW considering the above example, please?