In this instructable, I'll be sharing details of this lighting system that I made for terrariums and aquariums. The photo above shows it being fitted to a foraging area for ants. My main objective was to mimic a complete day/night cycle so that I would be able to observe foraging patterns as well as behaviour. After working that out, I added a few more extra modes which I found to be helpful for observation as well as for display purposes. I
Since I'm focusing primarily on the lighting system, I will not be delving much into the construction of the terrarium itself. Housing the electronics will also be up to you depending on your enclosure type. The main focus will be on explaining the code and circuit so that you will be able to apply it to other projects.
I imagine that this lighting system could be scaled up and used as home lighting instead of just terrariums and aquariums. Also, this works with plants too as they grow just fine.
A write-up intended for antkeepers was posted here (http://www.formiculture.com/index.php/topic/2498-etherwulfs-foraging-area-lighting-system/#entry30874). This instructable will focus primarily on the technical aspects so any refer to that for myrmecological specifics.
- Lighting system is concealed entirely in the lid and can be fitted to a different foraging area easily
- 5050 RGB led strips allow for a wide variety of colours
- Simple UI. One button cycles through the modes.
- Arduino Pro Mini microprocessor used because of its low-cost and availability
- Different modes for observation and display (Warm white light, Day/night cycle, Responsive lighting with light sensor, Random smooth fading between colours)
- Bi-colour led indicates whether system is active
Step 1: Choose Your Tank/Container
If you don't already have an aquarium or tank ready, go and prepare one.
The one picture was decorated by adding a layer of grout/cement before layering it with fine sand and decorative items (seashells, rocks, etc). Once it's dried, everything will be held firmly in place.
Mine was prepared for ants so you might need to research your setup yourself.
Step 2: Gather Circuit Components
First of all, you will need to gather the components below to build the circuit.
- DS1307 RTC Module x1
- Arduino Pro Mini x1
- LDR x1
- 10K resistor x1
- Bicolor LED x 1(Red/Green)
- 220R resistor x1
- Common anode 12V 5050 RGB LED strips (You may use common cathode strips but you'll need to wire it differently)
- 12V power supply x1
- SPST Toggle switch x1
- Momentary push switch
- Female power connector (Check that it fits plug of the power supply)
- 2N3904 NPN transistors x3 *
- 51R resistor x3
*A word on transistor selection:
You'll need to choose a transistor that can handle the current draw of the LED strips. This is going to vary based on the length and type of strips. I used 2N3904 transistors paired with 51 ohm base resistors because the current draw of my LED strips were well below their maximum specifications. Check the datasheets to make sure that your transistors are capable of handling the current draw of your LED strips.
Regarding base resistors, you may check here (http://electronics.stackexchange.com/questions/83685/need-help-calculating-resistance-for-transistor-base) or the internet for more info.
Step 3: Constructing and Housing the Circuit
Here are a few notes on the circuit.
- S1 is a momentary push switch
- LED1, LED2, LED3 represent each of the leds in the RGB strip
- The RAW pin is connected in series with a toggle switch to 12V (not pictured)
- LED4 and LED5 represent the bi-color LED.
- The LDR is connected in a voltage divider with a 100K resistor. Consider changing the value of the 100k resistor to adjust sensitivity.
- I used a cheap DS1307 RTC module from ebay but those from adafruit and sparkfun will work too.
Regarding the physical construction, this is up to you. You may use a protoboard, strip board or just do point-to-point wiring like I did. How you do this will be be dependent on the enclosure for your circuit. I wanted to use a small enclosure so I had "compress" the circuit considerably.
The toggle switch is mounted together with the power socket on one side while the bicolor led and pushbutton is mounted on the other side.
- Notice the LDR in the picture. Remember to drill a hole in the lid for it!
- You should ensure that the programming headers on the Pro Mini are accessible so you can update the program easily
- Use electrical tape when necessary to avoid nasty shorts if you are using point-to-point wiring.
- Consider the order in which you solder your components. The switches, LED, and power jack were all screwed in first before soldering. This is very important when working with small enclosures.
- Drill a hole in the bottom so that you can insert the wires from the LED strips later
Step 4: Affix the LED Strips to the Lid
Peel off the strips and affix them to the underside of the lid of your tank/container. Then use hookup wire to solder the connections together. In the picture, some of my led strips were mislabelled so you may see red going to green, etc. Again, you'll have to check your own strips.
Carefully insert the leads into a hole in the lid and make sure that it lines up with the hole in your enclosure. After that, solder your leads to your circuit. Then, you'll be done with the hardware part.
Step 5: Understanding the Program
Download the program attached and open it up so you can reference it as I discuss each part.
The program switches cases upon the button being pushed. Hence, it advances the the next case whenever the button is pushed. When in case 0, the bicolor led is red to indicate that it is inactive. When the button is pushed and the mode changes, it flashes green and stays off.
1.) Warm white light
This is basically a straightforward warm white light.
2.) Day/Night Cycle
This must be my favourite mode out of all of them and the one I spent the most time on. Hence, I'll spend a bit of time breaking down how it works.But first, watch the accelerated video to get an idea of how it will work. The actual version simply stretches this out over 12 hours from 7.00 am to 7.00 pm.The system uses a real-time clock (RTC) module to keep time even when the power is off. This avoids complications with using a cycle based off circadian rhythms as it would mean that the user would have to turn on the system at an exact time in order for it to function properly.
First of all, the key problem I had to solve here was to ensure smooth transitioning between the colours as well as stretching them evenly over hourly periods. The tricky part was fading each led up and down between different values simultaneously while ensuring that the PWM values would be mapped to the seconds each hour.Also, it was necessary to make sure that adjustments to colours can be made easily. After messing about with the atmega328's internal timers to achieve a higher PWM resolution and using interrupts, I decided against that approach because I found it was unnecessary.
Eventually, I realised I was overthinking the whole thing and I managed to work out a far simpler and more effective approach. The program checks the time constantly and and calculates the difference in brightness between each LED. Then it updates each led with the PWM value that it should be at that point in the hour. It's rather hard for me to explain as the program makes a few small adjustments to keep the transition smooth. It'd be best to check the code attached for additional details.This approach basically allows the user to turn on the system at any time without affecting the day/night cycle.
After spending a fair bit of time watching timelapses of sunrises and sunsets, I decided on a color palette that replicates the process as accurately as I could get it.The cycle begins at 7.00 am in the morning and ends at 7.00 pm. It transitions between colour progressively through the day. It includes a total of five sequences, twilight, sunrise, noon, sunset, and dusk. After 7.00 pm, the system turns the lights red to mimic darkness for ants while allowing for continued observation at night.
If you are using this for an aquarium or terrarium, you may modify the 'night' phase to your liking. I imagine light blue would be nice but that's up to you.
3.) Responsive lighting
This mode adjust the light level based on ambient lighting so the brightness always remains at a comfortable value and isn't overly dim or dazzlingly bright. As it gets darker, the lighting gets darker as well. Change this to your liking.
An LDR is employed here in a voltage divider to measure the brightness of ambient light which is then used to calculate an appropriate brightness for the led strips. This is the mode I use most often when it's not in day/night cycle mode.
4.) Random RGB Fading
This mode crossfades between a random selection of colours smoothly. The LEDFader library is used here to smoothen out the fading process and it does look very nice indeed. This is shown in the video as well.
Step 6: Program the Arduino and Test!
Use a FTDI module like this one (https://www.sparkfun.com/products/9716) to program your Arduino Pro Mini. Plug it in and upload the code.
After that, connect your 12V power supply and turn on the main toggle switch. The red led should light to indicate that it is in standby mode. Press the button to cycle through the modes.
If everything is working, congratulate yourself on a job well done!
If you like this project, please favourite it and vote for me!