I have a class RelayChannel and I want to call the function RelayChannelOn() to this code but I get error : NameError: name 'RelayChannelOn' is not defined.

Here is the code where am calling the function.

  import RPi.GPIO as GPIO

    import time
    import RelayChannel



    GPIO.setup(21, GPIO.IN) #PIR

    GPIO.setup(RelayChannelOn(13), GPIO.OUT) #BUzzer


        time.sleep(2) # to stabilize sensor

        while True:

            if GPIO.input(21):

                GPIO.output(RelayChannel(13), True)

                time.sleep(0.5) #Buzzer turns on for 0.5 sec

                GPIO.output(RelayChannel(13), False)

                print("Motion Detected...")

                time.sleep(5) #to avoid multiple detection

            time.sleep(0.1) #loop delay, should be less than detection delay


  • This appears to be a general Python question. Perhaps search for a Python tutorial? – joan Mar 26 '18 at 22:10

I think you are missing a period in the following line:

GPIO.setup(RelayChannelOn(13), GPIO.OUT) #BUzzer

change it to:

GPIO.setup(RelayChannel.On(13), GPIO.OUT) #BUzzer
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.