Connect led to Raspberry Pi as shown below (I used GPIO 20 port, also you can use another GPIO port but, you must point out this port in the python file).
Then open a text document, named it led_status.py. Then write the codes below in it.
import RPi.GPIO as GPIO def set_led(status): GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) led = 20 GPIO.setup(led, GPIO.OUT) GPIO.output(led, status)
Run the script by the command below;
to turn on the led python -c ‘import led_status; led_status.set_led(1)’
to turn off the led python -c ‘import led_status; led_status.set_led(0)’
Sources for pictures: