LED garland on a microcontroller. New Year's LED garland on a microcontroller Diagram of an LED garland on a microcontroller

The ATtiny2313 garland is very easy to assemble. In this simple article we will make a mini garland of 4 LEDs.

Are you, our button, pressed or released?” – this is exactly the question we asked in the last article. And depending on the state of the button, we made an effect of 4 LEDs. In this article we will analyze a similar situation. So, let's go!

Remember the Chinese garland for 100 rubles?

We press the button and the blinking effect becomes completely different;-) This is exactly what we will do in this article;-)

We will not make a Chinese garland with N number of light bulbs, but will make a simplified diagram of such a garland using an AVR Tiny2313 MK and four LEDs. Using the button we will change the blinking effect.

So, our task literally sounds like this:

Create a garland on the AVR Tiny2313 microcontroller from four LEDs and one self-returning button (a button that is pressed and releases itself). We press the button once - the first blinking effect of the button appears, press the button a second time - the second blinking effect appears, and so on. We will have seven effects in total. The condition is that while the LEDs are blinking, our MK does not respond to the button. That is, until the effect has passed, pressing the button is not reflected in the effect in any way. The effect is NOT interrupted. When the effect ends, only then will the MK process the button press.

The task seems clear. First, let's create a simple circuit in Proteus. The diagram will look something like this (click to enlarge, opens in a new window):


All? No, not all! Now we sew our MK with a HEX file. Where can I get it? From Atmel Studio 6. But to create it, we first need to write a program that our MK will use. How to do all this, look in this article.

Below is the text with comments:



Also pay attention to the line of code:

(_delay_ms(50); // enable a delay of 50 milliseconds for anti-bounce

The Proteus program would work without this line of code. Why did we put it in then? The point is that the real state of affairs is a little worse. The scapegoat in this case will be the most harmless button, which we will put in the circuit for switching garlands, assembling it on a breadboard.

What does the button do in the circuit according to the MK circuit design? It supplies a logical zero or one to the MK pin. So? So. But in a real circuit, it does not immediately close and open the circuit. When closing or opening the button, we do not have a clear switching of signal levels from logical one to zero and vice versa. Switching using a button looks something like this:

From logical one to zero something like this:


From zero to one something like this:


All this billboard when switching a button is called contact bounce and interferes with logic device developers. The fact is that the MK can count these chaotic impulses as either a logical one or a zero. This misunderstanding has now been resolved with a simple line of code.

I am attaching SIshnik, HEX and the Proteus file to the project.

CMU/SDU on a microcontroller (8 channels)

This device combines a color music device (CMU) and a light dynamic device (SDU) with 8 channels, with many lighting effects. The outputs of the device are designed to connect a sufficiently powerful load.

Frequency separation among DMU channels is purely software and very simple; a PIC microcontroller PIC16F628A is used. The number of timer/counter pulses for a strictly defined period of time is counted and, depending on the value of this counter, one or another LED turns on.

And here is the diagram of the device:

Digging allows:

  • Select mode - CMU/SDU. In the SDU mode, even if there is a signal at the input, only the main program of the light-dynamic device works. In the CMU mode, if there is no signal, the selected SDU effect is played as a background mode.
  • Select the SDU effect. The button cyclically switches all possible effects of the dynamic light device.
  • Increase and decrease speed. These buttons control the speed of the SDS effects; they have no effect on the CMU.

The printed circuit board is single-sided and quite simple. The LEDs installed on the board are debugging and serve simply as an additional visualization device.

For colored spotlights, I used ready-made spotlights from a hardware store. From them I removed the standard light bulb socket and installed a matrix of 37 bright LEDs there. Each spotlight has its own color - red, green, blue, etc., whatever we could find. Spotlights are placed at the corners of the room and at the midpoints at the top of the walls, all aimed at the center of the room. At night with music it looks very impressive, especially the strobe effect

2, diagram

This LED garland project on a microcontroller is well suited for beginners. The circuit is distinguished by its simplicity and contains a minimum of elements.

This device controls 13 LEDs connected to the microcontroller ports. An ATMEL microcontroller is used as a microcontroller: ATtiny231320PI. Thanks to the use of an internal oscillator, pins 4 and 5 are used as additional ports of the microcontroller PA0, PA1. The circuit provides the execution of 12 effect programs, 11 of which are individual combinations, and the 12th program is a sequential one-time repetition of previous effects. Switching to another program is done by pressing the SB1 button. Effect programs include running single fire, increasing fire, running shadow and much more.

The device has the ability to adjust the speed of changing combinations when executing a program, which is carried out by pressing the buttons: SB2 - increase speed and SB3 - decrease speed, provided that switch SA1 is in the "Program speed" position. It is also possible to adjust the frequency of LED lighting (from a stabilized glow until light flickering), which is carried out by pressing the buttons: SB2 - decrease (to flicker) and SB3 - increase, provided that switch SA1 is in the "Flicker frequency" position. For switch SA2, the closed position corresponds to the mode for adjusting the speed of program execution, and the open position corresponds to the mode for adjusting the frequency of LED lighting.

The numbering order of the LEDs in the circuit corresponds to their lighting order during program execution. If necessary, the RESET pin can be used for reset, but it is not used as the PA2 port. When programming, the device selected a clock frequency of 8 MHz from the internal oscillator (fuses CKSEL3..0 - 0100). Although it is possible to use a frequency of 4 MHz (fuses CKSEL3..0 - 0010) with corresponding changes in the time intervals of the circuit.

The type of LEDs indicated in the diagram was used in a prototype; any LEDs with a supply voltage of 2-3 volts are suitable for the circuit; resistors R1-R17 can be used to adjust the brightness of the LEDs.

You can download the HEX firmware, as well as the program files in assembler, below

List of radioelements

Designation Type Denomination

Shop
DD1 MK AVR 8-bit

ATtiny2313

1
Search in store
C1 Electrolytic capacitor100 µF 10 V1
Search in store
R1-R17 Resistor

1 kOhm

17
Search in store
LED1-LED13 Light-emitting diodeLD57113
Search in store
SB1-SB3 Button
3
Search in store
SA1 Switch
1
Search in store


3, diagram

Christmas tree garland switch based on PIC16C84.


In my opinion, the most suitable platform for such a device is
There is a microcontroller AT89C2051 from Atmel, AT90S2313 (also Atmel),
Bo PIC16F84 from Microchip. I chose PIC16C84 - purely for reasons
It is possible to use an outdated crystal somewhere (unfortunately, for this
task, it is not very convenient due to the peculiarities of constructing tables in the program.
me memory).

2. Device capabilities.

Supports four control channels (phase control is used
thyristors with duplication on control LEDs).

Provides a choice of one of sixteen control programs (however
now only five are written), or sequential execution of all programs
ram and manual selection of speed (slow, normal, fast) switching.

3. Device management.

All control is done using four buttons:

"<<" - выбор программы, переключиться на предыдущую;
">>" - select a program, switch to the next one;
When you select a program, its number (in binary code) is displayed on the
contor LEDs in binary code, as long as the button is pressed
boron.
"Speed" - switching program execution speed, cyclically
"normal">"fast">"slow">"normal".
"Demo" - automatic selection of programs after program execution
the next one starts. This mode is canceled when you press the
ki"<<" или ">>".

In addition, when you turn on the device, you can select additional options.
presses, for which you need to press and hold the “Demo” button, and, at the same time
with it a combination of other buttons, each of which determines the following
blowing modes:
"<<" - режим "резкого" включения/выключения, без плавной регулировки
channel brightness;
">>" - this button is currently reserved for future use;
"Speed" - control mode for three channels, the fourth channel in some
Do not use in certain modes (such as “running lights”).

4. Design and details.

You can use PIC16C84 or
PIC16F84, with any clock frequency. As a timing element
- quartz or piezoresonator with a frequency of 4 MHz, special requirements for
stability is not presented. Thyristors (triacs) - almost any
with sufficient margin for switching voltage. Diodes in "silo"
in the rectifier - choose one with a sufficient margin for current and reverse
voltage of at least 400 volts. Current limiting resistors in the control circuit
influencing electrodes of thyristors - it is recommended to choose with dissipated power
with a power of at least 1 watt.

The design has galvanic contact with the network, so the metal
Certain elements of external design should not have contact with the circuit.
This especially applies to control buttons. When setting up the device
Traditional safety precautions must be observed.

"Advanced" users can try to improve the controls
additional program or add new lighting effects (please send
please, description or “sources” of new effects to the author), the program on-
written using mnemonic codes of the spasm assembler from Parallax Inc.,

The proposed lighting effects machine contains four groups of LEDs combined into a New Year's garland, which is controlled by a microcontroller.

The basis of the lighting effects machine (see figure) is a microcontroller, which made it possible to make the device as simple as possible. The controls are variable resistor R2 and button SB1.

Scheme

Using the button, you select an effect (out of ten possible), and use a variable resistor to adjust the speed of its playback (faster, slower).

Control signals from the outputs of the microcontroller DD1 through current-limiting resistors R5, R6, R8, R9 are supplied to the bases of transistors VT1-VT4, which supply voltage to the groups of LEDs HL1-HL3, HL4-HL6, HL7-HL9, HL10 -HL12. Resistors R4, R7, R10, R11 limit the current through the LEDs.

Rice. 1. Schematic diagram of a lighting effects machine based on LEDs and a microcontroller.

Details

Fixed resistors MLT, S2-23, variable R2 - SPO, SP4-1 are used, its resistance can be in the range of 1...50 kOhm, but the condition R1 = R2 must be met. Oxide capacitors are imported, SZ - K10-17, any LEDs can be used with a permissible current of up to 20 mA and a voltage of up to 3 V.

KT315B transistors are interchangeable with transistors of the KT315, KT3102 series with any letter indices. You can use any voltage stabilizer with an output voltage of 5 V, and any diode bridge with a permissible current of at least 0.15 A and a permissible reverse voltage of at least 20 V.

Step-down transformer - with a voltage on the secondary winding of 9... 10 V at a current of up to 0.15 A. Small-sized button with self-reset - PKn159, DTST-6, power switch - MT1, MTD-1, P1T1-1. Four groups of LEDs are twisted into one garland, in which the LEDs should be arranged in the following sequence: HL7, HL1, HL4, HL10, HL8, HL2, HL5, HL11, etc.

Setting up

The device does not require setup. If necessary, the brightness of the LEDs can be changed by selecting resistors R4, R7, R10, R11. When programming, set the following microcontroller configuration: CKSEL0=1, CKSEL1=0, RSTDISBL=0, SPIEN=0, BODEN=1, BOD-LEVELS.

In the author’s version, the variable resistor turned out to be of low quality (unreliable contact of the moving contact to the resistive layer), which sometimes led to the microcontroller program “freezing.” This drawback was eliminated by installing a constant 1 MΩ resistor between pin 1 of the microcontroller and the negative power line.

This SDS is developed in two versions. The first controls only the LEDs located on its board and is intended for developing and debugging lighting effects programs. A microcontroller with a debugged program can be transferred to the board of the second version of the SDU, to which you can connect 16 lighting devices powered from a 220 V network

Of the 20 pins of the ATtiny2313 microcontroller, 19 are used in the SDS under consideration: two for supplying the supply voltage; one - for connecting a button that controls the speed of playback of lighting effects; 16 - for generating control signals for garlands or other lighting devices.

There are eight effects playback speed settings; they can be switched in a circle by pressing a button. At minimum speed, the state of the garlands changes every 8 s, and at maximum speed, the change period is reduced to 0.5...1 s. It should be borne in mind that due to the nature of the program, the duration of pressing the button required to switch the speed is quite long. In addition, it depends on the speed currently set. The microcontroller stores speed information in its EEPROM, so when the SDU is turned on, it becomes the same as it was in the previous operating session.

Rice. 1. SDU circuit with ATtiny2313 microcontroller for 16 garlands

The circuit diagram of the debugging version of the SDU, which controls only LEDs HL1-HL16, is shown in rice. 1.

Microcontroller DD1 operates from an internal RC oscillator with a frequency of 4 MHz. The XP1 connector is intended for connection to the programmer of a microcontroller installed in the SDU panel. During programming, the LED power supply circuit must be broken by switch SA1, which eliminates their influence on the programming process. Resistor R1 maintains a high logic voltage level at the PD2 input of the microcontroller when the SB1 button is released. When the button is pressed, this level goes low.

The device is assembled on a printed circuit board measuring 95x70 mm made of foil fiberglass. Its drawing is shown in rice, 2. There is a panel on the board for the microcontroller. This allows you to program it and test it in operation, and then transfer it to another SDS, which will be described below.

The board is designed to install oxide capacitors (C1 and C2) SR or similar. The dielectric of capacitors SZ and C4 is ceramic. Resistors - CF-0.125 or other similar ones. Transformer T1 - TPG-2 with a secondary alternating voltage of 6 V, designed for installation on a printed circuit board. You can use its analog BVEI 306 2061 with a power of 2.6 VA. In the case under consideration, the DA1 stabilizer does not require a heat sink. Buttons SB1 and switch SA1 can be of any size suitable for installation on the board.

The second version of the SDU controls not LEDs, but incandescent lamps or other 220 V lighting devices. To do this, each of the resistor-LED pairs of the previous version is replaced by a triac switch, the circuit of which is shown in rice. 3. To control the powerful triac VS1, optocoupler 1)1 is used here, the photodinistor of which is designed so that the moments of its opening always coincide with the transitions of the voltage applied to it through zero. This reduces the electromagnetic interference generated by the SDU.

Since only 5 mA of current through its emitting diode is sufficient to control the MOS3043 optocoupler, the total load on the microcontroller does not exceed 80 mA. The total current consumption from the power supply in the new version is approximately two times less. This made it possible to abandon the transformer and use a transformerless unit with quenching capacitors. On his diagram ( rice. 4) the numbering of elements continues what started on rice. 1.

The printed circuit board of the second option has dimensions of 195x85 mm. Its drawing is shown in rice. 5. Elements of sixteen identical switches have position numbers on it with digital prefixes indicating the serial number of the switch. For example, 8R1—8R3, 8U1, 8VS1 are the elements of the eighth switch, which replaced resistor R9 and LED HL8 and controls an incandescent lamp (or a garland assembled from them) 8EL1.

All 16 triacs 1VS1 - 16VS1 are mounted on a common heat sink made of an aluminum plate with dimensions of 160x25x2 mm, located perpendicular to the surface of the board. Mounting holes for triacs are drilled in it at a height of 19 mm from the board.

Triacs VT138X-600 in a fully insulated TO-220F housing can be replaced by devices of the VT137-VT139 series for 600 or 800 V, including those in a conventional TO-220 housing with a metal mounting and heat-dissipating flange. Since this flange is connected inside the triac to its pin 2, and all these pins are connected on the board, insulating the triacs from the heat sink is not required.

It is recommended to first attach the triacs to the heat sink, and then mount their entire assembly on the board. Resistors 1R3-16R3 are soldered directly to the triac terminals. Pins 1 of the triacs are clamped in the holes of the ZVI-10-2.5-6 mm2 screw terminals facing them, the block with which ( rice. 6) is installed along the long side of the board next to the triacs. There are a total of 17 pairs of clamps in the block, 16 of which are used to connect lamps 1EL1-16EL1, and another one is for their common wire.


Capacitors C5 and C6 - K73-17V or imported, capable of operating at an alternating voltage of at least 250 V. Resistors 1R1 - 16R1 - MF-1.

The microcontroller must have a panel in which it must be installed already programmed.

Attached to the article are three versions of the microcontroller program, suitable for use in both versions of the CDS:
PG16H_S_REGULhex - 16 garlands work independently;
PG8_MK_S_REG.hex - two groups of eight garlands work synchronously;
PG4_MK_S_REGUL.hex - four groups of four garlands work synchronously.

The microcontroller configuration is in all cases left set at the factory.
If a smaller number of garlands (LEDs) are used, then elements related to unused garlands may not be installed on the boards of the described SDS. When working with the SDS of the second option, all components of which have a galvanic connection to the network, it is necessary to comply with electrical safety rules.

Radio Magazine, No. 11 2014 I. ABZELILBASH, Sibay, Bashkiria