How to set up smartphones and PCs. Informational portal
  • home
  • Windows 7, XP
  • Do-it-yourself watch on LED indicators. Clock on AVR microcontroller with DS1307

Do-it-yourself watch on LED indicators. Clock on AVR microcontroller with DS1307

As the name implies, the main purpose of this device is to find out the current time and date. But it has many other useful features. The idea of ​​its creation appeared after I came across a half-broken watch with a relatively large (for a wrist) metal case. I thought that I could insert a home-made watch there, the possibilities of which are limited only by my own imagination and skill. As a result, a device appeared with the following functions:

1. Clock - calendar:

    Countdown and display on the indicator of hours, minutes, seconds, day of the week, day, month, year.

    Availability of automatic correction of the current time, which is performed every hour (maximum values ​​+/- 9999 units, 1 unit = 3.90625 ms.)

    Calculating the day of the week by date (for the current century)

    Automatic changeover to summer and winter time (switchable)

  • Leap years are taken into account

2. Two independent alarms (a melody sounds when triggered)
3. Timer with a discreteness of 1 sec. (Maximum countdown time 99h 59m 59s)
4. A two-channel stopwatch with a count rate of 0.01 sec. (maximum counting time 99h 59m 59s)
5. Stopwatch with 1 second count rate. (maximum counting time 99 days)
6. Thermometer in the range of -5 ° С. up to 55 ° С (limited by the temperature range of normal operation of the device) in increments of 0.1 ° С.
7. Reader and emulator of electronic keys - tablets of the DS1990 type using the Dallas 1-Wire protocol (memory for 50 pieces, in which there are already several universal "all-terrain keys") with the ability to view the key code byte.
8. IR remote control (only the command "Take a picture" is implemented) for digital cameras "Pentax", "Nikon", "Canon"
9. LED flashlight
10.7 melodies
11. Sound signal at the beginning of every hour (switchable)
12. Sound confirmation of pressing buttons (switchable)
13. Battery voltage monitoring with calibration function
14. Digital adjustment of indicator brightness

Maybe this functionality is redundant, but I like universal things, well, plus the moral satisfaction that this watch will be made by hand.

Schematic diagram of the clock

The device is based on the ATmega168PA-AU microcontroller. The clock is ticking according to the T2 timer, which operates in asynchronous mode from the clock quartz at 32768 Hz. The microcontroller is in sleep mode almost all the time (the indicator is off), waking up once a second to add this very second to the current time and falling asleep again. In the active mode, the MC is clocked from the internal RC oscillator at 8 MHz, but the internal prescaler divides it by 2, as a result, the core is clocked from 4 MHz. For indication, four single-digit LED digital seven-segment indicators with a common anode and decimal point are used. There are also 7 status LEDs, the purpose of which is as follows:
D1- Sign of negative value (minus)
D2- Sign of a running stopwatch (flashing)
D3- Sign of the included first alarm clock
D4- Sign of the included second alarm clock
D5- Sign of sound signaling at the beginning of every hour
D6- Sign of a running timer (blinking)
D7- Sign of low battery voltage

R1-R8 - current-limiting resistors of segments of digital indicators HG1-HG4 and LEDs D1-D7. R12, R13 - divider for battery voltage control. Since the clock supply voltage is 3V, and the white LED D9 needs about 3.4-3.8V at the rated current consumption, it does not glow at full power (but it is enough not to stumble in the dark) and therefore is connected without a current-limiting resistor. Elements R14, Q1, R10 are designed to control the D8 infrared LED (implementation of remote control for digital cameras). R19, ​​R20, R21 are used for interfacing when communicating with devices that have a 1-Wire interface. Control is carried out by three buttons, which I conditionally named: MODE (mode), UP (up), DOWN (down). The first of them is also designed to wake up the MC by an external interrupt (while the indication turns on), so it is connected separately to the PD3 input. Pressing the rest of the buttons is determined using the ADC and resistors R16, R18. If the buttons are not pressed within 16 seconds, then the MK falls asleep and the indicator goes out. When in mode "Remote control for cameras" this interval is 32 seconds, and with the flashlight on, 1 minute. Also MK can be put to sleep manually using the control buttons. When the stopwatch is running with a count rate of 0.01 sec. the device does not enter sleep mode.

Printed circuit board

The device is assembled on a double-sided round-shaped printed circuit board to fit the inner diameter of a wristwatch case. But in the manufacture I used two single-sided boards with a thickness of 0.35 mm. This thickness was again obtained by peeling it from a double-sided fiberglass with a thickness of 1.5 mm. Then he glued the boards. All this was done because I did not have a thin double-sided fiberglass, and each saved millimeter of thickness in the limited internal space of the watch case is very valuable, and there was no need to combine it in the manufacture of printed conductors using the LUT method. The PCB drawing and the location of the parts are in the attached files. On one side there are indicators and current-limiting resistors R1-R8. On the back - all the other details. There are two through holes for white and infrared LEDs.

The contacts of the buttons and the battery holder are made of flexible, springy sheet steel with a thickness of 0.2 ... 0.3 mm. and tinned. Below are photos of the board from both sides:

Construction, parts and their possible replacement

Microcontroller ATmega168PA-AU can be replaced with ATmega168P-AU, ATmega168V-10AU ATmega168-20AU. Digital indicators - 4 pieces KPSA02-105 super bright red color with a height of 5.08 mm. Can be supplied from the same series KPSA02-xxx or KCSA02-xxx. (just not green - they will glow faintly) I do not know of other analogs of similar sizes with decent brightness. In HG1, HG3, the cathode connection of the segments differs from HG2, HG4, because it was more convenient for me to lay out the printed circuit board. In this regard, a different character generator table is used for them in the program. Used resistors and capacitors SMD for surface mounting of standard sizes 0805 and 1206, LEDs D1-D7 of standard size 0805. White and infrared LEDs with a diameter of 3mm. The board has 13 through holes where you need to install jumpers. A DS18B20 with a 1-Wire interface was used as a temperature sensor. LS1 is a conventional piezoelectric sounder that fits into the lid. With one contact, it connects to the board with the help of a spring installed on it, with the other it connects to the watch case by the lid itself. Quartz resonator from a wristwatch.

Programming, firmware, fuses

For in-circuit programming, the board has only 6 round contact pins (J1), since a full-fledged connector does not fit in height. I connected them to the programmer using a contact device made of a PLD2x3 pin plug and soldered onto them with springs, pressing them with one hand to the spots. Below is a photo of the device.

I used it because during the debugging process I had to reflash the MK many times. With a one-time firmware, it is easier to solder thin wires connected to the programmer to the patches, and then unsolder again. It is more convenient to flash the MK without a battery, but so that the power comes either from an external + 3V source, or from a programmer with the same supply voltage. The program is written in assembler in the VMLAB 3.15 environment. Source codes, firmware for FLASH and EEPROM in the application.

FUSE bits of microcontroller DD1 must be programmed as follows:
CKSEL3 ... 0 = 0010 - clocking from the internal RC oscillator 8 MHz;
SUT1 ... 0 = 10 - Start-up time: 6 CK + 64 ms;
CKDIV8 = 1 - frequency divider by 8 is disabled;
CKOUT = 1 - Output Clock on CKOUT is disabled;
BODLEVEL2… 0 = 111 - supply voltage control is disabled;
EESAVE = 0 - erasing the EEPROM during chip programming is prohibited;
WDTON = 1 - No constant activation of Watchdog Timer;
It is better not to touch the rest of the FUSE bits. FUSE – bit is programmed if set to “0”.

EEPROM flashing with the dump enclosed in the archive is required.

The first EEPROM cells contain the initial parameters of the device. The table below describes the purpose of some of them, which can be changed within reasonable limits.

Cell address

Appointment

Parameter

Note

The amount of battery voltage at which a low battery signal occurs

260 ($ 104) (2.6V)

coefficient for correcting the value of the measured battery voltage

time interval for transition to sleep mode

1 unit = 1 sec

time interval for switching to sleep mode when the flashlight is on

1 unit = 1 sec

time interval for switching to sleep mode when in remote control mode for cameras

1 unit = 1 sec

This is where the IButton key numbers are stored.

Small explanations for the points:

1 point. The value of the voltage on the battery is indicated here, at which the LED will light up, signaling its low value. I set it to 2.6V (parameter - 260). If you need something else, for example 2.4V, then you need to write 240 ($ 00F0). The low byte is entered into the cell at $ 0000, and the high byte, respectively, in $ 0001.

2 point. Since I did not install a variable resistor on the board to adjust the accuracy of the battery voltage measurement due to lack of space, I introduced software calibration. The calibration procedure for accurate measurement is as follows: initially, a factor of 1024 ($ 400) is written in this EEPROM cell, you need to put the device in active mode and look at the voltage on the indicator, and immediately measure the real voltage on the battery with a voltmeter. The correction factor (K), which must be set, is calculated by the formula: K = Uр / Ui * 1024 where Uр is the real voltage measured by a voltmeter, Ui is the voltage measured by the device itself. After calculating the "K" factor, it is entered into the device (as described in the operating instructions). After calibration, my error did not exceed 3%.

3 pips Here you can set the time after which the device goes into sleep mode if no buttons are pressed. It costs me 16 seconds. If you need to fall asleep after 30 seconds, then you need to write down 30 ($ 26).

The 4 and 5 points are the same.

6 pips The address $ 0030 stores the zero key family code (dallas 1-Wire), then its 48-bit number and CRC. And so 50 keys in series.

Setting, work features

Setting up the device comes down to calibrating the battery voltage measurement as described above. It is also necessary to detect the deviation of the clock in 1 hour, calculate and enter the corresponding correction value (the procedure is described in the operating instructions).

The device is powered by a CR2032 (3V) lithium battery and consumes about 4 μA in sleep mode, and 5 ... 20 mA in active mode, depending on the brightness of the indicator. With a daily five-minute use of the active mode, the battery should be enough for about 2 ... .8 months, depending on the brightness. The watch case is connected to the minus of the battery.

Key reading was checked on DS1990. Emulation is tested on METAKOM intercoms. Serial numbers from 46 to 49 (last 4) are stitched (all keys are stored in EEPROM, they can be changed before flashing) universal keys for intercoms. The key registered at number 49 opened all METAKOM intercoms that I came across, the rest of the universal keys could not be tested, I took their codes from the network.

Remote control for cameras tested on Pentax optio L20, Nikon D3000. Canon could not get it to check.

The user manual is 13 pages long, so I did not include it in the article, but put it in the attachment in PDF format.

The archive contains:
Scheme in and GIF;
Drawing of the printed circuit board and the arrangement of elements in the format;
Firmware and sources in assembler;

List of radioelements

Designation A type Denomination Quantity NoteScoreMy notebook
DD1 MK AVR 8-bit

ATmega168PA

1 PA-AU Into notepad
U2 temperature sensor

DS18B20

1 Into notepad
Q1 MOSFET transistor

2N7002

1 Into notepad
C1, C2 Capacitor30 pF2 Into notepad
C3, C4 Capacitor0.1 uF2 Into notepad
C5 Electrolytic capacitor47 uF1 Into notepad
R1-R8, R17 Resistor

100 ohm

9 Into notepad
R9 Resistor

10 kΩ

1 Into notepad
R10 Resistor

8.2 Ohm

1 Into notepad
R11 Resistor

300 Ohm

1 Into notepad
R12 Resistor

2 MOhm

1 Into notepad
R13 Resistor

220 kΩ

1 Into notepad
R14 Resistor

30 kΩ

1 Into notepad
R15, R19 Resistor

4.7 k Ohm

2 Into notepad
R16 Resistor

20 kΩ

1

Self-made wristwatch on a vacuum indicator, made in steampunk style. Material taken from www.johngineer.com. This wristwatch is based on the IVL-2 display. Initially I bought several of these indicators to create a standard table clock, but after reflection I realized that you can build a stylish wristwatch too. The indicator has a number of features that make it more suitable for this purpose than most other Soviet displays. Here are the parameters:

  • The nominal filament current is 60mA 2.4V, but works with 35mA 1.2V.
  • Small size - only 1.25 x 2.25 "
  • Can work with relatively low grid voltage 12V (up to 24)
  • Only consumes 2.5mA / segment at 12.5V

All pictures can be made larger by clicking on them. The biggest obstacle to the successful completion of the project was food. Since this watch was conceived as part of a suit, it doesn't matter that the battery lasts only 10 hours. Stopped for AA and AAA.

The circuit is pretty simple. Atmel AVR ATMega88 microcontroller, and real-time clock - DS3231. But there are other ICs, much cheaper, that will work just as well in a generator.

The VFD is driven by the MAX6920 - 12-bit shift register with high voltage (up to 70V) outputs. It is easy to use, very reliable and compact. It is also possible for the display driver to solder a bunch of discrete components together, but this was impractical due to space constraints.

The battery voltage also powers the 5V boost converter (MCP1640 SOT23-6), which is required for the AVR, DS3231, and MAX6920 to operate properly, and also acts as an input voltage for the second boost converter (NCP1403 SOT23-5), which produces 13V for grid voltage of the vacuum indicator.

The watch has three sensors: one analog and two digital. The analog sensor is a phototransistor and is used to detect the light level (Q2). Digital sensors: BMP180 - pressure and temperature, and MMA8653 - accelerometer for motion detection. Both digital sensors are connected via the I2C bus to the DS3231.

Brass tubes are soldered to beauty and protect the glass display of the wristwatch, and 2mm thick copper wires are used to attach the leather strap. The complete schematic diagram is not given in the original article - see the connection via datasheets to the indicated microcircuits.

I bring to your attention electronic microcontroller clock... The clock circuit is very simple, contains a minimum of details, and is available for repetition for novice radio amateurs.

The design is assembled on a microcontroller and a real-time clock DS1307... As an indicator of the current time, a four-digit seven-segment LED indicator is used (ultra-bright, blue glow color, which looks good in the dark, and, at the same time, the clock plays the role of a night light). The clock is controlled by two buttons. Thanks to the use of the DS1307 real-time clock microcircuit, the program algorithm is quite simple. Communication between the microcontroller and the real-time clock occurs via the I2C bus, and is organized by software.

Clock scheme:

Unfortunately, there is an error in the schema:
- the conclusions of the MK to the bases of the transistors must be connected:
PB0 to T4, PB1 to T3, PB2 to T2, PB3 to T1
or change the connection of the collectors of transistors to the indicator discharges:
T1 to DP1 ... .. T4 to DP4

Details used in the watch diagram:

♦ ATTiny26 microcontroller:

♦ Real time clock DS1307:

♦ 4-digit seven-segment LED indicator - FYQ-5641UB -21 with a common cathode (ultra-bright, blue light color):

♦ quartz 32.768 kHz, with an input capacitance of 12.5 pF (can be taken from the computer motherboard), the accuracy of the clock depends on this quartz:

♦ all transistors - NPN-structures, you can use any (KT3102, KT315 and their foreign counterparts), I used BC547S
♦ microcircuit voltage stabilizer type 7805
♦ all resistors with a power of 0.125 watts
♦ polar capacitors for operating voltage not lower than supply voltage
♦ backup power supply for DS1307 - 3 volt lithium cell CR2032

To power the watch, you can use any unnecessary cell phone charger (in this case, if the voltage at the charger output is within 5 volts ± 0.5 volts, part of the circuit is a voltage regulator on a 7805 microcircuit, you can exclude)
The current consumption by the device is - 30 mA.
The backup battery for the DS1307 clock may not be installed, but then, in the event of a power outage, the current time will have to be set again.
The printed circuit board of the device is not shown, the structure was assembled in a case from a faulty mechanical clock. The LED (with a blinking frequency of 1 Hz, from the SQW DS1307 output) serves to separate the hours and minutes on the indicator.

Factory settings of the microcontroller: clock frequency - 1 MHz, FUSE-bits do not need to be touched.

Clock algorithm(in Algorithm Builder):

1. Setting the stack pointer
2. Setting the timer T0:
- frequency SK / 8
- overflow interrupts (at this preset frequency, an interrupt is called every 2 milliseconds)
3. Initialization of ports (pins PA0-6 and PB0-3 are configured for output, PA7 and PB6 for input)
4. Initialization of the I2C bus (pins PB4 and PB5)
5. Checking the 7th bit (CH) of the zero register DS1307
6. Global enable interrupt
7. Entering the cycle with checking the button press

The first time it is turned on, or when it is turned on again without backup power to the DS307, it returns to the initial setting of the current time. In this case: button S1 - to set the time, button S2 - go to the next digit. Set Time - The hours and minutes are written to the DS1307 (seconds are set to zero), and the SQW / OUT pin (7th pin) is set to generate 1 Hz square-wave pulses.
By pressing the S2 button (S4 - in the program), interrupts are prohibited globally, the program goes to the time correction subroutine. At the same time, tens and units of minutes are set using the S1 and S2 buttons, then, from 0 seconds, pressing the S2 button records the updated time in DS1307, allows the global interrupt and returns to the main program.

The watch showed good accuracy, the time drift per month was 3 seconds.
To improve the accuracy, it is recommended to connect quartz to DS1307, as indicated in the datasheet:

The program is written in the "Algorithm Builder" environment.
Using the clock program as an example, you can familiarize yourself with the algorithm for communicating between the microcontroller and other devices via the I2C bus (each line is commented in detail in the algorithm).

Photo of the assembled device and printed circuit board in .lay format from the site reader Anatoly Pilguk, for which many thanks to him!

The device uses: Transistors - SMD VS847 and CHIP resistors

Appendices to the article:

(42.9 KiB, 3,038 hits)

(6.3 KiB, 4,058 hits)

(3.1 KiB, 2,500 hits)

(312.1 KiB, 5,833 hits)


The second version of the clock program in AB (for those who do not have the upper one)

(11.4 KiB, 1,842 hits)

Simple LED clocks can be made with a cheap PIC16F628A controller. Of course, the stores are full of various electronic clocks, but according to their functions, they may either lack a thermometer or an alarm clock, or they do not glow in the dark. And in general, sometimes the proto wants to solder something himself, and not buy ready-made. To enlarge the diagram of the diagram - click.

The watches offered have a calendar. It has two options for displaying the date - month in digit or syllable, all this is configured after entering the date by switching further with the button S1 while the desired parameter is displayed, the thermometer. there are firmwares for different sensors. See the device inside the case:


Everyone knows that quartz resonators are not perfect in terms of accuracy, and within a few weeks, an error accumulates. To combat this case, the watch provides for a stroke correction, which is set by the parameters SH and SL... More details:

SH = 42 and SL = 40 - this is forward 5 minutes a day;
SH = 46 and SL = 40 - this is 3 minutes a day back;
SH = 40 and SL = 40 - this is forward by 2 minutes a day;
SH = 45 and SL = 40 - this is back 1 minute per day;
SH = 44 and SL = С0 - this is forward by 1 minute per day;
SH = 45 and SL = 00 - this correction is disabled.

In this way, perfect accuracy can be achieved. Although you will have to drive the correction several times until you set it perfectly. And now the work of the electronic clock is clearly shown:

temperature 29 degrees Celsius

As indicators, you can put either LED digital assemblies, which are indicated in the diagram itself, or replace them with ordinary round super-bright LEDs - then this clock will be visible from afar and can be hung even on the street.

Clock with LED backlight and pulsating minute hand on an Arduino microcontroller
This unique watch with LED backlight and pulsating minute hand was made using the TLC5940 PWM controller chip. Its main task is to expand the number of contacts with PWM modulation. Another feature of this watch is the converted analog voltmeter into a device that measures minutes. For this, a new scale was printed on a standard printer and pasted over the old one. As such, the 5th minute is not counted, it is just that during the fifth minute the time counter shows an arrow, resting on the end of the scale (goes off scale). The main control is implemented on the Arduino Uno microcontroller.

In order for the clock backlight not to shine too brightly in a dark room, a circuit was implemented to automatically adjust the brightness depending on the illumination (a photoresistor was used).

Step 1: Required components



Here's what you need:

  • Analog voltmeter module for 5V DC;
  • Arduino UNO microcontroller or other suitable Arduino;
  • Arduino circuit board (proto board);
  • DS1307 Real Time Clock (RTC);
  • Module with PWM controller TLC5940;
  • Petal LEDs for illumination - 12 pcs.;
  • Components for assembling an automatic brightness control (LDR) circuit.

Also, for the manufacture of some other components of the project, it is desirable to have access to a 3D printer and a laser cutting machine. It is assumed that you have this access, therefore, drawings for manufacturing will be attached in the instructions at the appropriate stages.

Step 2: dial




The dial consists of three parts (layers) cut on a laser cutting machine from 3 mm MDF sheet, which are fastened together with bolts. A non-slotted plate (bottom right in the picture) is placed under another LED positioning plate (bottom left). Then, the individual LEDs are placed in the corresponding grooves, and the front panel is put on top (top in the figure). There are four holes drilled around the edge of the dial through which all three pieces are bolted together.

  • To test the performance of the LEDs at this stage, a CR2032 coin cell battery was used;
  • To fix the LEDs, small strips of adhesive tape were used, which were glued to the back of the LEDs;
  • All LED legs have been pre-bent accordingly;
  • The holes were re-drilled at the edges and bolted through. It turned out to be much more convenient.

The technical drawing of parts for the dial is available at:

Step 3: Design the circuit



At this stage, the electrical circuit was developed. For this, various tutorials and guides were used. We will not go deep into this process, the two files below show the finished electrical circuit that was used in this project.

Step 4: Connecting the Arduino circuit board





  1. The first step is to unsolder all the needle contacts on the circuit boards and breakout boards;
  2. Further, due to the fact that a lot of boards and peripherals use 5V and GND power, for reliability, two wires for 5V and GND were soldered on the circuit board;
  3. Next, a TLC5940 PWM controller was installed next to the pins used;
  4. After that, the TLC5940 controller is connected, according to the connection diagram;
  5. In order to be able to use the battery, an RTC module was installed on the edge of the circuit board. If you solder it in the middle of the board, then the designation of the contacts will not be visible;
  6. The RTC module is connected according to the connection diagram;
  7. The automatic brightness control (LDR) circuit is assembled, you can find it by the link
  8. The wires for the voltmeter are connected by connecting the wires to pin 6 and GND.
  9. At the end, 13 wires for the LEDs were soldered (In practice it turned out that it was better to do this before proceeding with step 3).

Step 5: program code

The code below has been assembled from various pieces of watch components found on the internet. It has been fully debugged and is now fully functional, plus some fairly detailed comments have been added. But before loading into the microcontroller, consider the following points:

  • Before flashing the Arduino, you need to uncomment the line that sets the time:
    rtc.adjust (DateTime (__ DATE__, __TIME__))
    After flashing the controller with this line (the time is set), you need to comment it out again and flash the controller again. This allows the RTC to use the battery to keep track of the time if the main power fails.
  • Every time you use "Tlc.set ()" you need to use "Tlc.update"

Step 6: outer ring

The outer watch ring was 3D printed on a Replicator Z18. It is attached to the watch with screws on the face of the watch. Below is a file with a 3D model of the ring for printing on a 3D printer.

Step 7: Assembling the watch


The Arduino microcontroller with all the rest of the electronics was attached to the back of the watch with screws and nuts as spacers. Then all the LEDs, analog voltmeter and LDR are connected to the wires that were previously soldered to the circuit board. All LEDs are interconnected by one leg and connected to the VCC pin on the TLC5940 controller (just a piece of wire is soldered in a circle).

So far, all this is not very well insulated from short circuits, but work on this will be continued in the next versions.

Top related articles