Smart alarm clock for smart home

What do not collect on avr, but in the end you still get hours
from amateur radio forums

imageMany residents of megacities (and not only) often experience the inconvenience of having to wake up early in the morning. Especially in winter - it is dark outside the window, the body thinks that it’s still night, hence the feeling of lack of sleep and poor health. However, in the summer in the morning sunlight it is usually much easier to wake up. It was decided to try to “trick” the body by using the smoothly increasing brightness of artificial light to awaken. Alarms with this effect exist ready-made, but they are quite expensive, in addition, the project was done more for your own pleasure.

On a hub, various remotely controlled sockets and bulbs with Wi-Fi control are often mentioned, in this project a similar problem is solved by means of IR control.

imageQuite a long time ago, a Chinese-made LED lamp with an IR remote control was purchased at an ebay auction. The lamp has a standard E27 base, 9W power and subjectively has the brightness of a forty-watt incandescent lamp. From the remote you can turn on / off the lamp, as well as set 5 different brightness levels.

The idea was as follows - to collect an alarm on the AVR microcontroller, which will smoothly increase the brightness of this lamp before transmitting an audio signal by transmitting IR commands. At the same time, the lamp is screwed in instead of one of the usual lamps of the overhead chandelier. Half an hour before the set time, the light turns on at the minimum brightness, then the brightness gradually increases to 100%.

As a result of the work, I wanted to see if not a masterpiece, then at least something in a decent-looking case, for which it was decided to make an alarm clock in a partially glass case with touch control. Atmel offers the QTouch library for its microcontrollers, which allows you to implement touch buttons in your devices at minimal cost. In this project, I just wanted to try out this wonderful library.

The final design was as follows - a single-sided printed circuit board on which LED indicators, an IR LED, a photo sensor, a power connector are installed on one side (front), and the other elements are soldered by surface mounting on the other side (tracks). Then the indicators are closed with a tinted glass plate, on the back of which touch buttons are glued in the right places. On the back side, the board is closed by a case, which is a plastic box of a suitable size. At the same time, we have an aesthetic appearance in the absence of mechanical buttons.

So, let's start designing. To begin with, we will determine the microcontroller - it must have a sufficient number of conclusions for the implementation of indications and touch buttons, and also be in the case not very difficult for manual soldering. These requirements are met by ATMEGA324P (44 feet and 0.8 mm pitch). We select the display - as such, it was decided to use an LED display with large numbers (1.8 ”). The display consists of four single-digit indicators with a common anode. Typically, large-sized display segments consist of several series-connected LEDs, so a five-volt power supply is indispensable, and a clock voltage of at least 9 V is required to power the watch.


To control such a display, a driver is required. The display has a common anode, so we will proceed as follows - the display cathodes will be connected to the ULN2803 chip through current-limiting resistors, and we will provide separate transistor switches for the anodes. The ULN2803 chip is an 8 transistor with resistors in the base circuit, which makes it very convenient for such an application.

Next, the watch itself, more precisely, the RTC chip. As such, the DS3231 was chosen - a chip with a built-in quartz resonator and a minimum number of external components. The manufacturer promises accuracy of the order of several seconds per year. Also, due to the built-in temperature meter for temperature compensation of quartz frequency drift, we get a “free” thermometer that shows the temperature inside the case.

For a call the piezoelectric transducer ZP-19 is used.

As an "executive element" that distinguishes an alarm clock from millions of similar ones, the circuit contains an infrared LED, which will form commands for the light bulb.

An unstabilized 12 V power supply is used to power the clock from the network. To power the microcontroller, a separate power supply must be provided in the circuit - we put the well-known linear source LM7805.

At the end, we will provide in the circuit a two-color LED for indicating the status of the alarm clock, as well as a photosensor for implementing a change in the brightness of the indicator depending on the level of illumination. The photosensor will be connected to the comparator, therefore, it is necessary to provide a trimming resistor to adjust the threshold.
Schemeready, you can start programming and manufacturing. Before manufacturing, most of the program was tested in the Proteus simulator, in which all the design was carried out.

Unfortunately, it was not possible to simulate the work of the QTouch library in the proteus, so first I had to collect part of the circuit on a breadboard and play with capacitive sensors separately. The library showed itself perfectly - a clear response in all cases.

The next element that required experimental testing is the actual remote control of the bulb. We connect the photodiode to the oscilloscope and look at the signal by pressing the remote control buttons:


The picture shows that the NEC protocol is used - one of the well-known infrared control protocols, where the information is encoded by the duration of the pause between pulses. Logical 1 - pause of 1.7 ms, logical 0 - pause of 0.6 ms. After the start sequence (9 ms pulse and 4.5 ms pause) 32 bits are transmitted: address, inverse address, command, inverse command. The protocol is well documented, and it is easy to find a detailed description on the Internet.

Using an oscilloscope, we also determine the transmission frequency - it turned out to be equal to 38 KHz. So, the necessary codes for the buttons of the remote control:


We write the functions that will form the IR commands, check with the help of the layout - the light turns on, the brightness is adjusted - that means everything is almost ready, you can collect the clock.

The board was made by the LUT method. I have a rather modest experience in the manufacture of circuit boards using this method, but it turned out quite bearable. Not without jambs - I forgot to provide for the RESET output in the programming connector on the circuit, I had to solder separately. In the photo, the board just assembled, with the flux still not washed in places.


Once again, check, turn on, fill in the firmware and begin the debugging process. After everything works, you can close everything in the case.

We continue to catch errors. As already mentioned, as the main element of the case, it was decided to order a tinted glass plate with a machined edge and four holes through which it will be attached to the board. If someone wants to make a similar design, I advise you to design the board after ordering the plate. I found a company that promised any work with glass according to sketches, with high precision, modern machines, etc., in practice, mounting holes were drilled with a difference of a centimeter from the sketch. However, I did not begin to make a complaint, I just adjusted the fee a little. Another mistake was the wrong choice of the diameter of the holes in the glass - initially, for fixing, I wanted to use decorative nuts with a flat surface.Chicago Screws ). However, when the nuts arrived, it turned out that they had a threaded part diameter of 5 mm, and the holes in the glass plate were 4 mm, so I had to abandon the idea and fix the glass with ordinary countersunk bolts, which were then simply painted with a marker.

Touch sensors are located on the back of the glass - for this we use aluminum tape. Pieces of foamed polyethylene (from packages with ebay) are pressed against the sensors by wires from the board. Under the alarm button there is an indicator LED - the logic of its operation is as follows: if the alarm rings in the next 24 hours - green, does not ring - red, all alarms are turned off - the LED does not light. The alarm clock symbol (bell) is also transferred to tape by the LUT method, carefully cut out and glued to the glass.

Tinted glass showed excellent performance in working with touch buttons and aesthetic design of the display, however, it very significantly attenuates infrared radiation. One IR LED does not work reliably, so in addition to breaking the track, another one was soldered, which shines through a hole in the upper wall of the case. As a result, we have a confident response, no worse than a regular remote control.

According to the results of the operation of the alarm clock, we can say that the idea fully paid off - waking up with such a device on a dark winter morning is really much easier. Additionally we have a bedside remote lighting switch.

The article was written more out of a desire to share the idea of ​​how to implement this with minimal effort, but if someone wants to repeat the device in this form, it is ready to provide firmware and answer questions.

Link to firmware sources, circuit and board in Proteus format:

List of sources:

Also popular now: