I have recently converted my aquarium lights from fluorescent lighting to LED lighting and I have decided to try and simulate a natural environment where light gradually increase from dawn till midday and then decrease till dusk. At night there's little light usually given by the moon.
Basically the LED lighting is powered from a 12V power supply and arduino controls the intensity of the light by modulating the voltage with the help of a n-channel MOSFET (I have used an IRFS630). The arduino can be powered by the same power supply but I have used a separated 5V USB PS for arduino and powered it through USB not through Vin.
The light intensity might not be the most accurate but it's the best I could think of. The pattern can be modified through the code.
Step 1: Parts Needed
First thing first gather all the parts needed for the project. I assume you already have a LED lighting that you want to play with, maybe an aquarium lighting, maybe something else, maybe not even LEDs but something that supports dimming.
So here's the list of the parts I used:
1. Arduino nano - 1 pcs
2. LCD 1602 display - 1 pcs
3. IIC/I2C adapter for LCD 1602 - 1 pcs
4. DS1302 RTC - 1 pcs (with CR2032 battery)
5. push button with cover - 1 pcs
6. n-channel MOSFET (I used a IRFS630) - 1 pcs
7. 10K ohm resistor - 1 pcs
8. Optional - some people say that you must use a resistor between arduino pwm pin and the gate of the MOSFET to protect the aruino, other people say you don't, at least not for low power applications, I have used none and it works just fine, way below 20mA drawn from arduino's pin, but if you want to you can use a 100 ohm resistor.
UPDATE: After 2 months of testing I have come to the conclusion that the 100 ohm is a must! the arduino kept blocking without it, randomly. Now it works perfectly.
You will also need soldering tools for soldering the I2C adapter to the LCD and if you want to make it like I did on a prototype board or on a PCB. I used header pins to connect the arduino because this gives me freedom to extract the arduino, program it and put it back on (and it's easier to replace it).
9. Optional - prototype board / PCB
10. Optional - header pins - with 15 pins or more each - 2 pcs (needed to connect arduino nano to the board)
That's about it, now let's get to work!
Step 2: Putting Things Together
First you must solder the IIC/I2C adapter with the LCD 1602 (also works with other LCDs like 2004). Use the schematic provided to do so.
Now if you want to use a breadboard just follow the schematic and make sure that only the grounding is common for the LED power supply and the arduino power supply if you use a 5V PS for arduino (on USB cable), otherwise you can link the same PS through the Vin pin of the arduino.
If you want to use a PCB or a prototype board just follow the schematic to link components, the design it's up to you, just make sure to double check the links in the end.
On the I2C adapter, opposite to the power and data pins there's a jumper, this jumper supplies power to the LCD back light, with it on the LCD light stays on continuously. Connect the push button here to only illuminate it when needed. You can use other types of buttons or switches if you want.
I have also included the fritzing schematic.
PS = Power Supply (if any one was wondering)
PCB = Printed Circuit Board
Step 3: Put Some Code Into the MCU
I have attached the .ino file and the two libraries I have used so there will be no incompatibility. The code is explained inside the .ino file.
Also for the I2C display's address you can use the attached i2c-scanner.ino to find it out.
Any comments or suggestions are welcome. Have fun!