RGB strip LED connection to Arduino. RGB LED strip


Arduino- computer platform, used in construction simple systems automation, small fee with built-in microprocessor and RAM. Controlling an LED strip via Arduino is one way to use it.

The ATmega processor controls the sketch program, controlling numerous discrete pins, analog and digital inputs/outputs, and PWM controllers.

Operating principle of Arduino

The “heart” of the Arduino board is a microcontroller to which sensors and control elements are connected. Preset program(called a "sketch") allows you to control electric motors, LED strips and other lighting fixtures, even used to control another Arduino board via the SPI protocol. Control is carried out using a remote control, Bluetooth module or Wi-Fi network.

Open source is used for programming source on PC. You can use the USB connector to download control programs.

The principle of load control via Arduino

There are two types of ports on the Arduino board - digital and analog. The first has two states - “0” and “1” (logical zero and one). When an LED is connected to the board, it will light up in one state and not in another.

The analog input is essentially a PWM controller that registers signals with a frequency of about 500 Hz. Such signals are supplied to the controller with an adjustable duty cycle. The analog input allows you not only to turn on or off the controlled element, but also to change the current (voltage) value.

At direct connection use weak LEDs through the port, adding a limiting resistor to them. A more powerful load will damage it. To organize control of LED strip and other lighting devices, use electronic key(transistor).

Connecting to Arduino

Direct connection of the LED strip to Arduino is only appropriate when using weak LED diodes. For an LED strip, additional electrical elements must be installed between it and the board.

Via relay

Connect the relay to the Arduino board via digital output. The controlled strip can have one of two states - on or off. If you need to organize control of an RGB strip, you will need three relays.

The current controlled by this device is limited by the power of the coil. If the power is too low, the element will not be able to close large contacts. For the highest powers, use relay assemblies.

Using a bipolar transistor

If you need to increase the current or voltage at the output, connect a bipolar transistor. When choosing it, focus on the load current. The control current does not exceed 20 mA, so add a 1 - 10 kOhm resistor to limit the current through resistance.

Note! Ideally you should use n-p-n transistor type based common emitter. If high gain is required, use a transistor assembly.

Using a field effect transistor

Instead of bipolar transistors, use field-effect transistors (abbreviated as MOS) to control LED strips. The difference between them is related to the control principle: bipolar ones change the current, field ones change the voltage at the gate. Thanks to this, a small gate current drives a large load (tens of amperes).

Be sure to add a current limiting resistor to the circuit. Because of high sensitivity To prevent interference, a 10 kOhm resistor mass is connected to the controller output.

Using expansion cards

If you don’t want to use relays and transistors, you can buy entire blocks - expansion boards. These include Wi-Fi, Bluetooth, equalizer, driver, etc., which are required to control loads of different powers and voltages. These can be either single-channel elements, which are suitable for monochrome tapes, or multi-channel (for controlling RGB color tapes).

Various programs

Libraries with programs for the Arduino board can be downloaded from the official website or found on the Internet on other information resources. If you have the skills, you can even write a sketch program (source code) yourself. To collect electrical circuit no specific knowledge is required.

Application options for a system running Arduino:

  1. Lighting. The presence of a sensor will allow you to set a program according to which the light in the room either appears immediately or gradually turns on parallel to sunset (with increasing brightness). To enable, you can use Wi-Fi, telephone and integration into the Smart Home system.
  2. Lighting of the corridor and staircases. Arduino will allow you to organize the lighting of each part (for example, a step) separately. Add a motion sensor to the board so that the addressable LEDs light up sequentially depending on the location where the movement of the object is detected. If there is no movement, the diodes will go out.
  3. Light music. Use filters and feed to analog input sound signals to organize light music (equalizer) at the output.
  4. Computer modernization. Some sensors will allow you to create a dependence of the color of the LEDs on the temperature of the processor, its load, load on RAM. The DMX 512 protocol is used.

Arduino chips expand the possibilities of using monochrome and multi-channel (RGB) LED strips. In addition to the merging of different colors, the formation of hundreds of thousands of shades, you can create unique effects - fading when the sun sets, periodic on/off when motion is detected, and much more.

This project is about how to make LED backlight, controlled from the next room, so as not to get up from the sofa. LED RGB lighting decorates both a small aquarium and a large room equally well.

Can be exposed different colors bath from RGB tape on Arduino. Create, so to speak, a microprocessor-controlled sauna from Arduino.

You just need the following components to assemble the RGB backlight:

  1. Bluetooth module HC-05 for wireless communication with Arduino.
  2. Arduino nano, mini, Uno board with microprocessor ATmega 8, ATmega 168, ATmega 328.
  3. RGB LED strip, if necessary, with or without IP65 waterproof design.
  4. An Android smartphone as a remote control for RGB lighting.
  5. MOSFET field effect transistors, such as P3055LD, P3055LDG, PHD3355L, but better with leads for mounting in mounting holes. Bipolar transistors work worse .
  6. Resistors 10 kOhm, 0.125 W - 3 pieces.

A little theory about RGB connection tapes toArduino

You cannot connect the LED strip directly to the Arduino board. The LED strip glows from 12 V, while the microprocessor needs only 5 V to operate.

But the most the main problem The problem is that the microprocessor outputs do not have enough power to power an entire strip of LEDs. An average meter-long LED strip consumes 600 mA. This current will definitely damage the Arduino board.

The PWM outputs of the microprocessor used do not have enough power to illuminate the RGB strip, but they can still be used to remove the control signal.

For power supply decoupling, it is recommended to use transistors as switches. It is better to use MOSFET field-effect transistors: they require a meager gate current to open, and they also have more power compared to bipolar switches of the same size.

RGBtapes toArduino

On wiring diagram PWM outputs are used to control the tape: 9 (red), 10 (green), 11 (blue).

Three resistors of 10 kOhm, 0.125 W are hung on the “gate” of each transistor.

The plus from the 12 V power supply (red wire) goes directly to the RGB strip.

The negative from the 12 V power supply (black wire) is distributed over the “sources” of the field-effect transistors.

The "drain" of each transistor is connected to separate contact tapes: R, G, B. For ease of connection, it is recommended to use red, green, blue wires.

The GND ground pin of the Arduino board should be connected to the minus of the input power.

The Arduino Uno board itself is powered from a separate network adapter. For Arduino nano, mini, you will need to assemble a simple power supply using a 7805 integrated stabilizer.

Connection Bluetooth module HC-05:

  • VCC - 5V (supply +5 V);
  • GND - GND (ground, common);
  • RX - TX on Arduino nano, mini, Uno;
  • TX - RX on Arduino nano, mini, Uno;
  • LED - not used;
  • KEY - not used.

The program sketch below is universal for controlling both one LED and an LED strip. The main thing is to leave the necessary lines, and delete the unnecessary ones or make comments in slashes.

Unsigned long x; int LED = 9; // green is connected to pin 9 int LED2 = 10; // blue is connected to pin 10 int LED3 = 11; // red is connected to pin 11 int a,b,c = 0; void setup() ( Serial.begin(9600); Serial.setTimeout(4); pinMode(LED, OUTPUT); pinMode(LED2, OUTPUT); pinMode(LED3, OUTPUT); ) void loop() ( if (Serial. available()) ( x = Serial.parseInt(); if (x>=0 && x<=255) { a = x; // для RGB ленты //a = 255-x; // для светодиода analogWrite(LED, a); } if (x>=256 && x<=511) { b = x-256; // для RGB ленты //b = 511-x; // для светодиода analogWrite(LED2, b); } if (x>=512 && x<=767) { c = x-512; // для RGB ленты //c = 767-x; // для светодиода analogWrite(LED3, c); } /* Serial.println(x); Serial.println(a); Serial.println(b); Serial.println(c); */ } }

If you need to connect one RGB LED, then there is a wiring diagram for connecting it.

Installing the application on your phone

Download the application with the short name RGB to your phone. .

After installation, launch the application from the icon.

Click on the inscription

We find the installed Bluetooth module HC-05 in the list.

If there is a connection, the address and name of the installed Bluetooth module will be displayed instead of the inscription.

Well, that's all, RGB backlight control is set up!

Here is a video example of our project in action:

GPS clock on Arduino Biometric lock - LCD display diagram and assembly

It was always interesting to try the ws2812b LED strip. I got the strip from Banggood. Especially suitable for the New Year holidays. I wanted to use it in different ways. As a decoration or garland for the New Year, or as an independent SDU.
The Chinese gave the following parameters:
-Operating voltage: DC 5V
-power: 43.2w
-Width: 12mm
-length: 1m
-waterproof: not waterproof (ip20)
-Excellent, high quality smart lighting!
-Based on high quality SMD5050 RGB LEDs insert (built-in) integrated ICS control ws2811. Each LED is independently addressable, opening up entirely new lighting possibilities.
-ws2812. 5050 SMD w/ws2811 IC built-in in144 RGB LEDs per meter
-ON WS2811 Control IC ONE LED Chip
-Each LED is individually addressable, with 8 bits of green, red and blue data shifted over 24-bit color
-strip can be cut one from one led chip.

Note: Power supply or controller does not include

Package included:
1 * RGB LED strip

What is ws2812b? This is the second generation of individually addressable full-color LEDs, also known as NeoPixel. RGB LEDs and a controller are collected in one housing. There are 255 brightness levels available for each color. A total of 16 million colors and only one wire for control. Available in the form of individual LEDs, strips, rings, matrices, etc. An external controller is required for operation; Arduino is quite suitable for this role. Each of the LEDs (red, blue, green) consumes 20 milliamps at maximum brightness. The maximum power consumption is 60 milliamps when all three diodes are on, resulting in a white color. From here it is easy to get the maximum consumption of the entire strip by multiplying 60 milliamps by the number of LEDs. Diode controllers consume a little more.





Connection
The tapes themselves do not glow; they require a microcontroller. Arduino is perfect for this role.
An Arduino or Raspberry PI will do. I put together a wiring diagram.


There are 255 brightness levels available for each color. A total of 16 million colors and only one wire for control. Available in the form of individual LEDs, strips, rings, matrices, etc. An external controller is required for operation; Arduino is quite suitable for this role. Each of the LEDs (red, blue, green) consumes 20 milliamps at maximum brightness. The maximum power consumption is 60 milliamps when all three diodes are on, resulting in a white color. From here it is easy to get the maximum consumption of the entire strip by multiplying 60 milliamps by the number of LEDs. Diode controllers consume a little more.
Approximate peak consumption for 1 meter strips:
30 diodes per meter 9.5 watts (slightly less than 2A at 5V)
60 diodes per meter 19 watts (3.6A at 5V)
144 diodes per meter 35 watts (7A at 5V)
It is recommended to select power supplies with a small power reserve.
Connection.
The tapes themselves do not glow; they require a microcontroller. Arduino (Uno.Nano,Pro mini) is perfect for its role.


How to use this ribbon is up to you - as a decoration, a garland for the New Year, or as an independent SDU. I purchased a 1 meter long strip with 144 LEDs. It can be cut into several pieces if necessary. The backing comes in white and black. The ends have connectors for connecting the next ribbon. That is, you can lengthen the garland.


I made a light and music installation to visualize music in real time. Many different lighting effects synchronized with music.


51 strip LEDs are connected to one channel, and in parallel, in this case, a ring with LEDs (purely for demonstration)

Connect the outputs from the loudspeaker to the sound source. Made on a ws2812b LED strip, Arduino UNO, step-down Dc-Dc board or 5 volt/3 amp power supply. The principle of a signal level indicator with a large number of lighting effects has been implemented. Where to use this scheme is your own business and depends on your imagination. Sketch at the link
I think the advantage is that this strip is controlled via one wire, and you can get different effects on each LED.
The downside, I think, is that these LEDs are still, of course, overpriced. Nevertheless, you can get a lot of effects in color and dynamics for subsequent developments, even for beginners. Thank you all for your time and have a nice New Year!!!
More details in the video

An RGB controller is used to control these devices. But, besides it, in recent years the Arduino board has been used.

Arduino - operating principle

Arduino board

An Arduino board is a device on which a programmable microcontroller is installed. Various sensors, controls or encoder are connected to it and, according to a given sketch (program), the board controls motors, LEDs and other actuators, including other Arduino boards via the SPI protocol. The device can be controlled via a remote control, Bluetooth module, HC-06, Wi-Fi, ESP or internet, and buttons. Some of the most popular boards are Arduino Nano and Arduino Uno, as well as Arduino Pro Mini - a device based on the ATmega 328 microcontroller


Appearance of Arduino Pro Mini
Appearance of Arduino Uno
Appearance of Arduino micro

Programming is carried out in the open source Arduino environment installed on a regular computer. Programs are downloaded via USB.

The principle of load control via Arduino


Arduino control

The board has many outputs, both digital, having two states - on and off, and analog, controlled via a PWM controller with a frequency of 500 Hz.

But the outputs are designed for a current of 20 - 40 mA with a voltage of 5 V. This is enough to power an RGB indicator LED or a 32x32 mm matrix LED module. For a more powerful load this is not enough.

To solve this problem in many projects you need to connect additional devices:

  • Relay. In addition to individual relays with a supply voltage of 5V, there are entire assemblies with different numbers of contacts, as well as with built-in starters.
  • Amplifiers based on bipolar transistors. The power of such devices is limited by the control current, but you can assemble a circuit from several elements or use a transistor assembly.
  • Field-effect or MOSFET transistors. They can control loads with currents of several amperes and voltages up to 40 - 50 V. When connecting the mosfet to PWM and an electric motor or other inductive load, a protective diode is needed. When connecting to LEDs or LED lamps, this is not necessary.
  • Expansion cards.

Connecting LED strip to Arduino


connecting LED strip to Arduino

Expert opinion

Alexey Bartosh

Specialist in repair and maintenance of electrical equipment and industrial electronics.

Ask a question to an expert

Arduino Nanos can control more than just electric motors. They are also used for LED strips. But since the output current and voltage of the board are not sufficient to directly connect a strip with LEDs to it, additional devices must be installed between the controller and the LED strip.

Via relay


Connection via relay

The relay is connected to the device via a digital output. The strip controlled with it has only two states - on and off. To control the red-blue-green ribbon, three relays are needed. The current that such a device can control is limited by the power of the coil (a low-power coil is not able to close large contacts). To connect more power, relay assemblies are used.

Using a bipolar transistor


Connection using a transistor

A bipolar transistor can be used to amplify the output current and voltage. It is selected based on load current and voltage. The control current should not be higher than 20 mA, therefore it is supplied through a current-limiting resistance of 1 - 10 kOhm.

It is better to use a transistor n-p-n with a common emitter. For a higher gain, a circuit with several elements or a transistor assembly (amplifier microcircuit) is used.

Using a field effect transistor

In addition to bipolar ones, field-effect transistors are used to control the strips. Another name for these devices is MOS or MOSFET-transistor.

Such an element, unlike a bipolar one, is controlled not by current, but by voltage at the gate. This allows the low gate current to drive large load currents—up to tens of amperes.

The element is connected through a current-limiting resistance. In addition, it is sensitive to noise, so the controller output should be connected to ground with a 10 kOhm resistor.

Using expansion cards


Connecting Arduino using expansion boards

In addition to relays and transistors, ready-made blocks and expansion boards are used.

This could be Wi-Fi or Bluetooth, a motor control driver such as the L298N module, or an equalizer. They are designed to control loads of different power and voltage. Such devices are single-channel - they can only control a monochrome strip, and multi-channel - designed for RGB and RGBW devices, as well as strips with WS 2812 LEDs.

Example program


Arduino and LED strip

Arduino boards are capable of controlling LED structures according to predefined programs. Their libraries can be downloaded from the official website, found on the Internet, or written a new sketch (code) yourself. You can assemble such a device with your own hands.

Here are some options for using such systems:

  • Lighting control. Using a light sensor, the light in the room turns on both immediately and with a gradual increase in brightness as the sun sets. Switching on can also be done via wi-fi, with integration into the “smart home” system or connection by telephone.
  • Turning on the light on the stairs or in a long corridor. The LED lighting of each step separately looks very nice. When a motion sensor is connected to the board, its activation will cause a sequential, time-delayed switching on of the lighting of the steps or corridor, and turning off this element will lead to the reverse process.
  • Color music. By applying an audio signal to the analog inputs through filters, the output will be a color and music installation.
  • Computer modding. With the help of appropriate sensors and programs, the color of the LEDs can depend on the temperature or load of the processor or RAM. This device operates using the dmx 512 protocol.
  • Controlling the speed of running lights using an encoder. Similar installations are assembled on WS 2811, WS 2812 and WS 2812B microcircuits.

Video instruction


On the eve of the New Year, I suggest you assemble a programmable RGB Christmas tree garland with the ability to create various patterns.

What will you need for the garland?

WS2811 RGB Full Color 12mm LED String DC 5V can be purchased on Aliexpress for $20. The usual end of one such garland can be connected to another to increase the length. This article is designed for building light patterns, so if you have a programmable LED garland with a different protocol on hand, you will need to rewrite the program and connect the garland in accordance with the datasheet.
5 volt current source, designed for the current consumed by your garland. Usually the seller indicates the current consumed by the garland.
Arduino of any version. The author used a standard Arduino Uno.
Green acrylic paint
Insulating tape
The wire.
It is advisable to have JST connectors to make it easier to connect the garland to the controller

Before you start assembling your Christmas tree garland, make sure that all LEDs are working properly. On the Internet you can find how to connect the WS2811 to Arduino.

Determine the +5V and GND pins from the datasheet for your WS2811
Red = +5V
Blue = GND
White = Data

The connection looks like in the picture.

Install the popular WS2811 Arduino library from Adafruit. You can download and read the installation instructions here:
Modify the attached code according to the length of your garland in #define LED_COUNT. Download and run the program on Arduino. Please note that the pixels change color from red to green to blue to white within 5 seconds. This ensures that all 3 LEDs inside the pixel are working.

(downloads: 1085)

Voltage drop estimation.

Each LED pixel and subsequent connected LED garland will cause some kind of voltage drop. So after 50 LEDs in your LED garland, the voltage of the power supply will drop by some noticeable amount. For example, from 5V to 4.7V. This means that the next garland that you connect to the first one will be powered not from 5V, but from 4.7V, and the voltage after it will drop even lower. As a result, each LED will be darker than the previous one. Ultimately, when the voltage drops to 3.3V, the microcircuit that serves the WS2811 protocol simply stops working.

Since each pixel has 3 LEDs and the white color of the garland means that all 3 LEDs glow equally, the voltage across it will drop more than if, for example, only red LEDs were lit. When starting the testing program, did you notice strong darkening at the ends of the garland? You can connect additional 5V power there. The author did this every 100 pixels

Painting the garland.

Normal Christmas lights are colored green to blend in with the tree. Your LED string light has wires of different colors. Hang the garland and paint the wires green with acrylic paint, this will take a little time. Wrap the WS2811 housings in black electrical tape, it will be faster than painting them.


Determining the X and Y position of each pixel

Hang the assembled garland on the Christmas tree. You can then calculate the X and Y position of each pixel and insert this data into the program code. To do this, use this code file. Uncomment the first function loop(), which lights up sections of 10 LEDs. If you have more than 50 LEDs, then you can extend this section by simply copying, remembering to indicate the required number in #define LED_COUNT

Try to overlay the grid so that the bottom left LED falls into cell 1.1. This is done so that the program can determine the middle of the tree in both X and Y directions. Entering X and Y coordinates is a manual process, you will get each coordinate by watching the video. 200 coordinates sounds, of course, intimidating, but it will take about 20 minutes.

You can print out the grid and attach it to your computer monitor or phone display so you don't have to bother with video editors.

The attached file, like the previous file, is an example of code that iterates through various patterns, as in the video.

(downloads: 1240)

From the video you can understand the logic of the program and write your own templates or change the code to suit your needs. The other file attached is a setup file to allow the Arduino to be controlled via serial interface from another device. The author used a Raspberry Pi to control an Arduino.

Here's a New Year's garland using Arduino and the WS2811 kit.

(downloads: 1132)







2024 gtavrl.ru.