LEDS
First, let’s find out what a led is.
LEDs, also known as Light Emitting Diodes, are electronic components that convert electricity into light. LEDs have several advantages, including long lifespan, low energy consumption, and fast switching speeds. They also come in a variety of colors and sizes and can be used in many different applications such as car interiors, home lighting, computer screens, mobile phones, televisions, and many more devices.
A diode, also called a semiconductor diode, is a two-terminal electronic component that allows current to flow primarily in one direction (asymmetric conductance). An LED is a type of diode, so it also has a “+” and “-” terminals and it needs to be connected correctly. If it is connected incorrectly it won’t light up. Therefore, you should check that the LEDs are properly connected in the circuits we will be making. (The terminals of an LED are often referred to as the anode and cathode, And usually the long pin is “+” and the short pin is “-“)
In the image below, you can see how the terminals of an LED are.
Let’s begin,
LED PROJECT-1: Led Blink
First, we will make a simple LED lighting application, the materials required for this are;
- Arduino Uno
- Breadboard
- LED
- Resistor / 220 Ohm
- Some cables
One more brief information…
In an electrical circuit, a resistor is a passive component that resists the flow of electric current. Its purpose is to reduce the current flowing in a circuit and to regulate the voltage level. The resistance value is measured in ohms (Ω) and it’s represented by the Greek letter omega.
In the example we use a 220 ohm resistor to protect the arduino pin because, if the LED draws too much current it can damage the arduino pin.
Follow these steps sequentially:
1- Connect the cathode (-) pin of the LED to the GND pin of the Arduino
2- Connect one end of the resistor to the anode (+) pin of the LED
3- Connect the other end of the resistor to pin 5 of the Arduino
The circuit connection should look like this.
After carefully setting up our circuit, it’s time to create our program. In this program, an LED by turning it on for 1 second and turning it off for 1 second. Before writing the program, it’s important to break down what we want to do into smaller parts and think about it, otherwise, we will get lost in complex programs. Since we are going to start with a simple program, our job will be relatively easy. We want to blink an LED by turning it on for 1 second and turning it off for 1 second. We want to do this continuously, so we need to create a loop. This loop will repeatedly execute the actions inside it. Now, let’s decide what the actions inside this loop will be:
Turn on the LED
Wait for 1 second
Turn off the LED
Wait for 1 second
Go back and repeat.
As you can see, we have described the program in words. It will be easier to do it now. Now, let’s create the algorithm we have defined with blocks. We must add a start condition to the beginning of the program.
Right after, we need to add the loop command.
Now let’s add what the commands in this loop will be.
First of all, we need to make the pin that our led is connected to “high”. so we will give 5V DC to the led from this pin and the led will work.
then wait 1 second.
Now let’s make the pin “low” and turn off the led.
then wait 1 second.
That’s it, the final version of our program will be as follows.
Now let’s upload the program to the Arduino
1-Press Connect
2- First we check “show all connectable devices” and then we press connect.
3- Now we are uploading the program.
4- That’s it.
LED PROJECT-2: Control Of LED With Button:
Button: Buttons are devices that control the flow of electric current by opening and closing the circuit. When you press the button, the mechanism inside short-circuits the two sides of the contacts, allowing the current to flow. When you don’t press the button, the spring mechanism inside returns to its previous position.
In the previous project, we defined the Arduino pins as digital outputs, but in this project, we need to use the pins that we connect the buttons to as digital inputs because we will be making an input signal from here.
When setting up our circuit, we need to position our button correctly on the breadboard, because the button’s pins should not be shorted, otherwise, the button will have no function.
In order to prevent this, we need to place the button in the center of the breadboard.
We connect one pin of the button to the 5V pin of the Arduino, the other leg of the button is connected to the GND pin of the
Arduino via a 10K ohm resistor, and again this pin of the button is connected to the 12th pin of the Arduino.
(Note: The resistor prevents the input pin from receiving direct 5V, which can cause the input to work non-stability, hence a load is attached for more stable operation. This is an issue related to electronics and for more information, it is recommended to research the Ohm’s law.) Just as we learned in the previous project, we connect the LED with the help of a resistor to the 5th pin of the Arduino.
Now let’s control the LED with the button using the code we write.
we used the if-else command structure which we hadn’t used before.
The “if-else” structure allows you to perform different operations based on the result of a condition.
After the if, the condition is written and if the condition is true (digital 1), the code in the if block will run, if it’s false (digital 0), the code in the else block will run.
LED PROJECT-3: RGB Led
RGB LED stands for Red, Green, and Blue Light Emitting Diode. It is a type of LED that has the ability to change colors. The RGB refers to the red, green, and blue colors, and by mixing these colors, a wide range of colors can be obtained. RGB LEDs are often used with control circuits, which allows the user to change colors and create effects. RGB LEDs are commonly used in lighting, visual effects, and other applications.
RGB Led has 4 pin connection, they are common anode or cathode-Red-Green-Bue.
Actually, an RGB LED is not much different from the LEDs we used in the previous project. It contains only 3 different colored 3 LEDs, and these LEDs are operated using a common anode/cathode connection. You will understand it better in the following image.
Common Anode:
Common Cathode:
Let’s play with light using an RGB LED. With the help of the block you see below, you can run the RGB lights in sequence and create a fun environment.
Circuit Diagram: