make it simple..

2016@abutech. Powered by Blogger.

Pages

Wednesday 2 November 2016

contolling LED bulb using raspberry pi 3


First experiment using led:

Hardware Requirements

             LED bulb
             1k ohm resistor
             2x female to male jumper wire
             breadboard
    anode(big leg) of the LED is connected  through resistor 
    in gpio pin 17 and cathode(small leg) of the led is connected 
    to ground(GND) of the gpio pin

    python program for control the led: 

     python has new gpiozero library to control the gpio pins according to the speific python programming paradigm. The following python program can be control the led bulb.                                                                                                                        
    from gpiozero import LED
    from time import sleep
    led=LED(17)
    while 1:
         led.on()
         sleep(1)
         led.off()
         sleep()


    in the above program LED module is imported from gpiozero library then sleep module is imported from time library for the purpose of led blink. led=LED(17) this specifies the led bulb connected to the gpio 17,  while 1: this line tells the condition is always true and running the program until the user terminate it.
       led.on() in this line on() function send the output signal to the          gpio 17 pin as on and then sleep(1) this fucntion tells wait for            one second and then off() fucntion send the output signal to the        gpio 17 pin as off, So that the led is blinking.

0 comments:

Post a Comment