Photo relay on the ATTiny13 microcontroller. Miniature reminder timer on the ATtiny13A microcontroller

Sometimes you need to program a small task for which even Arduino is too redundant. For such small tasks, small, inexpensive and very low power ATTiny controllers may be suitable.
In this review I will tell you about them, how to cook them and what to eat them with.

I bought ATTiny13 quite a long time ago. They lay there and waited in the wings. And then at work I found a tabletop light-guide Christmas tree with burnt filling. This is where I remembered ethical controllers.
But everything is in order

Let's start with the characteristics of ATTiny13

These are 8-bit controllers with RISC architecture and ultra-low consumption.
  • Memory for programs (FLASH) - 1Kb
  • Non-volatile data memory (EEPROM) - 64 Bytes
    RAM - 64 Bytes
    Number of inputs/outputs - 6
    PWM outputs - 2
    Analog inputs (ADC 10bit) - 4
    Timer 8 bit - 1
    Supply voltage 1.8 - 5.5V
    Operating frequency - up to 20 MHz
    Consumption in active mode 1.8V/1MHz - 190µA
    Consumption in sleep mode 1.8V/1MHz - 24uA
  • I purchased Tinkers in a DIP8 package.


    They are very small compared to

    ATTiny programming

    I decided to program from the Arduino IDE, especially since I’m already on the arduino.cc website. From there. I unpack the archive into the folder c:\Program Files (x86)\Arduino\hardware\ and additional boards appear in the Arduino IDE
    Now loading programs. The microprocessor memory capacity is only 1Kb and no bootloader will fit there. Therefore, sketches are loaded by the programmer via ISP. USBAsp, which I used to program Atmega328, did not want to work with Tinka. You need special programmer firmware, which I didn’t bother with. . To do this, I put together the following diagram:
    In the Arduino IDE, select “File->Samples->ArduinoISP” and upload the programmer sketch to Arduino. Then I select “Tools->Programmer->Arduino as ISP”. Now you can upload simple sketches to Tink. It should be noted that ATTiny13 core for Arduino contains a limited set of Arduino functions.

    List of Apduino functions supported by ATTiny13 core

    • random()
    • randomSeed()

    • millis()
    • micros()
    • delay()
    • delayMicroseconds() *
    • analogRead()
    • analogWrite()
    • pinMode()
    • digitalRead()
    • digitalWrite()
    • pulseIn() (Untested)
    • shiftIn() (Untested)
    • shiftOut() (Untested)

    Application of ATTiny13

    I decided to restore such a Christmas tree with light guides
    Initially there was a 12V halogen light bulb and a motor that rotated a color filter disk

    All this died happily. I’m assembling the following circuit with a piece of LED strip:
    on a breadboard
    Let Tink gradually change the colors of the ribbon. But this requires a 3-channel PWM, and the ATTiny13 has only two such outputs in hardware. This means the PWM will be software for 3 channels, controlled by a built-in timer.

    Three-channel PWM sketch for ATTiny13

    #include #include #include #include uint8_t counter=0; uint8_t lev_ch1, lev_ch2, ​​lev_ch3; uint8_t buf_lev_ch1, buf_lev_ch2, ​​buf_lev_ch3; ISR(TIM0_OVF_vect)( if (++counter==0) //timer zero crossing counter ( buf_lev_ch1=lev_ch1; //PWM duration values ​​buf_lev_ch2=lev_ch2; buf_lev_ch3=lev_ch3; PORTB |=(1<

    After this, all that remains is to secure the board and tape in the Christmas tree body. I paste white tape to improve light reflection inside the black case


    The Christmas tree is ready. Shines no worse than with a halogen bulb


    Conclusions:

    ATTiny13 microcontrollers are quite suitable for simple automation tasks. Their advantages: low consumption and low price. Disadvantages include very small resources and a rather complex (compared to a regular Arduino) programming setup. But of course, these microcontrollers deservedly occupy their niche

Hello Datagorians!
I started renovation work at home, and I needed an automatic lighting control system that should turn off during the day and, accordingly, turn on at night. I am a fan of AVR controllers and I decided to search the Internet for ready-made solutions, but, unfortunately, I did not find anything suitable.

I needed a simple system that would measure the light level, switch the lighting in day/night mode and have a relay switch delay timer.

This is how this project was born - a photo relay on a small eight-legged 8-bit MK ATTiny13. Why “fence a garden” on an MK, when everything can be assembled using transistors and a bunch of loose materials? Let's consider my project an educational one, aimed at mastering the controller segment of electronics.

Photo relay circuit


The circuit has its own transformerless power supply, built on C1, C2, R1, R2, zener diode D1 and diode bridge BR1.

When operating the circuit, do not touch any of its parts, because The power supply has no galvanic isolation from the electrical network!
Carry out all settings either with the circuit’s power completely turned off, or strictly observing safety precautions.

The zener diode produces a voltage of 9.1 V. This is 2 V higher than the minimum permissible input voltage for normal operation of the 78L05 stabilizer and sufficient for the relay to operate (although its nominal coil voltage is 12 V, more on that later).
Diode D3 serves to protect the 78L05 stabilizer. Tanks C3, C4, C5 are its standard equipment. Transistor Q1 is the switch for relay RL1, resistor R4 limits the base current. Capacitors C6, C7, C8 smooth out noise on the controller lines.

Substring resistors “LUX” and “TIME” are used to adjust the relay response threshold depending on the illumination and adjust the delay of this response from 1 second to 29 minutes.

I had to tinker with food. The fact is that the maximum permissible current through the zener diode D1 (if it is 1 W) is 31 mA. This means that the current consumption of the relay together with the voltage stabilizer U2 and the controller U1 should not exceed this value. It is necessary to take into account possible fluctuations in the Network from 235 V to 190 V. With a capacitance of C1 of 0.47 μF, the current through the zener diode is approx. 22 mA at an input voltage level of 220 V, theoretically there is a reserve.
After conducting experiments, I found out that the relay used reliably operates at a voltage of 6.9 V and a current of 18 mA, and release occurs as much as 2 V. In practice, I observed how the relay continued to work normally at a mains voltage of 190 V.

--
Thank you for your attention!

LED + UART firmware for filling (hex)
🕗 03/12/16 ⚖️ 20.82 Kb ⇣ 25 Hello, reader!

--
Thank you for your attention!
Igor Kotov, editor-in-chief of Datagor magazine

The circuit was debugged in Proteus v8.4 SP0
🕗 03/12/16 ⚖️ 22.72 Kb ⇣ 31 Hello, reader! My name is Igor, I'm 45, I'm a Siberian and an avid amateur electronics engineer. I came up with, created and have been maintaining this wonderful site since 2006.
For more than 10 years, our magazine has existed only at my expense.

Good! The freebie is over. If you want files and useful articles, help me!

--
Thank you for your attention!
Igor Kotov, editor-in-chief of Datagor magazine

The printed circuit board was drawn in SprintLayout v6.0

The program was written in CodeVision AVR 3.12 ( sources):

The design is an IR locator device implemented on one AVR microcontroller, ATtiny13 chip. Short bursts of pulses are emitted by a transmitter (IR LED) in the infrared wavelength range and are received by being reflected from the surface by its photodetector. Received reflected signals are processed and, if perceived as a useful signal, are displayed by LED indication.

Sometimes you just need to set a time interval, without much microscopic precision. For example, for cooking, where the error is a few seconds per half hour, the hour does not play an important role. Based on these considerations, an internal RC oscillator was selected as a clock generator. The stability of which depends on temperature and changes in supply voltage, since the microcontroller remains operational at a voltage of 1.8-5.5 V. I used a 3-volt battery (or 2 cells of 1.5 V each) as a power source.

This simple mini-security alarm on the ATtiny 13 microcontroller is designed to protect apartments, offices, country houses... When the reed switch opens, the alarm sounds a sound signal or, with a little modification, you can send an SMS from a mobile phone. The alarm is controlled by IR key fobs. Main characteristics: dynamic power supply of the photodetector, awakening from the "SLEEP" mode upon interruption from the watchdog timer in the "POWER-DOWN" mode, and as a result low power consumption - about 30 μA.

The principle and algorithm of operation of this device is very similar to the operation of industrial standard security systems for protecting premises. The proposed simple security alarm is triggered by opening the sensor contacts with normally closed contacts in security mode. In quality, which can be:

Wire cable designed to withstand wire breakage if the perimeter is violated;

A reed switch sensor that responds to the movement of a piece of magnet over its contacts when a door is opened, for example, or a factory-made passive infrared sensor that responds to a change in the position of an object with infrared radiation (which is the body of a person - an intruder, in the area of ​​a protected object).

This is a small independent device that prevents unauthorized starting of the engine of a car, motorcycle, boat, yacht... which works independently of other security systems. To remove the engine lock, you must press a button in a certain place (selected at the discretion of the car owner) in the car interior. This can be either a separately installed hidden button or the use of a standard car button.

For beginner radio amateurs mastering microcontrollers, it is often necessary to assemble and test the firmware or circuit in action on a real microcontroller (for example, proteus often simply refuses to adequately simulate a circuit with a microcontroller). For these purposes, and not only beginners, use a debug board and or a development board. For Attiny13/15 microcontrollers and pinout pinouts of other microcontrollers compatible with them, a debug board was manufactured equipped with the minimum necessary functionality. This board has a small, compact size and is cheap to assemble.

In the photo above, a program is loaded into the microcontroller and the debug board itself is connected to a 5-volt power supply through a programmer from the laptop’s USB port.

Development board for microcontrollers Attiny13/15 is built according to the following scheme:

To connect the microcontroller to the debug board, use a connector for microcircuits in a DIP-8 package or a simple “bed” connector for eight-legged microcircuits. This connector can be used both in the usual version with clamping contacts, and in the version with collet contacts. The use of such a connector makes it possible to quickly replace the microcontroller in the debug board in the event of possible malfunctions associated with the microcircuit itself. For example, due to inexperience, you can lock a microcontroller. A quick solution would be to replace it in the debug board, and in the future cure the microcontroller using other means - an RC chain or Fuse bit doctor. It will also be possible to quickly change the brand of the microcontroller - for example, replace Attiny13 with Attiny15 within the same board.

Below is the finished debug board from the mounting side and from the soldering side:

As jumpers, in addition to the usual wire ones, resistors of standard size 1206 with a nominal value of 0 Ohm were used.

So, a little about what is on the development board. Let's start from the power supply - the voltage to the microcontroller is taken from the programmer from the USB port (5 volts), this voltage can be supplied to the microcontroller directly or through three diodes, which reduce the voltage to 3.2 - 3.3 volts. The use of diodes is due to their minimal cost. If you wish, you can always edit the printed circuit board and use voltage stabilizers like AMS1117 3.3 volts. the supply voltage is selected using jumpers Jmp1 and Jmp2 on the development board. It is convenient to use jumpers with “handles” as in the photo, so as not to be forced out when you need to transfer food. Also, power from the programmer is supplied to the microcontroller through limiting resistor R2. Its rating can be taken from 0 ohms to about 10 ohms, depending on preference. To pin PB5 (reset) of the microcontroller with resistor R1 the supply voltage is pulled up, this is necessary to prevent spontaneous restart of the controller in the presence of any interference. A clock button is also connected to this pin to allow you to manually restart the microcontroller while debugging any circuit or firmware.

Since the priority of this debug board is the production of not the most complex projects, the board has connectors with collet contacts for connecting three LEDs. The current limiting resistors are selected in such a way that it is possible to use LEDs of three colors simultaneously (red, green and blue) - 180 Ohms for red and 100 Ohms each for green and blue. This spread in ratings is due to the fact that the voltage drop on red LEDs is usually less than on other colors. This solution will allow the use of RGB LEDs.

However, you can also use ordinary LEDs to indicate something.

Especially for programming, a standard 10-pin connector for AVR programmers, such as USBasp or AVRdoper or others, is provided on the printed circuit board.

Several connectors (pin connections) are provided to connect various components or devices to the microcontroller pins. On the one hand, two types of connectors (PLS-5 and PBS-5) - include a supply voltage contact and a zero potential contact (Gnd), as well as PB0, PB1, PB2 of the microcontroller. On the other hand, there are also two types of connectors (PLS-4 and PBS-4) - include contact zero potential (Gnd) and microcontroller pin contacts PB3, PB4, PB5. There is a separate PLS-3 connector, which includes three contacts connected to the Vcc supply voltage. For more details, see the electrical circuit diagram.

The board has several capacitors that filter the power supplied to the microcontroller to improve performance.

In order to immediately test the development board after manufacturing, a simple firmware was developed that controls three LEDs - they light up and go out in turn. Everything you need will be included below. This simple debugging board can serve as an impetus for newbies in this business to study microcontrollers - after all, there is nothing complicated about it if you have the most basic knowledge of the C or Assembler programming languages.

To program the microcontroller Attiny13 test program (firmware) needs to know the configuration of the fuse bits:

The article is accompanied by test firmware for the Attiny13 microcontroller, a project for the same microcontroller using test firmware, source code in the program, a printed circuit board drawn in, as well as a video of the test firmware running on the debug board.

List of radioelements

Designation Type Denomination Quantity NoteShopMy notepad
IC1 MK AVR 8-bit

ATtiny13A

1 ATtiny15 To notepad
VD1-VD3 Rectifier diode

1N4148

3 To notepad
C1 Electrolytic capacitor10 µF1 To notepad
C2, C3 Capacitor100 nF2 To notepad
R1 Resistor

10 kOhm

1 To notepad
R2 Resistor

4.7 Ohm

1 0 to 10 ohms To notepad
R3, R5 Resistor

100 Ohm

2 To notepad
R4 Resistor

180 Ohm

1 To notepad
LED1 Light-emitting diodeRed1 To notepad
LED2 Light-emitting diodeGreen1 To notepad
LED3 Light-emitting diodeBlue1 To notepad
S1 Tact buttonTC-A1091 To notepad
X1 ConnectorPLS-41 4 pins To notepad
X2 ConnectorPBS-41 To notepad
X3 ConnectorPLS-51 5 pins To notepad
X4 ConnectorPBS-51

This small device is designed primarily for diabetics, but it has a much wider range of uses. Its task is to signal the passage of a given period of time, measured from the moment the button is pressed.

Thus, you can be reminded of the need to measure blood glucose levels after a certain time after eating, or of the need to look into the boiler room some time after igniting the stove, etc.

The device is used to measure one of four possible time periods: 15 minutes, 30 minutes, 1 hour or 2 hours. The countdown is signaled by rapid flashing of the LEDs, and the end of the countdown by flashing and sound. It is powered by one CR2032 battery, so the reminder is very light and miniature.

Design

The schematic diagram of the proposed solution is shown in the figure below.

The use of the ATtiny13A microcontroller from ATMEL made it possible to significantly simplify the design of the device. This type of microcontroller is ideal for use in this case. It has a small SO8 package, the ability to use voltages from 1.8V and various modes to reduce power consumption. In addition, this is one of the most popular and cheapest microcontrollers in this class, which is available in almost any electronics store.

A CR2032 lithium battery is used for power supply, providing a voltage of 3V, which is sufficient to power the device components.

A sound notification about the expiration of a specified period of time is produced using a piezoelectric emitter with a built-in generator. It is quite loud and can be heard even when the device is hidden, for example, in a pocket. The sound emitter is controlled using transistor VT2 (BC847).

The countdown is started and stopped by one press of the SW1 button, the contact of which is pre-connected R6 (10 kOhm) to the power supply positive.

The same resistor is installed on the RESET pin of the microcontroller to prevent accidental changes in its logic level. This change may be caused by an external electromagnetic field or by the microcontroller being exposed to too much static electricity.

The time interval is selected by switching one of the four sections of the switch SW2, type DIP-SWITCH. The closed section connects one of the four resistors (R7 to R10) to the power supply minus, forming with resistor R11.

The microcontroller, applying a high logical level to resistor R11, uses an ADC (analog-to-digital converter) to measure the voltage that is formed at the divider.

Thus, only two microcontroller pins are used to set the time. In addition, this circuit can be disabled by changing the PB1 pin level to low, which will significantly reduce power consumption.

Assembly and commissioning

The miniature reminder is assembled on a double-sided printed circuit board measuring 46mm x 31mm. First of all, it is necessary to solder the surface mount elements that are located on the bottom side of the board - the microcontroller, transistors and others. Next are two LEDs on the opposite side. Finally, you need to solder the through-hole components on the same side as the LEDs.

The microcontroller requires firmware with factory fuses. If everything was assembled correctly, the device is ready for use after installing the battery in the compartment. Simply set the desired measurement time using switch SW2.

Exploitation

While in sleep mode, the circuit does not show any signs of operation. After pressing the SW1 button once, the information is read from the divider and the time countdown begins, as evidenced by the LEDs blinking once. From now on they will flash every 1 second until the countdown ends. If all SW2 switches are in the OFF position, the LEDs will not blink and the device will go into sleep mode.

After the set time has elapsed, the LEDs begin to flash intensely and the sound emitter makes short sounds. Stopping is done by briefly pressing SW1.

It's important to note that once the countdown has started, you won't be able to stop or change its duration. This avoids the situation of accidentally turning off the timing, which can occur when accidentally pressing the SW1 button.

The current consumption at rest is about 0.5 mA, so theoretically a battery with a nominal capacity of 200 mAh should last for 45 years in standby mode. In practice, you can count on a time comparable to the battery life. During the countdown, the average current consumption is about 8 mA, and during the alert state it rises to 15 mA.

(11.5 Kb, downloads: 304)