Introduction: Flux Lamp
For our electronics project, we worked on a lamp inspired by f.lux. Just as f.lux allows users to have different screen colors for day and night, our lamp gives people better control over their room lighting. Not only can users set the color temperature for both the day and the night, they can also control the brightness of the lamp. The light is also self-contained and allows users to set the time that they wake up and correct the built-in clock from a touchscreen.
Please note that we are not endorsed by the maker(s) of f.lux and that this is not an official f.lux product.
Step 1: Build the Circuit Board
First off, you will need to design and then print or build your circuit board. If you don't have access to a PCB printer, you may still want to use circuit design software to help you simplify your design. We used the free version of CadSoft EAGLE to design our board, which worked fine. While we couldn't use a PCB printer, our circuit is pretty simple and just build it ourselves. To replicate our design, you can use the diagram above. If you do have a PCB printer, we've also attached our files below so you can just print it out.
Once you've made the board, you will need to attach the following components to the board with solder:
- three TIP-120 semiconductors, with heat sinks clipped on
- three sets of 22-23-2041 molex connectors and receptacles
- three power resistors: two 12 Ω, one 15 Ω (do not connect yet - see the next step)
- a real-time clock, which consists of:
- a DS1307 IC
- a 32.768KHz crystal
- two 2.2 KΩ resistors
- a CR2032 coincell battery and corresponding battery holder
Step 2: Power the LED
The next step is to connect the LED to the circuit. We used a LZ4-20MC00 LED (note that the picture on the website is different from how the LED actually looks).
First, solder wires to each of the pads on the LED. Make sure the heatsink on the bottom of the LED is not touching a conductive surface or it may be difficult to sufficiently heat the soldering pads. You may find it helpful to color code your wires to help keep track of which wires correspond to which colors. The numbers on the LED correspond to individual colors as follows:
- 7 is the positive red terminal, 6 is the negative red terminal
- 1 and 5 are the positive green terminals, 8 and 4 are their corresponding negative terminals
- 3 is the positive blue terminal, 2 is the negative blue terminal
If you want to make a lamp that looks different from ours, make sure to leave the wires long enough. It is easier to bundle wires up a bit than to try to make everything reach when the wires are too short.
Next, crimp Molex pins onto the ends of the wires so they can be plugged into the Molex connectors on the circuit board. Then insert the pins into the connectors, being careful of the order - Green, Blue, Green, Red, (pins 1, 3, 5, 7) from left to right. The connector corresponding to the positive terminals on the LED should be attached to the receiver on the bottom of the circuit board. The connector corresponding to the negative terminals should be attached to the receiver on the upper left of the board. Note that the order of the negative pins does not matter as they will all be connected to ground.
To power this LED from a 12V source, you'll need 12Ω and 15Ω resistors. The ones we used have a heat sink chassis and are rated for up to 10W, so they can handle the current going through the LED. You won't actually mount these on the circuit board because they can get very hot. Instead, attach them to a large and effective heat sink. Connect the 15Ω resistor to the bottom TIP-120 for red and the two 12Ω resistors to the TIP-120s.
To power the LED, we included a jack to plug a 12V source into. We connected this jack to a plug to insert into our Arduino and we connected it to wires leading to the circuit board. The positive wire connects to the common end of the resistors (in the center of circuit board) and the negative / ground wire connects to the bottom of the upper left molex.
At this point you can connect a few more wires that will prepare you to connect the touchscreen. Connect two wires from the Arduino SCL pin to pin 5 of the RTC and to the SCL pin on the touchscreen. Likewise, connect two wired from the Arduino SDA pin to pin 6 of the RTC and to the SDA pin on the touchscreen. You will need to join wires together as you will not be able to insert two wires into each Arduino pin.
Step 3: Connect the Touchscreen
In our project, we used a 2.8" Capacitive Touchscreen Breakout Board w/MicroSD Socket from Adafruit. While about $10 more expensive than resistive touchscreens, capacitive touchscreens are better if using your finger (as opposed to a stylus), don't have to be calibrated, and are more familiar for most users. This particular touchscreen also comes with a MicroSD slot that allows you to read files from a MicroSD card. Since Arduinos aren't that powerful, we found it was faster to display an image from a MicroSD card than to generate it when needed. It is worth noting that while there is an Arduino shield version of this touchscreen, it costs more and interferes with connecting the LED and real-time clock to the Arduino. It also requires a compatible Arduino board and enough space in your enclosure for the Arduino to sit right behind the touchscreen.
Adafruit has a pretty good guide for connecting the touchscreen to your Arduino. For our project, we wired our touchscreen to use SPI to communicate with the Arduino. While the 8-bit mode is faster, it does not allow you to use the MicroSD card and may not be supported by the graphics library we used in this project (though Adafruit does provide their own library for it). As the guide points out, the best way to tell the touchscreen to use SPI (instead of 8-bit mode) is to solder 3 pins on the touchscreen. If you want to be able to access files on the MicroSD card, you will also need to connect an additional pin to your Arduino as described here.
Step 4: Program the Arduino
For the programming portion of our project, we wrote an Arduino program to:
- automatically adjust temperature and brightness of LED based on time of day
- let the user set the current hour and minute using the touchscreen and update the real-time clock
- display the current time on the main menu
- let the user specify when they wake up using the touchscreen
- let the user adjust the minimum and maximum color temperature and LED brightness using the touchscreen
- store the user's settings on the Arduino's EEPROM so they can be retrieved after the power is disconnected
Our code relies on the following libraries:
- the Adafruit GFX library (more info here)
- the Adafruit ILI9341 library (this is specific to the screen we used - slightly more info here)
- the ILI9341_due library (this added features to the Adafruit library and is significantly faster - more info here)
- the Adafruit FT6206 library (this is specific to the capacitive touchscreen we used - more info here)
- the SdFat library (more info here)
- the Adafruit RTClib (more info here)
- and a whole bunch of Arduino standard libraries (more info here)
Note that the ILI9341_due library is designed for the Arduino Due. While it runs pretty fast on Arduinos less powerful than the Due, it can still take up a lot of space depending on what functions you use. Unfortunately, this caused our code to require about 44KB of flash. This means it will only fit on the Arduino Due, Mega, and Zero. However, if you can modify our code to use a different graphics library, then it should fit on almost any Arduino (this would not be trivial, though).
If you'd like to use the code we wrote for our project, you can download the file attached below. Note that we connected the CS, D/C, and CCS pins on the touchscreen to different pins on the Arduino than the ones specified in the Adafruit guide (while the placement works well on the Uno, it is less convenient on the Mega). You can update which pins are used by the code by changing the CS_PIN, DC_PIN, and CCS_PIN variables found at around line 40. You will also need to download the special bitmap provided (which should be renamed to "colors.bmp"), copy it to a MicroSD card, and put the MicroSD card in the touchscreen for everything to work. Note that the preview of the image may look weird because of the special format we used (see the "Loading images from an SD card" section here).
We would like to thank Tanner Helland for developing code to convert color temperatures to RGB values, which saved us from having to parameterize this ourselves. You can find his post on the subject here.
Step 5: Create an Enclosure
For the last part of the project, you'll need an enclosure to hold all of your electronics. There are many ways you could do this, and you could design it however you want as long as there is a large enough heat sink for the LED and the power resistors. Ours turned out to not be quite big enough, given that anything metal became too hot to touch within an hour if the LED was on at full brightness.
For the base of the lamp, we used a piece of 4" acrylic tubing that we had on hand. We used a mill to drill screw holes to attach the touch screen, as well as the hole to insert the power jack. Once you have the bottom of your enclosure done you can insert the jack and finish soldering wires from the Arduino plug.
Since we had access to 3D printers, we were able to print the top part of our lamp (which consisted of a small LED diffuser and a globe). We designed these in Autodesk's 123D Design and have made our files available above, so you can print out a copy of your own. If using a 3D printer is not an option, you can probably find something something similar to our globe online or in a hardware store and could probably make a simple diffuser with paper and tape.