Musical ringer for MK Attiny13. Play melody on PIC Download doorbell circuit diagram on pic16f628a

Very often, when we buy things, we place certain hopes on them, but sometimes, completely unexpectedly, they become a reason for a scandal. This is exactly what happened to the author when he had to purchase a new Chinese-made doorbell every week. On the fourth call, it finally became clear that the Chinese are good people, but their products... Our industry, unfortunately, has forgotten about such minor problems of consumers. There are a lot of musical bell schemes, but the author did not find simple and multifunctional ones, so he had to develop a simple and reliable bell himself to create comfort in the house. Beginning microcircuit engineers can easily repeat this circuit and add to the program to their taste.

For the musical call was chosen simple microcontroller ATtinyl5 from Atmel. A small number of pins, a small package, multifunctionality - all these characteristics are very attractive for microcontroller modeling. The main idea was to duplicate the Chinese call with the addition of a music generation circuit, as well as to implement its completely autonomous, independent operation. In addition, control of the supply network was organized. As soon as the mains power disappears, the circuit begins to consume current from the electrolytic capacitor, and when the voltage drops below normal, the controller interrupts the program and goes into sleep mode.

The circuit (Fig. 5.1) can work as a separate device or be connected at points A and B to the home bell circuit. Power is supplied from the network AC voltage 220 V. A half-wave rectifier with current limitation powers the circuit of a powerful zener diode and voltage stabilizer. The circuit for reducing the network voltage to a level of 9 V (Rl, SZ) is designed for a current consumption of 40 mA. The stabilization current of the zener diode is 20 mA - the same amount consumed by the 5 V voltage stabilizer that powers the microcontroller during operation of the device.

At the moment of switching on, the main current is consumed by capacitor C2, but this current is limited by the reactance of C2 and the resistance

R1. Capacitor C2 also serves as a current source when the power to the circuit is turned off, while D2 is locked, and R5, R4, LED1, R3, Dl, R2, IC2 remain consumers.


Rice. 5.1. Musical bell circuit

When the voltage on C2 drops to a level less than 9 V, the zener diode D1 reduces current consumption to a minimum and turns off. Capacitor C 4 smoothes out high-frequency impulse noise passing from the network to the power circuit. Capacitors R5 and R4 constitute a voltage divider on the zener diode D1 (necessary for the measuring channel of the microcontroller). The measuring channel does not contain a sampling and storage circuit, as well as an integrator and a high-pass filter, since these functions are performed by filtering power elements C2, C4. The integrator function is performed by the limiting zener diode D1.

The microcontroller turns on as soon as the power supply is applied. At the same time, LED1 lights up. When the voltage on the zener diode D1 drops to a level of less than 9 V, the microcontroller goes into sleep mode. As soon as the microcontroller receives power voltage, it generates low-frequency signals of musical melodies on a piezo emitter (you can choose any piezo emitter). To better reproduce the melody, you can use a speaker, but at the same time it is necessary to provide a current amplifier for it (on a microcircuit or on a transistor) and increase the capacitance C2.

Program

The program is developed for a microcontroller with a clock frequency of 4 MHz. Its execution when the power is turned on begins with the interrupt vector, along which it goes to the subroutine specified by the vector. When reset, the interrupt vector moves the program to the RESET label. Next, the program checks the supply voltage. This function is performed by the ADC using a single conversion. The program checks the circuit's supply voltage, and if it drops below 0.89 V, the microcontroller goes into sleep mode.

After successfully passing the power test, the values ​​of all variables are reset to zero, and the I/O port and two timers are configured: TO and T1. The TO timer is designed to set the playing time of the melody, and the T1 timer is designed to set the frequency of the selected note. Timer T1 is configured to synchronize from the microcontroller clock generator with a division ratio of 1/64. The frequency of a note is specified by entering the half-cycle length. By going through a cycle consisting of dividing the clock frequency of the internal oscillator and inverting the output signal twice, a period with a given frequency is formed.

The program is based on the use of timer T1 in conjunction with the alternative function of the OClA output of port PB1, i.e. As soon as the timer has completed the pulse count specified by the program, a unit is output to the PB1 output. In the next cycle, T1 is reset and repeats the count of pulses to a given value, upon reaching which the signal at the PB1 pin is inverted. With each subsequent count, the value on PB1 is inverted. Table will help you understand the calculation of the established coefficients for notes of the first, second and third octave (the author did not consider sharp and flat due to the limited resource of the microcontroller). 5.1. Output data: clock frequency - 4000000 Hz, division factor - 2.

Table 5.1. Calculation of coefficients for notes of the first, second and third octave

Real

Real

Setting the TO timer determines the duration of the note. The TO is configured to synchronize from the microcontroller clock generator with a division ratio of 1/1024. Unfortunately, this timer is only 8 bits wide. Even with the maximum clock frequency division factor, it is very difficult to reach the required note duration (about 0.1-0.5 s). For this reason, the maintenance cycle is additionally set up to 64 times. This function is repeated many times until the TO stops the note and moves on to the next note.

The required coefficients are set by sequentially polling the program memory. At the end of the program, the frequency of the note and the duration of the sound are set. To avoid operations with 16-bit data, separate processing of 8-bit data is organized (operations with a double-byte word are intended for further modernization of the program). After playing the last note, the microcontroller goes into sleep mode.

The ringing melody is limited to the range of notes from "C" to "B". You can program any scale - there is plenty of free space at the end of the program for this. You can change the order of reading the notes and get an interesting melody.

The assembly code for the program is shown in Listing 5.1, and the hexadecimal code is shown in Listing 5.2.


Please note that the note duration table and note frequency can only be read using the microcontroller's LPM command. This command in the ATtinyl5 version is essentially the only one that performs the functions of indirectly reading data from memory into the R0 register. In addition, there is a stack limit at the bottom level. A stack supports a maximum of three attachments. The author tested stack nesting at level 3 in the AVR Studio 4 simulator and found that the program crashed because the conditional branch instructions also use the stack. The program loses functionality and consistency. Taking into account these comments, the original “firmware” is small in size (for the Tiny 15 microcontroller), but has been tested and is quite functional.

At the end of playing the melody, the microcontroller goes into sleep mode regardless of the power supply to the circuit.

The board is made of double-sided PCB, or breadboard. The installation diagram is shown in Fig. 5.2, and the wiring diagram is in Fig. 5.3.

Connects to connector SL1 mains voltage 220 V. The S1 button can be installed on the board or placed in the stairwell. You can use a ready-made button, instead of the button on the board we install a jumper, and use the power supply for the bell according to the previous scheme (power supply interruption via the network wire). It is possible to connect to a home bell in parallel with the solenoid (in this case, instead of a button on the board, we install a jumper).


We mount the board and secure it in the bell body. The SZ capacitor is rarely found on sale, so it can be replaced with a set of capacitors soldered in parallel (i.e., together). Zener diode D1 D815G is in a metal case for better cooling, since at the moment of network surges it consumes and dissipates significant current into heat. Diode D2 - any for a reverse voltage of 300 V and a current of at least 0.2 A. Piezo emitter - any type for a voltage of 3-5 V. LED1 LED - any for a current of YumA or less. Resistors R1 and R2 - 1 W MLT-1. Capacitors C5 and R6 for most microcontrollers do not need to be installed (these elements are not included on the circuit board), however, if it is impossible to run the program, they must be soldered by surface mounting.

Setting up the scheme

To check the circuit, +9 V power (“plus” to the cathode D1, “minus” to ground) can be supplied from an independent source to the zener diode D1. The melody starts playing immediately when the power is connected.

You can check the circuit when powered from the mains without a microcontroller. To do this, you need to connect a load to the output of IC2. As a load, you can use a resistor with a nominal value of 300 Ohms and a power of 1 W. If you turn off the circuit before the supply voltage builds up, you can double the value of resistor R5 or install an additional 1000 pF (10 V) capacitor in parallel with R5 (selected experimentally).

If the melody has a low-frequency tone, then the microcontroller used is set to an internal clock frequency of 1 MHz. You can increase the tonality by adding a 4 MHz quartz resonator and 100 pF correction capacitors to pins 2 and 3 of the microcontroller (RV2, RVZ). If the program starts unstable, it is necessary to install capacitors C5, R6.

In the future, the circuit can be supplemented with a photosensor to adjust the sound level at night, as well as a door opening sensor to turn off the melody when the door is opened or when the light in the hallway is turned on (S2). The remaining pins of the microcontroller can be used to implement polyphonic musical accompaniment by connecting two more piezo emitters. These functions are not implemented in the program.

Memory music ringer on PIC16F84

Sometimes you want to know: “Didn’t the doorbell ring when no one was home?” The proposed musical bell, which has a special memory function, will help with this. It was made on a microcontroller of the popular R/S family. The result was an extremely simple device capable of playing several dozen melodies and remembering the last press of the bell button if the door was not opened in time.

The principle of operation of this device is as follows: if the front door is not opened within three minutes from the moment the bell button is pressed, then the next time it is opened, one of the programmed melodies will be played. In other words, by opening the door and hearing this melody, you will understand that someone I called in your absence. Otherwise, its operation is no different from a regular musical bell.

In the described embodiment, the device plays 16 melodies, which are selected randomly. By changing the control program codes, you can replace ib melodies with any others, as well as change their number and playing time.

The circuit diagram of the call is shown in Fig. 1. Its basis is the DD1 microcontroller (PIC16F84-04I/P from Microchip). The clock frequency is set by the ZQ1 quartz resonator. Signal 34 is removed from pin 7 (RB1) of the microcontroller, amplified by transistor VT1 and reproduced by dynamic head BA1.

The bell button SB1 and the door opening sensor SF1 are connected to the microcontroller pins through current-limiting resistors R3, R5. Capacitors C5 and C6 prevent spontaneous operation of the bell due to interference created by electrical appliances.

The device is powered from an alternating current network through a step-down transformer T1. The voltage of the secondary winding is rectified by the diode bridge VD1. DC voltage stabilizes integral stabilizer DA 1.

Drawing printed circuit board and the location of parts on it are shown in Fig. 2. The board is designed to accept MLT resistors. capacitors K50-35 (C1, C2) and KM (rest).

Diode bridge VD1 - KTs405 with any letter index. Quartz resonator ZQ1 - at a frequency of 4 MHz. Capacitors C3, C4 - any ceramic with a capacity of 15...33 pF. Transistor VT1 - any of the KT815 series. The resistance of resistor R1 should be no more than 40 kOhm.

Any transformer that provides a voltage of 9...10 V on the secondary winding at a current of 0.3 A is suitable as T1. In the author’s version, the TS-Sh-ZM1 transformer is used. in which the number of turns of the secondary winding is reduced by 90.

Button SB1 is a regular button for a doorbell, door opening sensor SF1 is a reed switch. fixed to the door frame. A magnet is installed on the door itself. When the door is closed, the reed switch closes under the influence of a magnet, and when opened, it opens. The sensor can be of any design.

Program listing:

(click to enlarge)

To replace melodies, let's get acquainted with the principle of placing them in the microcontroller memory. They are located in program memory in the address range from 200H to 3FFH. One note occupies one machine word in memory. Each melody must end with the code 07Н. M_RAND mask. located at addresses 0079Н and 0085Н. determines the number of melodies and. accordingly, the maximum number of notes in the melody (Table 2).

So, if the mask is F8H (32 melodies of 15 notes each), then the first melody will occupy addresses 200H-20FH. second -210H-21FH.....32nd - 3F0H-3FFH. Obviously, each of them takes up 16 machine words, and the maximum number of notes in a melody is 15 (one machine word is allocated to code 07N).

It should be noted: if there is no code 07Н at the end of the melody. then the next one will be played without stopping, etc. until then. until this code is encountered. In this case (16 melodies of 31 notes), the first melody occupies addresses 200H-21FH. the second -220H-23FH, etc. The actual number of notes (from 1 to 31) depends on where the code 07H is placed. Note codes depending on their duration and belonging to a particular octave are presented in table. 3.

(click to enlarge)

To preview melodies, you can use the music.exe program.

The Wait_D constant is located at address 008ВН. determining the waiting time for the door to open. This time (in seconds) is approximately equal to Wait_D-2. In our case, the constant is 5AN (in decimal system- 90) and the waiting time is 90 · 2 = 180 s = 3 min.

To change the program, you need to load the ring.hex file into a hexadecimal editor (usually it is built into software programmer) and edit, taking into account that the machine word of the PIC16F84 microcontroller is 14 bits long and represented by a four-bit hexadecimal number. Only the two least significant digits need to be replaced, since the most significant ones represent the instruction code. For example, in memory at address 208H there is the number 3483H, but you need to write the code 07H. Changing only the low-order digits, we get the number 3407Н.

It is also possible to make changes directly to the source text of the program (nng.asm file). To do this, you need to create a Ring folder in the root directory of any disk, place the files nng.asm, ring.pjt and ring.lkr there. Then, in the MPLAB v4.12 environment, open the ring.pjt project and the ring.asm file. which needs to be edited. Next, they start building the project and get a new ring.hex file.

Timers refer to a fairly wide range of different technical devices as well as internal components of microcontrollers. In this case, a timer is a digital device designed to turn on and off an external device according to a given program. This could be, for example, an automatic plant watering device or an automatic feeding device aquarium fish.. It all depends on your imagination. For example, I once for a long time I used a similar device to periodically turn on/off a refrigerator whose mechanical thermostat had broken.

The timer is assembled on a very common and cheap microcontroller from Microchip, 8-bit PICF628A.The user can program the interval between turning on the external device and the duration of its operation. the maximum pause and start time is 9 9 hours 59 minutes, that is, actually 100 hours.

To control the timer, four buttons are used, and to display information, a standard LCD indicator with 2 lines of 16 characters is used, operating on the basis of the HD44780U controller from the company Hitachi.


An electromagnetic relay is used to control an external device. The relay winding must be designed for voltage 5 V . The microcontroller controls the relay through a transistor switchPN2222. Relay contacts must be rated for the current consumed by the controlled device. Control buttons are connected to the microcontroller ports RB0, RA2, RA3 and RA4.

The display operates in four-bit mode and requires 6 microcontroller ports to control it. For sound signal A piezoceramic bell is used to switch the load on and off. A sound signal also sounds when the timer is turned on.

The timer power supply contains a voltage stabilizer +5 V on a microcircuit - regulatorLM7805.To power the timer from a 220 volt network, you can use any unstabilized network adapter, purchased from the Chinese market. Output voltage The adapter can be in the range of 9 - 14 volts.


If we look closely at the device diagram, we will notice that the indicator pins numbered 15 and 16 are not used. they are connected only in indicators with backlighting. if you want to use a backlit indicator, then connect it to +5 B through a 39 ohm resistor.

In the proposed call, an SD or MMS memory card formatted for the FAT16 file system is used to store melodies or voice messages. Are being reproduced sound files WAV format. In addition to making calls, the device can be used as a player for such files.

The device (Fig. 1) is assembled on the widely used PIC16F628A microcontroller and has two operating modes, which are set with switch SA1. The top position of its contacts in the diagram corresponds to the “Player” mode, and the bottom position corresponds to the “Call” mode. The microcontroller checks the state of the switch contacts only once, immediately after turning on the power. Therefore, to change the mode, you must turn off the power, set the switch to the required position and then turn on the power again.

In the "Call" mode, after turning on, the DD1 microcontroller configures the internal registers, after which it goes into sleep mode. When you press the SB1 button ("Call/Play"), the microcontroller "wakes up", as evidenced by the HL1 LED turning on, supplies power to the memory card, initializes it and searches for a sound file. The search is carried out by WAV extension. Having found it, the microcontroller plays the file, turns off the power to the memory card, after which it “falls asleep” again, and the HL1 LED goes out. The next time you press the SB1 button, everything will repeat, but the next sound file will be played. Up to 512 melodies or messages can be recorded on a memory card - this is the maximum number of entries in the root directory for the FAT16 file system. After playing all the melodies, they will start playing again. Buttons SB2, SB3 and SB4 are not used in this mode.

In the “Player” mode, after power is applied, the microcontroller also configures internal registers, turns on the power to the memory card, carries out its initialization procedure, and if successful, the HL1 LED flashes. It then searches for the WAV file, and when it is found, the microcontroller will proceed to poll the state of the contacts of all buttons. When you press the SB1 button, continuous sequential playback of all sound files on the memory card will begin. By pressing the SB2 (“Stop”) button you can stop playing the current melody, and the SB3 (“Next”) and SB4 (“Previous”) buttons switch files, which is possible both during playback and after stopping playback. If the memory card initialization procedure fails, the microcontroller will make another attempt, and if this is also unsuccessful, two short low-tone beeps will sound, after which the microcontroller will stop responding to commands.

In the "Call" mode, if there is an initialization error, two short low-tone signals will also sound, after which the microcontroller will turn off the power to the card and go into sleep mode. If the memory card stops responding to commands or simply freezes, in the “Player” mode the microcontroller will first turn off, then turn on the card’s power and reinitialize it. In the "Call" mode, after the card freezes, the microcontroller will simply turn off the power to the card and go to sleep. If there are no WAV files on the memory card, three short low-tone signals will sound, after which, in the “Player” mode, the device will proceed to polling the state of the button contacts, when pressed the same warning signal will sound. In the "Call" mode, after a signal about the absence of WAV files, the microcontroller will turn off the power to the memory card and go into sleep mode. If the WAV file parameters do not meet the required values, for example, incorrect sample rate, bit depth, etc., a low tone will sound for one second and in both modes it will move to the next file.

To match the logical levels of the microcontroller and memory card signals, voltage dividers are installed on resistors R7, R8, R10, R13-R15. The sound signal is generated using a PWM module built into the microcontroller, the operating frequency of which in this device is 78.12 kHz. The generated signal is smoothed by the filter R12C10 and from the volume control R17 goes to the ultrasonic sounder assembled on the DA2 TDA2003 chip.

The device is powered by an external power supply with a voltage of 9... 12 V. The microcontroller's power supply is stabilized by an integrated stabilizer DA1 with an output voltage of 5 V. A 3.3 V voltage stabilizer is assembled on transistor VT1 to power the memory card. It is controlled by a microcontroller via port RA3 lines. At a low logic level on this line, transistor VT1 is closed, the voltage at its emitter is zero. At high level the transistor is open and the supply voltage is supplied to the memory card. The voltage at the base of the transistor is stabilized by a zener diode VD1.

The device plays audio files in WAV format (PCM, 16 kHz, 8 bit, mono); files with other parameters will not be played. Therefore, if necessary, the selected sound files are converted using a converter program (the file names can be anything) before recording on the memory card. The FAT16 file system is not suitable for storage media larger than 2 GB, so this maximum volume for a memory card that can be used in the device. Four microSD cards of different companies and sizes were tested: Kingston (1 GB), Kingmax (512 MB), Silicon Power (2 GB), Transcend (1GB). MMS cards should also work, but I could not test this due to their absence.

The device uses fixed resistors MLT, variable resistors SPZ-4aM, SPO, SP4-1, oxide capacitors are imported, the rest are ceramic K10-17. The switch is PD9-2, the buttons are TS-A3PS-130, but other similar ones will do. The KS139A zener diode can be replaced with an imported one with a stabilization voltage of 3.9 V, for example 1N4730. Instead of the KT503V transistor, you can use any of the KT3102 series, and the AL307BM LED can also be used in any plastic case with a diameter of 5 mm. The microcontroller is installed in the panel. The TDA2003 ultrasonic device can be replaced with a TDA2002, TDA2008, K174UN14 microcircuit; it must be installed on a heat sink with an area of ​​at least 60 cm2. Dynamic head - any broadband with a power of 2...4 W with a coil resistance of 4...8 Ohms. The memory card slot is homemade, since it was not possible to find a ready-made one. It is made of one-sided foil fiberglass and copper foil. A printed circuit board measuring 35x40 mm is made of fiberglass, on which seven contact pads are made. Spring contacts from the faulty microSD connector are soldered to the pads cell phone. A U-shaped guide is cut along the contour of the memory card, which is fixed to the board. Copper foil is soldered on top of the guide, which presses the card to the spring contacts

Rice. 2. Printed circuit board

The external bell button duplicates SB1. With a long connecting wire, to eliminate the influence of interference, it is recommended to install a capacitor with a capacity of 0.1 ... 10 μF, and it is advisable to use a shielded wire itself (the screen is connected to a common wire). Elements R19 and C13 are installed in the case of self-excitation of the ultrasonic sounder at a high frequency. Power source - unstabilized mains power supply with output voltage 9... 12 V and current up to 0.5 A.

Most of the elements are installed on a single-sided printed circuit board made of foil fiberglass, a drawing of which is shown in Fig. 2. The appearance of the mounted board with a connected memory card is shown in Fig. 3.

The program for the microcontroller is written in assembler in the MPLAB environment. Programming was carried out using the IC-Prog 1.05D program and the JDM programmer described in the magazine "Radio", 2004, No. 2, p. 51 (A. Dolgiy. “Programmers and programming of microcontrollers”).

Currently on sale you can find a variety of calls to suit every taste, both musical, providing a choice of up to two dozen melodies, and ordinary ones, without bells and whistles, which only perform the main function of signaling that someone has arrived. Is it possible to assemble a musical bell yourself? Of course you can, and in this article we will look at how to put together such a call. The ringer circuit is quite simple, and contains only 6 parts, not counting the buttons for turning on the melody playback and the button for changing the melody. The microcircuit has been produced since the nineties of the last century and is probably familiar to many radio amateurs.

The diagram shows the UMS-7 microcircuit, but using this diagram you can safely assemble a call using the UMS-8 microcircuit; they have the same pinout, but there are slight differences in the supply voltage. In the following picture you can see appearance microcircuits, in a standard Dip package, 14 legs:

The device I assembled has 2 buttons - Play And Choice . It looks like this:

Homemade musical bell

button Play (SA1), if you decide to assemble it for the purpose of using it as an apartment bell, you need to duplicate it (connect two buttons in parallel) and bring the second one out from the outside front door. While the melody is playing, press the button Choice (SA2), you can change the playing melody. The bell circuit is quite economical and allows you to power the device from two AA or AAA batteries. To easily replace batteries, I used the standard factory compartment for 2 batteries.

The sound volume is enough to signal that someone is coming to you. The circuit uses quartz at 32768 Hz. I remember meeting similar ones on old motherboards. I also give my version of the bell circuit board:

If anyone wants to use my version of the printed circuit board for the sprint layout program, at the end of the article it will be possible to download it from the link. When outputting the board to a printer, we use direct printing. Microcircuits usually contain 2-3 melodies, some additionally have a sound signal, similar to an electronic alarm clock. The exception is the UMS-8-08 microcircuit, it contains 8 melodies. You can see the list of melodies in the following figure:

I will also give a variant of the circuit with a button to stop the sound of the melody:

KT315 can be replaced with another low-power transistor n-p-n structures, for example, on KT3102. The speaker, as an experiment, was connected with a power of 2 watts, it sounded normal. I stopped, primarily because of the size of the device with a 0.5 Watt, 8 Ohm speaker, which I installed in the bell. The ringer volume, when using a speaker with a resistance of 4 ohms, will be slightly higher. I will give another version of the microcircuit connection diagram:

This circuit also provides a button to stop the sound. For beginners who have little experience in soldering, in order not to overheat the microcircuit during soldering, I recommend soldering a socket into the board, and inserting the microcircuit into this socket. There is an additional advantage here: if the melodies get boring, the microcircuit can be easily replaced with another one, with a different number, and the set of melodies will also change accordingly. The author of the article is AKV.



If you find an error, please select a piece of text and press Ctrl+Enter.