Adding a Dimmer to Your DOTKLOK

by solarmax in Circuits > LEDs

4561 Views, 9 Favorites, 0 Comments

Adding a Dimmer to Your DOTKLOK

DOTKLOK_20110330_Photoresistor 019.JPG
DOTKLOK_20110330_Photoresistor 028.JPG
DOTKLOK_20110330_Photoresistor 044.JPG
screenshot.8.jpg
I love my new home-built DOTKLOK (http://aomalley.org/dotklok/), but at night, that darn clock is too bight.  I decided to add a photoresistor, also called a photocell, as a dimmer and hack the 'KLOK a little. Photoresistors are basically resistors that change their resistance based on the amount of light that hits it's face.  They are very inexpensive and easy to incorporate into projects.

Open the DOTKLOK

DOTKLOK_20110330_Photoresistor 027.JPG
DOTKLOK_20110330_Photoresistor 028.JPG
Unplug your DOKKLOK from the power source and get a soft cloth for your work surface.  A microfiber cloth would be best, but here I'm using a clean bath towel.  

Un-screw the screws and nuts on the DOTKLOK case and lay it out on a soft cloth so you don't scratch the surfaces of the acrylic faces.  

You'll then want to carefully remove the SURE LED Matrix.  Mark the plug and socket so you know how to hook it up again.  Then, unplug it from the main board.  Set it aside for now.  

Prototyping the Photo-resistor on the Arduino

DOTKLOK_20110330_Photoresistor 028.JPG
With the LED Matrix removed, I spent some time with a prototyping Breadboard Arduino from Dale Wheat at http://www.dalewheat.com/store/ and some code from @ladyada at http://www.ladyada.net/learn/sensors/cds.html to work out how to incorporate the photo-resistor into the board.

Note: Not all photo-resistors are created equal and you may have to fool around with the settings to get it to work with your configuration. 

Simple Schematic

screenshot.8.jpg
The circuit is very simple.  The DOTKLOK board includes a 'hackable' prototyping area with pinouts for the Arduino's A0-A3, D2-D3, and D12-D13...along with corresponding GND and 5V holes.  

After prototyping the photoresistor on the breadboard, I determined that a 1K resistor would work best.  So, looking at the available pins, I'll be using Analog-0 to read the value of the photoresistor.  

If you're looking for a good tutorial on adding photoresistor to your Arduino project, check out @ladyada's site at http://www.ladyada.net/learn/sensors/cds.html.

Attach Pull-down Resistor to the Photoresistor

DOTKLOK_20110330_Photoresistor 030.JPG
screenshot.8.jpg
Because there are limited pinouts on the DOTKLOK board, I decided to add the pull-down resistor to the photoresistor directly.  I like to use shrink-wrap tubing to keeps things neat and to keep the leads from touching.    

More Shrink-wrap Tubing

DOTKLOK_20110330_Photoresistor 032.JPG
DOTKLOK_20110330_Photoresistor 036.JPG
screenshot.8.jpg
Add more shrink-wrap tubing to make it as neat as possible.  Use a heat-gun to shrink the tubing when it is all in place.  Now there are three leads.  One for one side of the photoresistor by itself (to 5V), one lead for the resistor itself (to GND), and one lead that includes both the 1K resistor and the photoresistor (to Analog-0).

Attach Ribbon Cable

DOTKLOK_20110330_Photoresistor 038.JPG
DOTKLOK_20110330_Photoresistor 040.JPG
I found some solid-conductor ribbon cable laying around the shop and I pulled off three conductors. I stripped the ends and added more shrink-wrap tubing to each conductor.  Then, I soldered the leads to the ribbon cable. Using the heat-gun, shrink the tubing around the newly soldered conductors.  Remember to add the shrink-wrap tubing BEFORE you solder the conductors to the leads of the photoresistor.  You only forget once and then you always remember to do it first.  

Bendy Ribbon-Cable

DOTKLOK_20110330_Photoresistor 040.JPG
DOTKLOK_20110330_Photoresistor 041.JPG
Bend the ribbon-cable around the board and place the photoresistor near the top of the DOTKLOK.  Make sure the correct leads are arranged at the correct terminals. 

Solder It In

DOTKLOK_20110330_Photoresistor 044.JPG
Solder the correct leads to A0, GND, and 5V.  It's now time to close your DOTKLOK back up.  Connect up the LED Matrix and attach it back the way it was originally.

Modify the Code - Add the Brightness Function

ht1632.jpg
Now that the photoresistor is installed in the DOTKLOK and the hardware is put back together, it's time to add some code to tell the LED Matrix to dim according to the value received on pin A0.  The first modification is to the HT1632.pde file.  Here you need to add the brightness function.  The raw reading from A0 (0-1024) will be converted, or mapped, to the value expected by the HT1632 driver (0-15).  So, the function will receive a passed integer called intensity that will have a value of 0-15.  I added some code to increase the intensity at high levels, and decrease it a really low levels.  

Define the Global Variables

screenshot.4.jpg
Next, we'll define two global variables.  In the dotklok_rev_1_2.pde file, add the two lines included in the photo below.  One for the pin to read the value, and the other for the value itself.  

Modify the Code - Read the Value

screenshot.7.jpg
Next, we need to read the value of the photoresistor and call the brightness function to change the brightness of the LED Matrix.  You can see the 'map' function used to map the analog value to the 0 - 15 value expected by the HT1632 driver.  

These two lines of code will need to be added at the bottom of the do-while loop of each animation in time_animations.pde.

Load the Code and Test It Out

Follow the instructions to reload the code to the DOTKLOK's ATMEGA328P processor and then test it out.  Here is mine: