1

When I run this python script led.py it works.

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(24,GPIO.OUT)
print("LED on")
GPIO.output(24,GPIO.HIGH)
time.sleep(1)
print("LED off")
GPIO.output(24,GPIO.LOW)

but if I open python3 shell and paste the above code

script# python3
Python 3.7.3 (default, Jan 22 2021, 20:04:44) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
>>> import time
>>> GPIO.setmode(GPIO.BCM)
>>> GPIO.setwarnings(False)
>>> GPIO.setup(24,GPIO.OUT)
>>> print("LED on")
LED on

then it does not work. what is happening here

1 Answer 1

1

You are not setting the GPIO level.

The LED will go on when you execute

GPIO.output(24,GPIO.HIGH)

The LED will go off when you execute

GPIO.output(24,GPIO.LOW)
1
  • daaah how did I missed it Commented Sep 17, 2022 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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