A simple GSM security device on PIC16F628A with a Touch Memory electronic key. The simplest electronic clock on PIC16F628A with detailed source code. Peak alarm clock pic16f628a

Description of the original scheme.

Modification of the device for arming and disarming the alarm using a key -Touch Memory

DEVICE DESCRIPTION

The device is designed for security and monitoring of remote objects. It is assembled on a PIC16F628A microcontroller, which counts the required time intervals and controls the mobile phone using AT commands. In addition, there is a dial-up function telephone numbers from the list (no more than 3) recorded in the PIC’s EEPROM and the ability to send SMS. The device is very simple to manufacture and set up.
The design is not our own - the circuit diagram, firmware and configuration program were taken from the Internet.

The device operates as follows: after turning on the power, the level at RA5 is checked. If the “write configuration” switch is closed, the microcontroller goes into parameter setting mode and waits for information to arrive from the PC.

In the case of working with a telephone, the telephone will be initialized (commands ATE0, AT+CMGF=0, AT+CNMI=1,1,0,0,1) and after a time delay (configurable) the device will go into standby mode - it will control the logical levels on “Input1” - “Input4”. If they do not match the values ​​​​previously recorded in the EEPROM, an SMS can be sent, dialing, or turning on external signaling devices (siren, light, etc.). After this, during the time determined by the “recovery time” parameter, the microcontroller will not respond to changes in the sensor state. This time can be set between 10 seconds. up to 2540 sec. (about 40 min). In addition, it is possible to configure time delays: before the dialing procedure and sending SMS, turning on signals 1 and 2 (0-255 s).

The author of the original circuit included the ability to determine the state of all four sensors at any time. To do this, send a message with the text “stat” to the number SIM cards mobile phone used as part of GSM alarm. In practice, this did not work out for me. To reset the device, it is possible to use the text “rst” in the SMS.

LED1 and LED2 are used to display the operating mode. When operating in security mode (main mode), LED D2 flashes once every 4 seconds. Both illuminated LEDs indicate readiness to write the configuration from the computer. Both non-blinking LEDs indicate data corruption in the EEPROM (incorrect device configuration). Flashes of LED2 with a period of 0.5 seconds indicate an attempt to transmit AT commands after turning on to configure the mobile phone. A flashing LED1 indicates that the power supply has not yet passed. set time. LED2 lights continuously when the controller interacts with the phone (trying to call and sending SMS).

In the original circuit, zener diodes D3-D6 protect the inputs of the microcircuit from exceeding the permissible voltage level. Due to the peculiarities of the microcontroller pins, I did not follow the original diagram, using dividers on resistors.

Both for communication with the phone and for communication with the computer when setting parameters, the “data rx” (PIC pin 7) and “data tx” (PIC pin 8) lines are used. The port speed is 19200 bps. The microcontroller supply voltage is the nominal supply voltage of a mobile phone (up to 4V). In principle, in several copies tested by the author, the device worked normally even from two discharged NiCd batteries (voltage about 2V). Connector diagrams for mobile phones can be found, for example, on the website www.pinouts.ru. As an example, we give the pinout of the connector for Siemens phone S35, with which this device works. We need only three contacts - (GND) connects to the "-" power supply, (DATA OUT) - connects to the "GSM TX" device, (DATA IN) to the "GSM RX". There may be some confusion in the concepts of “RT, TX”. If the connection fails, I recommend mutually replacing the RT and TX lines, this is not at all scary.

I connected these lines to mobile phone through a 1KΩ resistor. In some phone models, which operate via USB by default, you must additionally short-circuit a certain pin of the connector to switch the interface to operating mode via the COM port. To connect to a computer, an RS-232 to TTL level converter is required. I always use 2 elementary KT315 for these purposes, although you can use a MAX232 or similar chip. I did not build a printed circuit board, due to the elementary nature of the circuit, I placed all the components on the circuit board, with connections on the reverse side using ordinary wires.

The following are connected to the “Input” connector: 3 inputs of controlled parameters (in the original there were 4, I connected the 4th one to external power supply), housing, power supply (12V), input for blocking the operation of the PIC controller - during the disarming period it was necessary to block the operation of the PIC. Due to the very low current consumption of the PIR controller, its operation was maintained even from power supply via the DataRX and DataTX buses. I used an AOT 101AC optocoupler, which with its output simply short-circuited the quartz output, stopping generation and thereby blocking the operation of the MK. The author used a WDT (watchdog timer) in the microcontroller firmware; thanks to this, the operation of the microprocessor was restored when the quartz leg was “released”, and the microcontroller program began to be executed all over again. I didn’t look for any other way to stop work. When +12V is supplied to the “LOCK” pin, the operation of the microprocessor stops.
The remaining parameters must be configured in the configuration program.

Slightly modified and a modified version of the secret police was proposed by forum member Maratt from the forum of the original source site. The essence of the change is to improve the service quality of the ic develop security device, the author of which does not answer questions. If we can't change the program, we'll try to improve the hardware.

There is only one firmware version for the PIC16F628A controller, since the author did not publish the source code. If the phone does not behave as described, you need to deal with the phone. The left side of the diagram remains unchanged.

Now about the right side.

A project “car guard with an electronic key reader type DS1990A” was found on the network and simply added to the diagram.

The PIC12F675 controller provides reading the code of Touch Memory electronic keys type DS1990A from Dallas Semiconductor, comparing the read key with the information stored in memory, and issuing a control signal.

The serial number is read by briefly touching the electronic key to the controller's reading device. The controller is equipped with light indication of operating modes.

The number of keys stored in memory is no more than 20. The controller is clocked from an internal clock generator with a frequency of 4 MHz

The “Mode” LED is connected to the GPIO5 port (pin 2) of the microcontroller, indicating the operation of the controller electronic lock. Resistor R1 sets the current flowing through the LED.

An electronic key reader is connected to the GPIO4 port (pin 3) of the microcontroller. As already mentioned, the exchange of data and commands between the D1 microcontroller and the electronic key connected to the reader occurs using a single-wire 1-Wire interface. The 4.7K resistor is a load resistor for the 1-Wire interface line (Regular braided solid wire). A 150 ohm resistor and a 4V7 zener diode protect the microcontroller port from increased voltage (static and any other).

The Prog key button is connected to the GPIO3 port (pin 4) of the microcontroller. By pressing this button, the key is written to the microcontroller’s memory, as well as all keys are erased. The 4.7K resistor generates a high level voltage at pin 4 of the microcontroller. And by pressing the Prog button, a low level voltage is generated.

The GPIO2 port (pin 5) of the microcontroller changes its state depending on the mode (disarmed -1, armed -0)

To record the first or subsequent keys, after turning on the power, touch the reader with the electronic key and press the Prog key button. After four short flashes of the “Mode” LED, the serial number will be stored in the microcontroller’s memory. If the microcontroller memory is completely full, this will be indicated by four light signals. The LED flashes will be slower than when writing the key to the microcontroller memory.

To erase all the keys stored in the memory at once, you need to turn off the power to the electronic lock controller, press the button and apply power to the device, holding the button for about 4 - 6 seconds, until a series of short flashes of the “Mode” LED appear. The number of LED flashes is determined by the number of electronic keys stored in the memory (there will be four short LED flashes to erase each key). After this, you can release the button and the device will return to normal operation. But before use it is necessary to write into the microcontroller memory serial number at least one key.

Description of work

When power is applied, the controller, after initialization, enters the mode of checking the connection of the electronic key. The “Mode” LED begins to blink after turning on the power, indicating that the device is in security mode; the controller output has a low log level that does not affect the operation of the generator. When you touch the controller reader with an electronic key, the serial number of which is stored in the microcontroller’s memory, the LED will blink twice. A high level will appear at the controller output, which will block the operation of the generator. The “Mode” LED will be constantly lit, indicating that the mode is disarmed.

When you touch the reader's electronic key again, the system will be armed and the LED will go into flashing mode.

Attention! After turning off the power, the device goes into security mode!

My version of the secret police:

Of course, when repeating this scheme, you always encounter pitfalls. I had them too. To begin with, I decided on what scheme I would use to assemble the secret police and I was right - the diagram and signet with an additional power board turned out to be a very practical design.

Security device diagram:

Rice. 1 — Schematic diagram of a simple GSM security device on PIC16F628A with electronic key Touch Memory type

Power and alarm device for a simple security device.

Power supply diagram for a security device:

Rice. 2 - SCHEME circuit diagram power supply for security device

Connects to the contacts of connector X1 secondary winding network transformer. There should be a voltage of 16-18V at the contacts of connector X2.

Connectors X2 and X3 are intended for connecting a node (highlighted in red) which includes:

1. Charger,

2.12V battery.

3. Battery protection device from complete discharge.

When installing a security device in a place where there is no mains voltage, a charged battery is connected to connector X3.

Transistor VT1 contains a key for switching a 12-volt audio alarm-buzzer with a built-in generator connected to connector X5. The signal output of the same name is connected to connector X4 (Signal1). For a more powerful device, for example an autonomous siren, a relay can be connected to connector X5, which will switch this device.

Transistor VT2 contains a key for switching a built-in (soldered onto the board) or remote buzzer (connected to connector X8) with a supply voltage of 5V. Connector X6 (Signal2) is connected to the signaling output of the same name. The Signal3 input (X7 connector) can be connected to pin 6 of the PIC12F675 or used at your discretion.

The VR1 chip contains a voltage stabilizer with an output voltage of 3.0V. We connect the signal power input to its output X9. At this voltage, the PIC16F628A and PIC12F675 controllers operate stably, and the RX TX signals are level-matched with the phone or modem.

The VR2 chip contains a voltage stabilizer with an output voltage of 4.2V. To the output of which a modem or telephone is connected. This is the nominal supply voltage of the SIM300D module. To power the phone, you need to reduce this voltage to 3.7V by reducing the resistance of the resistor to 560*. At the output of the stabilizer there is a voltage divider, the middle point of which is connected to connector X10. The divider simulates the signal from the battery thermistor cell phone. When connecting contacts X10 instead of a battery, the phone will operate from a stabilizer. Some phone models may require selection of divider resistors.

I will not show the manufacture of the printed circuit board, since this is already trivial, I will immediately show the result of the work.

With installation of parts:

Fig. 3 - Do-it-yourself GSM alarm board - with installation of parts, front and back.

Rice. 4 — Reverse side of the GSM alarm board

Complete power supply for alarm:

Rice. 5 - Finished board power supply from parts side

Rice. 6 - Power supply board on the reverse side

I didn’t get too sophisticated and used a case from a computer power supply. The housing with a built-in transformer can be seen in the figures below:


Not shown here, but to the left of the power socket, a terminal strip was screwed using bolts and nuts.



Rice. 7 — device body.

To close the hole from the cooler, I cut out a shaped piece from the chipboard and mounted a pressure ring from the transistor on it - a “reader” for the electronic key. I installed a couple of LEDs to visually monitor the operation of the device.

Rice. 8 — Part of the device body covering the hole from the fan.

I glued the cut piece of chipboard using hot glue. I brought out a terminal block on the back panel of the iron case and connected the sensor and siren terminals to it. Power is supplied to the transformer via a standard cable from the power supply.

Siemens A60 phone connected via a standard connector

Fig. 9 - Mobile plug

Plug pinout matches any x55/x60/x65. There are two exceptions so far - ST55/ST60.

1 - +U
2 - Gnd
3 - Tx
4 - Rx
5 - CTS
6 - RTS
7 - DCD
8 - left sound
9 - general sound
10 - right sound
11 - microphone ground
12 - microphone

In accordance with the pinout, it is necessary to solder the wires to the board and power supply.

Rice. 10 — Connection of two boards (power supply and GSM alarm)

Everything was then set up and placed into the case. The device was installed to protect a country house. In order to exclude the possibility of an intruder disabling the alarm, I used an old uninterruptible power supply. This made it possible to solve the problem of the device operating in the absence of mains power. I used reed switches and a glass break sensor as sensors.

Rice. 11 — RS-232 to TTL level converter (transistor-transistor logic)

The finished device looks like this:



Rice. 12 - Level converter RS-232 - TTL on transistors

Actually the conclusions from the box are: general, RX, TX, and a single (milky) wire from the box — «+».

Very important!! — After assembling the device, configure it using the program!

Now a few words about setting up the device.

To set the controller parameters from a PC, the author wrote a simple program. When operating in programming mode, the configuration is written to the microcontroller's memory. You can also use a configuration file to create a binary EEPROM image, which is then written into the chip using a programmer.

To record parameters, an RS-232 - TTL level converter on a transistor is used. We connect the converter to COM port computer, RX and TX pins to the board respectively (RX-7 leg of the microcontroller, TX - 8 leg of the microcontroller), we connect the common wire of the converter to the common track of the board. We supply +5V through resistors to the converter, as shown in Fig. 11, from the power supply.

To record parameters to the microcontroller, before applying power to the entire security device, additionally press the button near the microcontroller; it is responsible for starting recording. Keep pressed during the entire process of recording parameters through the program. The recording process is fast enough, your finger won’t get tired 😉

We connect the power supply to the security board. Opens the program, select the port, click “RECORD” - done.

You should register parameters in the appropriate program windows before you decide to program them, because it will be difficult to hold down the programming button with one finger while dialing phones with the other, changing operating hours, etc.

If anyone doesn’t know, “Parameters” are the phone numbers to which the alarm will ring, as well as the siren operating time and call duration, etc. Everything in the program is signed and intuitive.

Rice. 13 — Program interface for flashing the configuration into the controller.

Implementation options:

Alarm housing option. The case used is for machine guns. Very convenient and practical design. Everything you need fit inside.

There are enough mounting holes on the back to mount the alarm on any surface.

Inside the shield you can see that everything fits very well. As for the power supply board, there is none. Everything is powered by a 5 volt power supply from the charger.

Well, here is the general view of the alarm - the front side.

Download PCB:

Printed circuit board in.lay and description for GSM alarm system with key reader -

Clock with a small 4-digit indicator. The dot between hours and minutes flashes at a frequency of 0.5 seconds. Can be built into any object: a desk calendar, a radio, a car. Estimated error – 0.00002%. In practice, for six months there was never a need for correction.

Power supply 4.5 - 5 volts, current up to 70mA. The voltage stabilizer is located in the adapter plug. It is assembled on a 3-watt transformer and a high-frequency converter - stabilizer according to a standard circuit. For a car, of course, a transformer is not needed. The microcircuit does not heat up without a heatsink. Connector for 3.5mm power supply. Quartz 4 MHz. Any low-power n-p-n transistors.

Any buttons . The length of the button pusher is selected based on the design requirements. You can also solder buttons on the conductor side. Each time you press the button, a unit is added. When held, the count speeds up to a reasonable speed.

Resistors MLT – 0.25. R7 – R14 300 – 360 Ohm. R3 – R6 1-3 kOhm.
Batteries: 4 pieces of GP-170, or similar. When the mains voltage is turned off, they only supply power to the microcontroller. They hold up for 8 days exactly, I checked.
Diodes with the lowest voltage drop in the forward direction.

The boards are made of one-sided foil fiberglass.

Before installing the microcontroller into the panel of the manufactured board, turn on the power and measure the voltage on the 14th leg of the socket. It should be 4.5 - 4.8 volts. On the 5th leg 0 volts. If you are not sure about the quality of the manufactured board or the serviceability of the parts, check the device without a microcontroller. This is done very simply:

  • Insert a jumper from the bare wire into the socket, terminals 1 and 14. This means that +4.5 volts from the first leg will open transistor VT 2 through a resistor and the cathode of the clock unit indicator will be connected to zero.
  • Connect any wire with one end to +, and with the other end alternately touch terminals 6,7,8,9,10,11,12,13 of the socket.
  • At the same time, observe the lighting segments and their correspondence to the diagram: + on the 6th leg – segment “g” is lit and so on.
  • Move the jumper to terminals 2 and 14 of the socket. Check all segments of the minutes unit indicator.
  • Jumpers 18 and 14 – tens of hours are checked, 17 and 14 – tens of minutes.

If something doesn't work correctly, fix it. If everything is correct, program the microcontroller and insert it into the socket with the power off.
HEX file is attached.
Turn on the power and get a ready-made watch.

If you buy all the parts, including resistors, then, according to my diagram, the device will cost about 400 rubles:

  • PIC16F628A – 22.8 UAH
  • LM2575T-5.0 – 10 UAH
  • FYQ 3641AS21 - 9.3 UAH
  • Panel – 3 UAH
  • Quartz – 1.5 UAH

Literature:

  • Pic microcontrollers. Everything you need to know. Sid Katzen.2008
  • PIC microcontrollers. Architecture and programming. Michael Predko. 2010
  • Pic microcontrollers. Application practice. Christian Tavernier.2004
  • Development of embedded systems using PIC microcontrollers. Tim Wilmshurst. 2008
  • Data sheet: PIC16F628A, FYQ 3641, LM2575.
  • Tutorial on programming PIC controllers for beginners. Evgeny Korabelnikov. 2008

Below you can download the firmware and PCB in LAY format

List of radioelements

Designation Type Denomination

Shop

MK PIC 8-bit

PIC16F628A

1
Search in store
VR2 DC/DC pulse converter

LM2575

1 5VSearch in store
VT1-VT4 Bipolar transistor

KT315A

4
Search in store
VD1, VD3, VD4 Diode

D310

3
Search in store
VD2 Schottky diode

1N5819

1
Search in store
VD5 Diode bridge

DB157

1
Search in store
C1, C2 Capacitor20 pF2
Search in store
C3 Capacitor0.1 µF1
Search in store
C4 330 µF 16 V1
Search in store
C5 Electrolytic capacitor100 µF 35 V1
Search in store
R1, R2 Resistor

10 kOhm

2
Search in store
R3-R6 Resistor

1.5 kOhm

4
Search in store
R7-R9, R11-R14 Resistor

300 Ohm

7
Search in store
R10 Resistor

360 Ohm

1

This device is a standard Digital Watch with an alarm clock, but they are controlled from the remote control remote control on IR rays. The clock is implemented in software, the display is dynamic. The circuit provides backup power in case of power outage. The alarm clock is implemented on a simple buzzer with a built-in generator - buzzer.

The control panel is implemented on a PIC12F629 microcontroller. The remote control is powered by regular battery For motherboard computers. If none of the buttons are pressed, the microcontroller is in SLEEP mode and consumes virtually no current. As soon as the button is pressed, the microcontroller “wakes up” and generates a code message to the IR LED.


When the power is turned on, the display shows the current time and the colon blinks. If you press the CLOCK button, the display will show the time for which the alarm is set (the colon does not blink), or --:-- if the alarm is turned off. Pressing the CLOCK button again, or after 6 seconds, the device will again display the current time. Pressing the COR button puts the device into clock correction mode if this moment the clock is displayed; or into alarm setting mode if an alarm is shown on the display. The first press - the hours blink, the +1 button sets the hours, the second press of the COR button - the minutes blink - the +1 button sets the minutes, the third press - exits the clock (or alarm) correction mode. If the alarm time is adjusted, it turns on automatically.

When the display indicates the alarm setting time (turned on by the CLOCK button) - pressing the +1 button turns on and pressing again turns off the alarm, the display, accordingly, shows the alarm setting time or --:-- (the colon does not flash). If the alarm is turned off, its setting time is not reset.

In the clock indication mode (the colon is blinking) - pressing the +1 button switches the clock to the “night” mode - in this mode the indicator goes out completely and only the colon blinks, which reduces power consumption and does not create unnecessary night illumination. At the same time, pressing any button on the remote control, as well as triggering it, takes the clock out of night mode.

If the alarm goes off, a beep sounds for one minute, all numbers on the display flash. Pressing any button on the remote control turns off the alarm (without resetting its setting time).

For backup power supply of the clock, as well as in the control panel, a battery from the computer motherboard is used. Its voltage is 3V, so the microcontroller in the clock needs to be used low-voltage - PIC16LF628A. If you use a battery with a voltage of more than 3.6V, then a regular PIC16F628A will do. Well, a completely ideal option is to use a microcontroller with NANOWATT technology - PIC16F819 (Attention! This microcontroller uses different firmware).


These electronic watches are the simplest. They were assembled in a few hours. The basis is a PIC16F628A microcontroller, in addition to it, the clock contains several simple and cheap elements, the information is displayed on a 4-bit (clock) led indicator. The circuit is powered from the mains and also has a backup power supply. This design can be recommended for beginners; I specifically provided the original program with detailed comments to make it easier to understand what and how it works.

The circuit is very simple, simple and the algorithm of their work (see comments in the source). Buttons kn1 and kn2 are used to correct the time - hours and minutes, respectively. The clock has a 24 hour display format. In the 1st digit of the clock, an insignificant zero has been suppressed. The accuracy of the clock depends entirely on the frequency of the quartz resonator. But even without special selections of quartz and capacitors in the clock generator, the clock runs very accurately.

The clock is assembled into 2 printed circuit boards, docked one to one at an angle of 90 degrees. The entire indicator is placed on one board, and everything else is on the other. The backup battery was broken from a Chinese lighter with LED flashlight. We remove the LED and install the battery holder on the board. The photo shows that cut-off resistor leads are connected to the batteries - they hold this entire structure. Of course, the capacity of such batteries is small, but when the watch is powered from the mains, no current is consumed from the batteries. They power the circuit only if there is no mains power. In this case, only the microcontroller is powered, the indicator is not powered by batteries, so it goes out, and the clock continues to run. The control buttons are located on the board in any convenient place on the case. The design of the buttons can be any. To supply power from the network, a Chinese power supply adapter was used, to which a board with a 7805 chip (5-volt stabilizer) was added. In general, any power supply with an output voltage of 5V and a current of 150mA will do.

The program is written in such a way that it can be used for initial study microcontroller PIC, the action of almost every command is commented on. If desired, you can easily add additional functions to it, such as a calendar, timer, stopwatch, etc.



File:
Size:
Content:

Schematic diagram of the frequency meter

The PIC16F628A microcontroller is used to do all the work without any additional chips. The 16F628A has 16 I/O pins, two of which are used for the crystal oscillator, one is for signal input and the other can only be used for input, giving us only 12 useful I/O pins. The solution is to install a transistor that opens when all other numbers are turned off.

The 7 segment LED display used here is a common cathode type BC56-12SRWA. When all the signals are on high level, transistor Q1 opens and switches on the first digit. The current for each segment is about 7 mA.

The entire frequency meter circuit consumes a current of about 30 mA on average. The microcontroller uses its internal 4 MHz oscillator to clock the CPU. And an external quartz oscillator with a frequency of 32768 Hz is needed to set 1 second time interval. Tmr0 is used to count the input signal at pin RA4.

The input signal will need 5 volts square wave. The frequency meter itself can measure up to 1 megahertz, which is more than enough for amateur projects. This is done for convenience, since the meter can reach readings of 999999 Hz - and there is no need to switch anything. We measure at least 11 hertz, at least 139.622 kilohertz.

In general, if anyone wants to repeat this project themselves, here are the . The board in the archive is slightly different from the one in the photo; some optimizations were later made. A program code open - you can optimize it if you know how.