Etiket arşivi: raspberry pi blink led

Raspberry Pi 3 Model B Turn on and off Led

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).

rpi

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:

  • https://www.coolcomponents.co.uk/raspberry-pi-3-model-b.html
  • http://www.rs-online.com/designspark/electronics/eng/blog/introducing-the-raspberry-pi-b-plus
  • https://www.raspberrypi.org/documentation/usage/gpio/