
As part of studying the 12 series, PIC microcontrollers decided to make a small, but very useful device.
My daughter lives an aquarium. The backlight is made on fluorescent lamps, which must be switched on every morning and turned off in the evening. And since we are a family of avid tourists, in order not to arrange for the fish to be tortured with light or darkness for 5-7 days, I decided to make the lighting with LED tape with automatic switch on / off from solar lighting.
Along the way, try to squeeze the maximum out of the microcontroller, in terms of functionality.
So the goal:
- Two independent lighting tapes
- Adjustable light variable resistor
- Implement tape brightness control using software implementation of PWM
- 3 modes of operation:
- sequential increase in the brightness of the tapes in turn (first one then the second)
- simultaneous increase in the brightness of the tapes
- simultaneous increase of brightness of tapes with automatic on / off mode from sunlight
- The automatic mode is implemented on the photoresistor taking into account the hysteresis to eliminate blinking in the twilight period
- Memorizing the selected mode in EEPROM with power on recovery
- LED indication of selected mode
- Change modes by pressing a button
- Since the tapes are powered from 12V, then make the power supply MK from 12V
In store was MK PIC12F675, which is ideally suited for my purposes.
A standard microassembly 7805 is used to power the MK from 12V.
BP was ordered to
BangGood - as it turned out, very worthy of BP for ridiculous money.
LED tape is also ordered there.
I will tell a little about this MK:
8 contacts,
1.75 kb - software flash memory,
128 bytes - EEPROM
64 bytes - RAM
4 - 10bit ADC
On GPIO pins there are software pluggable pull-up resistors.
4MHz - the frequency of the internal clock generator.
2 timers 8/16 bits
At first I was afraid that the speed of the internal clock generator would not be enough so that the tapes with a small PWM value would not blink. Tests on the old ATshnom BP and showed that the tape flicker. But then checking the finished product in the new Chinese BP showed that the ripple came from the old BP.
Actually it is better to tell me the scheme and the source of the program (under MPLAB X), in which everything is described in detail. Since the LED tape has its own current-limiting resistors, they are not indicated in the diagram.
The scheme, source code and some photosSource archive
')
On the label instead of ribbons with field workers, just LEDs with current-limiting resistors are installed.
Under the aquarium cover, 5050 LED strips are laid in the profile.
Well, the control unit itself is glued to the double-sided tape on top of the lid, where the sunlight comes from the window.
In the process, I ran into two problems - during the initialization I forgot to specify ANSEL = 0, as a result of which I was throwing all kinds of garbage on my digital legs.
And in the process of multiple flashing of the MK, the calibration constant has flown away (I cannot understand how, since the PicKit3 programmer automatically protects this constant from being overwritten). As it turned out, the calibration constant in the MIC PIC12 is stored in the last address of the software flash memory and the best method is not to lose it - you must first read and save (I scribbled with a needle on the MK body).
Many thanks to the easyelectronics.ru forum members for their help in solving these issues.
Now the machine has worked perfectly for 2 weeks in the field. Adjustable backlight looks very nice - especially if you place tapes of lighting in the background and in the background. The only negative - now I forget to feed the fish, as they no longer need to turn the lights on and off.
The next step will be an automatic feeder with RTC or via SMS from a mobile phone, but this is probably already on the PIC16 series.
The cost of the project came out at about $ 15-16 with BP, which creates a healthy competition for fluorescent lamps sold in aquarium shops, but LED lighting has many more options. As an option, you can simulate sunsets / sunrises with RGB tape, and the main lighting with white tape. In general, the weight options.