• Connection diagram and control of LED strip using Arduino. Connecting and controlling LED strip to arduino

    Arduino is ideal for controlling any devices. The ATmega microprocessor uses a sketch program to manipulate a large number discrete outputs, analog-digital inputs/outputs and PWM controllers.

    Due to the flexibility of the code, the ATmega microcontroller is widely used in various automation modules, including on its basis it is possible to create an LED lighting control controller.

    The principle of load control via Arduino

    The Arduino board has two types of output ports: digital and analog (PWM controller). A digital port has two possible states: logical zero and logical one. If you connect an LED to it, it will either glow or not.

    The analog output is a PWM controller, to which a signal with a frequency of about 500 Hz is supplied with an adjustable duty cycle. What a PWM controller is and the principle of its operation can be found on the Internet. Through analog port It is possible not only to turn the load on and off, but also to change the voltage (current) on it.

    Command Syntax

    Digital output:

    pinMode(12, OUTPUT);— set port 12 to be the data output port;
    digitalWrite(12, HIGH);— we apply a logical one to discrete output 12, lighting the LED.

    Analog output:

    analogOutPin = 3;– set port 3 to output an analog value;
    analogWrite(3, value);– we generate a signal at the output with a voltage from 0 to 5V. The value is the duty cycle of the signal from 0 to 255. At a value of 255, the maximum voltage.

    Ways to control LEDs via Arduino

    Only a weak LED can be connected directly through the port, and even then it is better through a limiting resistor. Trying to connect a more powerful load will damage it.

    For more powerful loads, including LED strips, an electronic switch – a transistor – is used.

    Types of transistor switches

    • Bipolar;
    • Field;
    • Composite (Darlington assembly).
    Load connection methods
    Via bipolar transistor Via field effect transistor Via voltage switch

    When a high logic level is applied (digitalWrite(12, HIGH);) through the output port to the base of the transistor, the reference voltage will flow to the load through the collector-emitter chain. This way you can turn the LED on and off.

    A field-effect transistor works in a similar way, but since instead of a “base” it has a drain, which is controlled not by current, but by voltage, a limiting resistor in this circuit is not necessary.

    The bipolar view does not allow you to regulate powerful loads. The current through it is limited to 0.1-0.3A.

    Field-effect transistors operate with more powerful loads with currents up to 2A. For even more powerful load use field effect transistors Mosfet with current up to 9A and voltage up to 60V.

    Instead of field ones, you can use a Darlington assembly from bipolar transistors on ULN2003, ULN2803 chips.

    ULN2003 chip and circuit diagram of an electronic voltage switch:

    The principle of operation of a transistor for smooth control of an LED strip

    A transistor works like a water faucet, only for electrons. The higher the voltage applied to the base of the bipolar transistor or the drain of the field effect transistor, the lower the resistance in the emitter-collector circuit, the higher the current passing through the load.

    Having connected the transistor to the Arduino analog port, we assign it a value from 0 to 255, and change the voltage supplied to the collector or drain from 0 to 5V. The collector-emitter circuit will pass from 0 to 100% of the load reference voltage.

    To control an Arduino LED strip, you need to select a transistor of suitable power. The operating current for powering the LED meter is 300-500mA; a power bipolar transistor is suitable for these purposes. For longer lengths, a field effect transistor will be required.

    Scheme LED connections Arduino tapes:

    Controlling RGB strip with Andurino

    In addition to single-chip LEDs, Arduino can also work with color LEDs. By connecting the pins of each color to the analog outputs of the Arduino, you can arbitrarily change the brightness of each crystal, achieving the desired color of the glow.

    Connection diagram to Arduino RGB LED:

    The Arduino RGB strip control is constructed similarly:

    It is better to assemble the Arduino RGB controller using field-effect transistors.

    For smooth control brightness two buttons can be used. One will increase the brightness of the glow, the other will decrease it.

    Arduino LED strip brightness control sketch

    int led = 120; install intermediate level brightness

    void setup() (
    pinMode(4, OUTPUT); set the 4th analog port to output
    pinMode(2, INPUT);

    pinMode(4, INPUT); set the 2nd and 4th digital ports to input for polling buttons
    }
    void loop()

    button1 = digitalRead(2);

    button2 = digitalRead(4);
    if (button1 == HIGH) Pressing the first button will increase the brightness
    {
    led = led + 5;

    analogWrite(4, led);
    }
    if (button2 == HIGH) pressing the second button will decrease the brightness
    {
    led = led - 5;

    analogWrite(4, led);
    }

    When you hold down the first or second button, the voltage supplied to the control contact smoothly changes electronic key. Then there will be a smooth change in brightness.

    Arduino control modules

    To create a full-fledged LED strip control driver, you can use sensor modules.

    IR control

    The module allows you to program up to 20 commands.

    The signal radius is about 8m.

    The price of the set is 6 USD.

    By radio channel

    Four-channel unit with a range of up to 100m

    The price of the set is 8 USD.

    Allows you to turn on the lighting when approaching the apartment.

    Contactless

    The distance sensor is capable of increasing and decreasing the brightness of the lighting by moving your hand.

    Range of action up to 5m.

    Module price 0.3 USD

    In this article we will talk about color LEDs, the difference between a simple RGB LED and an addressable one, and add information about the areas of application, how they work, how control is carried out with schematic pictures of connecting LEDs.

    LEDs – electronic component, capable of emitting light. Today they are widely used in various electronic equipment: flashlights, computers, household appliances, cars, phones, etc. Many microcontroller projects use LEDs in one way or another.

    They have two main purposes:

    Demonstration of equipment operation or notification of any event;
    use for decorative purposes (lighting and visualization).

    Inside, the LED consists of red (red), green (green) and blue (blue) crystals assembled in one housing. Hence the name – RGB (Fig. 1).

    2. Using microcontrollers

    With it you can get many different shades of light. The RGB LED is controlled using a microcontroller (MK), for example, Arduino (Fig. 2).

    Of course you can get by a simple block 5 volt power supply, 100-200 Ohm resistors to limit the current and three switches, but then you will have to control the glow and color manually. In this case, it will not be possible to achieve the desired shade of light (Fig. 3-4).

    The problem arises when you need to connect hundreds of colored LEDs to the microcontroller. The number of pins on the controller is limited, and each LED needs power from four pins, three of which are responsible for color, and the fourth pin is common: depending on the type of LED, it can be an anode or cathode.

    3. Controller for RGB control

    To unload the MK terminals, special controllers WS2801 (5 volts) or WS2812B (12 volts) are used (Fig. 5).

    With the use of a separate controller, there is no need to occupy several MK outputs; you can limit yourself to only one signal output. The MK sends a signal to the “Data” input of the WS2801 LED control controller.

    This signal contains 24-bit information about color brightness (3 channels of 8 bits for each color), as well as information for the internal shift register. It is the shift register that allows you to determine which LED the information is addressed to. In this way, you can connect several LEDs in series, while still using one pin of the microcontroller (Fig. 6).

    4. Addressable LED

    This is an RGB LED, only with an integrated WS2801 controller directly on the chip. The LED housing is made in the form of an SMD component for surface mounting. This approach allows you to place the LEDs as close to each other as possible, making the glow more detailed (Fig. 7).

    In online stores you can find addressable LED strips, where up to 144 pieces fit in one meter (Fig. 8).

    It is worth considering that one LED consumes only 60-70 mA at full brightness; when connecting a strip, for example, with 90 LEDs, you will need powerful block power supply with a current of at least 5 amperes. Under no circumstances power the LED strip through the controller, otherwise it will overheat and burn out from the load. Use external sources nutrition (Fig. 9).

    5. Lack of addressable LEDs

    Addressable led strip cannot work at too low temperatures: at -15 the controller begins to malfunction, in severe frost there is a high risk of its failure.

    The second drawback is that if one LED fails, all the others along the chain will also refuse to work: the internal shift register will not be able to transmit information further.

    6. Application of addressable LED strips

    Addressable LED strips can be used for decorative lighting of cars, aquariums, photo frames and paintings, in room design, as New Year's decorations, etc.

    An interesting solution is obtained if an LED strip is used as an Ambilight backlight for a computer monitor (Fig. 10-11).

    If you will be using microcontrollers on Arduino based, you will need the FastLed library to simplify working with LED strip ().

    LED RGB strip is a flexible strip with conductors and RGB LEDs (full color) printed on it. IN lately LED strips are widely used in architecture, auto and motorcycle tuning, costumes, decorations, etc. There are also waterproof tapes that can be used, for example, in swimming pools.

    LED strips come in two types: analog and digital.
    In analog strips, all LEDs are connected in parallel. Therefore, you can set the color of the entire LED strip, but you cannot set specific color for a specific LED. These tapes are easy to connect and not expensive.
    Digital LED strips are a little more complicated. An additional microcircuit is installed for each LED, which makes it possible to control any LED. Such tapes are much more expensive than regular ones.

    In this article we will consider working only with analog LED strips.

    Analog RGB LED strips

    Data sheet:
    - 10.5mm width, 3mm thickness, 100mm length of one segment
    - waterproof
    - 3M tape on the bottom
    - max. current consumption (12V, white) - 60mA per segment
    - glow color (wavelength, nm): 630nm/530nm/475nm

    RGB LED strip circuit diagram

    The tape is supplied in rolls and consists of sections 10 cm long. Each section contains 3 RGB LEDs, size 5050. Each section turns out to contain 9 LEDs: 3 red, 3 green and 3 blue. Section boundaries are marked and contain copper pads. Therefore, if necessary, the tape can be cut and easily soldered. LED strip diagram:

    Energy consumption

    In each section of the tape, 3 LEDs are connected in series, so 5V power is not suitable. The power supply should be 12V, but you can also supply 9V, but then the LEDs will not burn so brightly.

    One segment LED line consumes approximately 20mA when supplied at 12V. That. if you turn on the white color (i.e. red 100%, green 100% and blue 100%), then the power consumption of the section will be about 60mA.

    Now, you can easily calculate the current consumption of the entire tape. So, the length of the tape is 1 meter. The tape has 10 sections (10 cm each). The tape consumption with white color will be 60mA*10=600mA or 0.6A. If you use a PWM fade effect between colors, the power consumption can be halved.

    Connecting the tape

    In order to connect the tape, you need to solder the wires to the 4 contact pads. We used a white wire for +12V, and the rest of the colors according to the colors of the LEDs.

    Cut off protective film at the end of the tape. From which side the connection will be made is not important, because... symmetrical tape.

    Strip the insulation layer to expose the contact pads.

    Tin them.

    Solder four wires. It is better to use multi-core wire (for example PV3 or PVS cable), it is more flexible.

    To protect against water and external influences, you can use heat-shrink tubing. If the LED strip will be used in a humid environment, then additionally, the contacts can be coated with silicone.

    Working with LED strip

    The tape can easily be used with any microcontroller. To control LEDs, it is recommended to use pulse width modulation (PWM). Do not connect the tape pins directly to the MK pins, because This is a large current load and the controller may burn out. It's better to use transistors.

    You can use NPN transistors or better yet N-channel mosfets. When selecting a transistor, do not forget that the maximum switching current of the transistor must be taken with a reserve.

    Connecting LED strip to Arduino controller

    Let's look at an example of connecting an LED strip to a popular one. To connect, you can use inexpensive and popular mosfets. You can also use conventional bipolar transistors, for example TIP120. But compared to mosfet, it has more voltage loss, so it is still recommended to use the former.
    The diagram below shows RGB connection LED strip when using N-channel mosfets. The mosfet gate is connected to pin1 of the controller, the drain to pin2 and the source to pin3.

    Below is a connection diagram when using conventional bipolar transistors (for example TIP120). The base of the transistor is connected to pin1 of the controller, the collector to pin2 and the emitter to pin3. A resistor with a resistance of 100-220 Ohms must be placed between the base and the controller output.

    TO Arduino controller connect a power source with a voltage of 9-12 Volts, and +12V from the LED strip must be connected to the Vin pin of the controller. You can use 2 separate power supplies, just do not forget to connect the grounds of the source and the controller.

    Example program

    To control the tape, the PWM output of the controller will be used, for this you can use the analogWrite() function for pins 3, 5, 6, 9, 10 or 11. With analogWrite(pin, 0) the LED will not light up, with analogWrite(pin, 127 ) the LED will burn at full intensity, and with analogWrite(pin, 255) the LED will burn at maximum brightness. Below is an example sketch for Arduino:

    #define REDPIN 5 #define GREENPIN 6 #define BLUEPIN 3 #define FADESPEED 5 // the higher the number, the slower the fade effect will be void setup() ( pinMode(REDPIN, OUTPUT); pinMode(GREENPIN, OUTPUT); pinMode(BLUEPIN , OUTPUT); ) void loop() ( int r, g, b; // fade from blue to purple for (r = 0; r 0; b--) ( analogWrite(BLUEPIN, b); delay(FADESPEED); ) // fade from red to yellow for (g = 0; g 0; r--) ( analogWrite(REDPIN, r); delay(FADESPEED); ) // fade from green to teal for (b = 0; b 0; g--) ( analogWrite(GREENPIN, g); delay(FADESPEED); ) )

    This one is simple Arduino project designed for control using PWM (pulse width modulation). It can change the level of each color independently by changing the PWM duty cycle. This way you can create any color by mixing different colors in percentages. Rotating the encoder on the board allows the user to select desired channel and change its brightness. Transistors with low switching resistance create very low heat generation even when using large quantities LEDs. For example, the IRF540 transistor has a very low RDS pass-through resistance - about 70 mOhm.

    Tape controller circuit

    RGB LED is a very common type of LED strip that includes red, green and blue led chip in one building. Although they are housed in the same package, each die can be controlled independently. Thanks to this feature, we can get a huge number of different colors using RGB LEDs and of course the resulting color can be dynamically changed using a slider.

    The main controller is made using Arduino Uno. It reads the input data from the encoder and according to this information, the transistors are switched. The transistors are controlled by pins 9, 10 and 11, which have internal PWM functions. The direction of the encoder signals A and B are read using elements 2 and 3, which are connected to the module. The encoder button is used to select the channel and is connected to pin 1, which is set as the input data.

    Last time we looked at how to connect an LED strip to an Arduino via the L298 driver. Color management was carried out programmatically - the Random function. Now it’s time to figure out how to control the color of the LED strip based on the readings of the DHT 11 temperature and humidity sensor.

    The example is based on connecting an LED strip via the L298 driver. On top of that, an LCD 1602 display has been added to the example, which will display the readings of the DHT 11 sensor.

    The project will require the following Arduino elements:

    1. Arduino UNO board.
    2. Display LCD 1602 + I2C.
    3. Temperature and Humidity Sensor DHT
    4. LED strip.
    5. Driver L298.
    6. Power supply 9-12V.
    7. Housing for Arduino and display (optional).

    First of all, let's look at the circuit diagram (Fig. 1). On it you can see how to connect all of the above elements. There is nothing complicated in assembling the circuit and connecting it, but it is worth mentioning one nuance that most people forget about and end up getting incorrect results LED work– tapes from Arduino.

    Figure 1. Schematic diagram Arduino connections and LED strip with DHT 11 sensor

    To avoid correct operation LED strip (flickering, color mismatch, incomplete glow, etc.), the power supply of the entire circuit must be made common, i.e. combine the GND (ground) pins of the Arduino controller and the L298 driver (LED strip). You can see how to do this in the diagram.

    A few words about connecting a humidity sensor. If you buy a bare DHT 11, without strapping, then between the first and second contacts, 5V and Data, respectively, you need to solder a resistor with a nominal value of 5-10 kOhm. The temperature and humidity measurement range is written on back side DHT 11 sensor housing. Temperature: 0-50 degrees Celsius. Humidity: 0-80%.


    Figure 2. Correct connection humidity sensor DHT 11

    After assembling all project elements according to the diagram, you need to write program code, which will make it all work the way we need it. And we need the LED strip to change color depending on the readings of the DHT 11 sensor (humidity).

    To program the DHT 11 sensor, you will need an additional library.

    Arduino and RGB program code - strip. Changes the color of the tape depending on humidity.

    #include #include //library for working with LCD display 1602 #include //library for working with the humidity and temperature sensor DHT 11 int chk; //the variable will store all data from the DHT11 sensor int hum; //the variable will store humidity readings from the DHT11 sensor dht11 DHT; //object of type DHT #define DHT11_PIN 4 //Data pin of the DHT11 sensor is connected to input 4 #define LED_R 9 //pin for channel R #define LED_G 10 //pin for channel G #define LED_B 11 //pin for channel B / /variables will store color values ​​//when mixing all three colors the required color will be obtained int led_r=0, led_g=0, led_b=0; //declaring a display object with address 0x27 //don’t forget to use a display in the project via an I2C board LiquidCrystal_I2C lcd(0x27,16,2); void setup() ( //create a display lcd.init(); lcd.backlight(); // declare pins as outputs pinMode(LED_R, OUTPUT); pinMode(LED_G, OUTPUT); pinMode(LED_B, OUTPUT); ) void loop () ( chk = DHT.read(DHT11_PIN);//read data from the DHT11 sensor //output data to the display lcd.print("Temp: "); lcd.print(DHT.temperature, 1); lcd.print( " C"); lcd.setCursor(0,1); lcd.print("Hum: "); lcd.print(DHT.humidity, 1); /for correct operation of the sensor, a delay is required for polling lcd.clear(); hum = DHT.humidity; //take humidity readings //in the range from 19 to 30% humidity green if ((hum >= 19) && (hum<= 30)) { led_r = 1; led_g = 255; led_b = 1; } //в диапозоне от 31 до 40% влажности выдать красный цвет if ((hum >= 31) && (hum<= 40)) { led_r = 255; led_g = 1; led_b = 1; } //в диапозоне от 41 до 49% влажности выдать синий цвет if ((hum >= 41) && (hum<= 49)) { led_r = 1; led_g = 1; led_b = 255; } // подача сигналов цвета на выхода analogWrite(LED_R, led_r); analogWrite(LED_G, led_g); analogWrite(LED_B, led_b); }

    Tags: Tags