In this 1st project, you’ll be Blinking a light-emitting diode(LED) to your Raspberry Pi and create it blink with an easy python Code. And Learning how to blink light-emitting diode(LED) using the GPIO pins is an And also you recognize the way to control a light-emitting diode(LED).
≡ Parts Required
- Raspberry Pi
- 5 mm LED
- 330 Ω resistor
- Jumper wires
≡Circuit Diagram Blinking LED Raspberry Pi
Now you’re able to build your LED circuit. To wire an LED to the RaspberryPi, follow these next steps. Use the wiring diagram in Figure 1.
- Connect a blue breadboard rail to one of the Raspberry Pi GND pins (pins 6, 9, 14, 20, 25, 30, 34, and 39 all provide GND).
- Insert the LED into the breadboard.
- Insert the 330 Ω resistor into the breadboard so that one side is connected to the LED anode (the longer, positive lead).
- Connect the other side of the resistor to GPIO 25 (pin 22) with a jumper wire.
- Connect the LED cathode (the shorter, negative lead) to the GND power rail.
We’ve provided you instructions on where to place the resistor, but actually, it doesn’t matter whether it’s joined to the anode or cathode as long as it is attached to one. we didn’t just join the LED cathode directly to pin 6 (GND) since we only require the GND rail for that one connection. The reason is that its good work to use the breadboard GND rails, which will grow more useful in more advanced circuits.
≡ Code Blinking LED Raspberry Pi
To keep all your projects organized, create a folder called PiProjects in your RaspberryPI desktop environment to save all your projects’ Code.create a new folder called LEDs where you’ll save the RaspberryPI LED projects.
In simple conditions, the blinking LED project works as follows:
- The LED turns on for 1 second—GPIO 25 set to HIGH.
- The LED turns off for 1 second—GPIO 25 set to LOW.
- The LED is on again for 1 second—GPIO 25 set to HIGH.
- The LED is off again for 1 second—GPIO 25 set to LOW.
This program continues until you tell the program to stop.
we’ll control the RaspberryPi GPIOs using a Python library called gpiozero. The gpiozero library gives a collection of interfaces for everyday components like LEDs, buttons, potentiometers, sensors, and much more.
Open RaspberryPi Python 3 (IDLE) and go to File ▸ New File to create a new file. Now Copy this code to the Python Editor and save this as blinking_led.py inside the LEDs folder.
from gpiozero import LED from time import sleep led = LED(25) delay = 1 while True: led.on() print("LED set to on") sleep(delay) led.off() print("LED set to off") sleep(delay)
≡ Code Analysis Blinking LED Raspberry Pi
from gpiozero import LED from time import sleep
At you import LED from the gpiozero library for control the GPIO that the LED is connected to. and import the sleep() function from the time module.
led = LED(25)
Declaring the Pin
Now you create an LED object named led that refers to GPIO 25, which is the GPIO the LED is attached to. If you create and apply this LED object Python code knows GPIO 25 is output and thus should be set to HIGH or LOW. After this code, you can use led to refer to your GPIO 25.
Starting the while Loop
At you start a while loop with the state True, which means this loop will run forever until you stop the program yourself. The lines of code that follow the loop code are indented, telling Python that this is the content of the loop to be run as long as the while condition is met.
led.on() print("LED set to on") sleep(delay) led.off() print("LED set to off") sleep(delay)
Setting the Digital Output
Now you require to set the digital output for the LED. You utilize the led.on() function to set GPIO 25 to HIGH, turning the LED on, and the led.off() function to set GPIO 25 to LOW, turning the LED off. There is a pause of 1 second within each LED state using the sleep() function, which creates the blinking effect. The code stops where it is and waits for the amount of time specified in the delay variable before proceeding to the next line of code. This allows you to keep the LED on or off for a given period of time.
≡ Hardware Analysis Blinking LED Raspberry Pi
Overview of GPIO Pins
The General Purpose Input/Output (GPIO) pins provide you to connect electronic hardware, like LEDs and sensors, to your RspberryPi. They can be utilized to both read and send information, allowing your RaspberryPi to interact with the real world.
The Raspberry Pi 3 Model B board has a double row of 40 GPIO pins, shown. Here this layout is the same for the Pi 2 Model B and Pi 1 Model B+, but lightly different from the Pi 1 Model A and B, which have only the first 26 pins.
There are two methods to refer to a GPIO pin: its name or by its identical pin number (. For example, GPIO 25 corresponds to pin 22. GPIO pins can be set to HIGH, which outputs 3.3 V and turns a part on, or LOW, which outputs 0 V and turns the part off.
I2C ID EEPROM
I2C ID EEPROM
Overview of LEDs
The LEDs come in a wide variety of sizes, shapes, and colors, and some can even mix colors to create almost any color. In this project, you’ll use a simple 5 mm red LED.
Diodes are electronic components that have polarity, meaning they allow current to flow in only one direction, from positive to negative. LEDs, like all diodes, have a positive connection known as an anode, and a negative connection known as a cathode. The two legs, or leads, on LEDs, are of different lengths to help you identify which is positive and which is negative, The longer lead is the anode (+) and the shorter lead is the cathode (–).
How to Finding The Right Resistor
LEDs can work only so much current before they overload and burn out, which can possibly damage the LED and even the Raspberry Pi board. To prevent this, you must always connect LEDs in series with a resistor: a small component that limits the amount of current passing through it.
The Resistors get in all sorts of values, and you need one that’s strong sufficient to protect your component without being so strong that it limits the element capabilities. For example, a stronger resistor can dull the light an LED provides off. The appropriate resistance value depends on the LED you’re using—most LEDs you’ll use in electronics can handle a maximum current rating of 20 mA. For the LED in this project, picking up a resistor of any value between 220 Ω and 470 Ω is fine, and within this range, a lower resistance value will result in a slightly brighter LED.
The resistance value is shown by the color bands on the resistor. Resistors usually have four bands. The first two represent the first two digits of the value. The third is a multiplier representing the number of zeros after the first two digits. The fourth is the tolerance of the resistance, which notes the rate that the actual resistance might be above or under the given value. For example, a 330 Ω resistor with a 5 percent tolerance might be any value between 313.5 Ω and 346.5 Ω.
203 total views, 1 views today