Tags

, , , , ,

Back to the very basic – lighting up a LED and blink it! Well this is just to test the GPIO control. I should have done this before trying out on Servo motor. :p

But anyway, here is the circuit diagram.

LED connection to RPi GPIO

LED connection to RPi GPIO

I actually connected it to pin 11 (GPIO 17) instead of pin 7 shown in the diagram above. I used 330 Ohms resistor and connected it to Gnd at pin 6.
Reference: Resistor Color Code

Resistor color code

I wrote a simple Python program to make the LED blink. Alternatively, you can test out your circuit by connecting the signal wire to pin 1 (3.3V). If it lights up, then it’s good.

Remember to install RPI.GPIO first.

See below for the simple code for blinking the LED:


import RPi.GPIO as GPIO #Import GPIO library
import time #Import 'time' library so that we can use 'sleep()'

# Use physical board pin numbers
GPIO.setmode(GPIO.BOARD)
# Set up header pin 11 (GPIO17) as an output
print "Setup Pin 11"
GPIO.setup(11, GPIO.OUT)

var=1
print "Start loop"
while var==1 :  #run loop forever until CTRL C is pressed
    print "Set Output False" 
    GPIO.output(11, False) #switch off
    time.sleep(1)  #wait
    print "Set Output True"
    GPIO.output(11, True) #switch on
    time.sleep(1)

Here is the video for demonstration:

Next up, integrate this with a switch from web app.

Advertisements