📜 ⬆️ ⬇️

Artificial dawn

It all started a year ago. Before the New Year 2014, the vitality was somewhat declining. The process of self-digging led to the following thought:



- And why is it so dark, Lord? © Radio Day.
')
However, for a person who lives in the winter by summer time - the idea is quite natural.

Idea


Not being able to rearrange the time, I decided to try changing the sensations by changing the lighting. The train of thought was approximately the following: natural light enters the apartment naturally through a window, and when there is no light it is dark. It is difficult to light the light outside the window, but it is possible to create the illusion that there is light outside. Looking at the window at night, we see darkness - this does not change, but at night people usually turn on the light and close the curtains - it is so lighter and more comfortable. And what is the difference between a curtain window at night and day? And the fact that the light breaks through the curtains. So, actually, the very idea was born: it is necessary to highlight the space between the window and the curtains!

For a general conceptual check, a white LED tape was bought and glued (it turned out that there was an adhesive layer on these tapes) to the kitchen ledge, so that the LEDs themselves could not be seen even by chance - this is an illusion, it cannot be destroyed. Of course, I am aware that in many respects there is an element of psychology - but it really worked.

Necessary for a white five-meter tape 2A at 12V were taken were taken from the BP sdatshego portable disk. However, 12V from a computer power supply unit will be no worse (just you need to know how to start it and you shouldn’t turn it on completely without load).

Unfortunately, only three pictures from that first historical experiment (taken on a mixer) have been preserved, but I think they convey a general idea.



Yes ... well, a mess in general, so-so ... But! Let's not forget that it is evening. But on a winter morning, yes, according to summer time, it is quite invigorating!

Inspired by the first success, I decided to continue the experiment now not on myself, but on my own children. After all, it is one thing to get up on an alarm clock yourself and quite another to wake unhappy children, to school, when no sign is visible; knowing perfectly that one of them is like a lark who, if it was light outside, would have sat at the table a long time ago and quietly collected some kind of LEGO ... But, here - understandably - you really need a real illusion . Dawn is needed! Present. And not at 7 am, when dad turned on (dad, by the way, would have slept some more). And not immediately, but gradually. And the light should not be white, but red-orange-yellow.

Obviously, a scheduled RGB tape is needed. And that means a microcontroller and a real time clock. And the free time that appeared successfully coincided with the existing desire to do something useful on the AVR.

Implementation


Ta-dam. Meet - Voskhod1b! A device to simulate a natural dawn, he's a gentle alarm clock, he's an organizer, he's a nightlight, he's the same, whatever, if you add the necessary sensors and modify the code. For example: a traffic light assembly, office hours with an indication of lateness and breaks or lights for the aquarium or light and music design, etc., etc.


Dawn


Children get ready for school (so-called 'green whistle')




Daylight, extend the 'sunny' day


Night light

The schedule is programmed using a text interface. Available commands can be obtained by requesting a hint with the - h command, possible schedule operation modes can be found with the - ha command. You can connect either directly via UART or via bluetooth. Colors are encoded in three hexadecimal bytes. For the selection of color values, it is possible to use the interactive mode. In interactive mode, you can control both RGB and HSV color components. The work schedule is stored in the controller's EEPROM memory. The device can be turned off at any time. The state after switching on is 'not turned off, as it were'.

Here is an example of a schedule that I used for my third-year pupils, exhausted from school a year ago:

00:00:00 => 06:40:00: dark sleep
06:40:00 => 06:55:00: rgb 08 05 03 artificial ...
06:55:00 => 07:00:00: rgb 40 25 15 ... new ...
07:00:00 => 07:05:00: rgb 80 50 39 ... sunrise
07:05:00 => 07:55:00: rgb ff 91 1d warm white light
07:55:00 => 08:00:00: rgb 00 55 00 5 minutes before going to school - the 'green whistle'
08:00:00 => 08:05:00: rgb 55 55 00 go to school - 'yellow whistle'
08:05:00 => 08:20:00: rgb 55 00 00 already late for school - the 'red whistle'
08:20:00 => 11:00:00: dark children at school
11:00:00 => 13:30:00: rgb ff 91 1d warm white
13:30:00 => 14:30:00: rgb 80 50 39 a small daytime ...
14:30:00 => 15:00:00: rgb 20 12 07 ... backlight
15:00:00 => 16:57:00: dark daytime sleep
16:57:00 => 16:58:00: rgb 20 12 07 proms ...
16:58:00 => 16:59:00: rgb 40 25 14 ... we drink ...
16:59:00 => 17:00:00: rgb 80 50 30 ... camping
17:00:00 => 21:00:00: rgb ff 91 1d evening lights
21:00:00 => 22:00:00: rgb 40 25 15 artificial ...
22:00:00 => 23:00:00: rgb 08 05 03 ... sunset
23:00:00 => 23:30:00: rgb 01 01 03 twilight
23:30:00 => 00:00:00: rgb 00 00 01 night light until midnight

Scheme :


Used MK ATmega168. ATmega328 or ATmega88 / ATmega8 will do, but the latter will have slightly smaller teams and a shorter tip. I did not check, but I am sure that ATmega16 will work. Real time clock - DS1307. LEDs are lit MOSFET'ami IRF540N. Of course, such powerful transistors are not needed, they were just at hand, but common and not expensive - it’s not a pity. There is a power reserve, you can work with tapes at 24V, and if there is current protection in the power supply unit, short circuits in the tape are not terrible.

Necessary 5V for mega and 3.3V for bluetooth module HC-05 - produce linear stabilizers L7805 and L78L33. The bluetooth module (U5) is optional, as are the resistors R11, R12, R13 (matching 5V MK with 3.3V bluetooth controller) as a stabilizer U4. The scheme will run and work even without U2, but, of course, only in interactive mode.

Program. I didn’t want to write on an assembler, apparently that’s why the program didn’t fit in ATtiny2313, and I really didn’t stop at it. It was interesting to assess the possibility of using C ++ for programming microcontrollers. It turned out that it is quite possible, using abstract interfaces, to write code that is collected for both the MC (Atmel Studio 6.1) and Windows (Microsoft Visual Studio 2012). Under Windows, a project is built using the RTC, UART, EEPROM, and PWM emulation software. I am sure that the code will work without problems even under Linux, if we exclude the only windows-api function SetConsoleTitleA (), which displays the current PIM values ​​in the window title.

The library for working with UART is taken from Application Note AVR303 - buffered hardware UART on interrupts. The code is slightly modified to support ATmega8 / 16, ATmegaX8 and ATiny2313 (USART2.cpp, USART2.h).

Pavel Bobkov’s ChipEnable.Ru library (for which he thanks a lot) based on the AVR315 (twim.cpp, twim.h) is used to work with the DS1307 I2C interface.

Hmm, it turns out that the project is assembled "from the world on a thread." However, why be surprised - the way it is. From what I can boast of myself, this is perhaps the implementation of the HSV-> RGB fast conversion, which does not use the division operation (see HSV2RGB.cpp, HSV2RGB.h).

Work with UART and I2C is performed on interrupts, and so that the processor does not miss: PWM is software. That is almost software - tied to an 8-bit timer. Experiments have shown that purely software PWM in the main loop, despite the maximum frequency, looks bad, flickers. I suspect that the reason is associated with small frequency fluctuations that become visible to the eye. My PWM, though software, is not quite simple: the LEDs light up with a shift by a third of the period. For example, if R = G = B = 25, then the periods of illumination of the LEDs R [0,24], G [85,109], B [170,194]. According to my feelings, in this mode of operation, the tape looks better.

The circuit board is divorced in the DipTrace program on one layer. The size of the software is determined by the size of the purchased plastic box. Transistors and stabilizers had to be put in, but convenient clamping connectors had to be abandoned - there was not enough space.

Power supply - any suitable power for power LED-tapes. For the usual five-meter 12-volt RGB-tape (60 LEDs per meter) you need a 6A power supply unit. Of course, a computer power supply will also work. If you use the PSU from the computer, there is no need for stabilizers U3, U4, since 5V and 3.3V can be taken directly from it. The computer power supply has only two drawbacks: the size and the fan.

A schematic diagram, a PCB drawing (there is a version for LUT and a version for LUT with a fill), the source code, firmware for the ATMega8 / 88/168/328, and a windows emulator are attached.
The programming process and various programmer options are not considered here. I use usbasp programmer: www.fischl.de/usbasp
And the program: www.khazama.com/project/programmer/KhazamaAVRProgrammer162.rar

About fyuzy. Factory AtmegaX8 sold with the bit set "Divide clock by 8 internally", which must be removed. You also need to reconfigure the MC to use high-frequency quartz and be sure to use the “Brown-out detector level at VCC = 4.3V”, otherwise there may be problems with the contents of the EEPROM. In the khazama AVR Programmer program, used fyuzy look like this:




A little about some technological aspects of electronic production of PP in the home


Glass fiber shavings are a very harmful thing, it is desirable to minimize its quantity. For cutting the workpiece, I recommend using not a hacksaw, but scissors for metal - this is more accurate, and faster, and much more convenient. Drilling textolite is better under a layer of water, but this is a little later.

Printed circuit board LUT is our everything. Photoprocessing - I did not try, until there was no need for such thin productions as to mess around with UV lamps and evil alkalis. So, LUT. A lot of things have been tried: a lot of glossy magazines, and the notorious photo paper of a well-known company of various densities and foil (it’s scary to poke into the printer, but it really works), BUT my current choice is vinyl.



Purchased in the household, cheap. Need smooth, textured does not fit, color does not matter. Well, that's the beauty that is! We print a drawing of PP on paper, cut off a piece of vinyl film according to the size of the drawing, glue it onto the drawing from above, print it again. Cut out, iron it with an iron, cool it under a press (an inverted stool will do) and just gently remove the film from the board. Once again - you do not need to soak anything and roll it up - just slowly tear it off like tape. As a demonstration, my board is flooded with fine mesh, in the original LUT technology, to remove paper from the holes is very troublesome.



Yes, the board must first be cleaned of oxide and degreased. Fans can, of course, use fine sandpaper and acetone, but my choice, and for a long time - powdered Comet and paper towels to dry.

We poison in absolutely safe solution of citric acid in hydrogen peroxide. At room temperature, the process takes 15 minutes. Everything happens without stains and odor, as from ferric chloride. (100 ml of hydrogen peroxide, 40 g of citric acid, 1 tsp. Of salt). At the end of the solution is safely drained into the sewer.



We drill , as already mentioned, in the pelvis with water. By the way, the mega-shots on the photo are made, only from two motors from the jet printer.




Pay attention to the turbidity - some of this dust could be in the lungs.

Toner removal is made without chemicals. Acetone? No, not heard. A metal chip can be used to remove toner in less than a minute.




Tinning. Good old soldering iron already fed up. Like this eternal question, what to prick or drill before? Ludim ROSE alloy in water with citric acid and salt. The process takes several minutes. No glycerol! And no rubber spatulas - uncomfortable and hot. My choice is a paint brush and wooden sticks for fixing the board on the bottom of the pot. Citric acid removes the oxide film from the surface of the board. Salt is needed to raise the boiling point, and water with salt boils somehow calmer.



Naturally, the tinning utensils should not be used for food.

After tinning, the board is washed, dried (paper napkins) and covered with a layer of liquid flux (rosin in alcohol).

That's the beauty!

Assembly


As they say in such cases - “a well-fixed patient does not need anesthesia” “a correctly assembled circuit does not need adjustment”. However, I can recommend some order of assembly: we install all resistors and capacitors, sockets for microcircuits and stabilizers U3, U4. We supply power and make sure that at the 7th output of the MK 5V, and 3.3V is also in place. Then we install transistors, quartz, connect the LED tape and program the MK either on the board or in the programmer, and put it in place. After energization, the LEDs on the ribbon must within 5 seconds go through all colors from red through green and blue to red. If the process of changing colors takes 20 seconds - most likely the fusion “Divide clock by 8 internally” is incorrectly set. Then we connect via UART (9600/8 data / no parity / 1 stop) and play with colors in interactive mode. Install the DS1307, set the time with the ts command and make sure that the clock is running ... or is it not ??? There is a subtle point: DS1307 does not always start. We do not panic, launder the flux, dry the board, try to pull the quartz body to the ground, change the quartz or, at worst, DS1307 itself. The clock chip is very sensitive, it works practically on microcurrents - a little bit of accuracy and everything will work out.

The tape is fixed to the eaves and / or ceiling - the main thing is that only the light from the diodes is visible, and not the diodes themselves.




Connecting the tape to the board is conveniently done with a regular twisted pair, brown and brown with white are 12V, the other colors are R, G, B, respectively. If you use a bluetooth device, you can fix it on the eaves somewhere, then you have to pull only 12V or 220V in the same place and power supply.

About the bluetooth module - HC-05 - the handkerchief is small and to install it is convenient to first solder the legs to it, and then install it on the board.



Assembled device :



Pay attention to the jumpers. They connect the bluetooth module with the microcontroller: 3.3V - 3.3V1; URX - UTXb; UTX - URXb. If the bluetooth module is not used, the UART adapter connects to the URX, UTX, GND jacks.
And yes, I confess, I put the power stabilizer of the bluetooth module on my side , ugly as I do not like it myself just to fit the Molex connector into the box.







Growth points




Scheme, firmware, board, source

Total


In operation are two devices. Last collected exactly according to the attached documentation. It works 24 * 5.5 - because at the weekend, despite the general concept, everyone wants to sleep. Dad played with AVR, drilled his son, popay and now happily steers the tape from the tablet. In general, everyone is happy.

Thanks for attention. I hope the device will be useful to someone.

Source: https://habr.com/ru/post/249535/


All Articles