Dimming the wordclock

I just tried if it is possible to use one of the PWM pins of the Arduino to dim the LEDs if I want to. Short answer: yes and no. Now  for the longer answer.

I connected one of the shift registers with the Arduino. But instead of connecting the other pin of the LEDs with GND, I connected them to one of the PWM pins of the Arduino.

Since it currently seems to be impossible to embed a YouTube video without it loading tracking scripts the video can only be viewed directly on YouTube.

So, it works. I can control which LEDs are lit with the shift registers, and I can control how bright they are with the PWM pin. The only downside: I can only dim all of them at once, so no fading in and out of single words. The only way to do that would be to connect the relevant groups to different PWM pins. I guess I’ll have to give that some thought.

What I can do right now, is dimming them according to ambient light. When I connect a photoresistor to one of the analog ins I can detect the light level and make the clock brighter when the room is lit and dim it when the room becomes dark.

Here is the source code I used:

int ledPin = 9;    // LED connected to digital pin 9
// shift register stuff
const int g_pinCommLatch = 40;
const int g_pinData = 41;
const int g_pinClock = 42;
const int g_registers = 1;
byte g_registerArray[g_registers];
// Simple function to send serial data to one or more shift registers by iterating backwards through an array.
// Although g_registers exists, they may not all be being used, hence the input parameter.
void sendSerialData (
  byte registerCount,  // How many shift registers?
  byte *pValueArray)   // Array of bytes with LSByte in array [0]
  // Signal to the 595s to listen for data
  digitalWrite (g_pinCommLatch, LOW);
  for (byte reg = registerCount; reg > 0; reg--) {
    byte value = pValueArray [reg - 1];
    for (byte bitMask = 128; bitMask > 0; bitMask >>= 1) {
      digitalWrite(g_pinClock, LOW);
      digitalWrite(g_pinData, value & bitMask ? HIGH : LOW);
      digitalWrite(g_pinClock, HIGH);
  // Signal to the 595s that I'm done sending
  digitalWrite (g_pinCommLatch, HIGH);
}  // sendSerialData
void setup()
  pinMode (g_pinCommLatch, OUTPUT);
  pinMode (g_pinClock, OUTPUT);
  pinMode (g_pinData, OUTPUT);
  g_registerArray[0] = 254;
  sendSerialData (g_registers, g_registerArray);
} // setup
int c = 2;
void loop()
  g_registerArray[0] = c;
  sendSerialData (g_registers, g_registerArray);
  c *= 2;
  if (c > 128) {
    c = 2;
  // fade in from min to max in increments of 5 points:
  for(int fadeValue = 0 ; fadeValue = 0; fadeValue -=5) { 
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect    
} // loop

Published by


Diplom-Informatiker (DH) in Darmstadt. Ich blogge über Entwicklung, Internet, mobile Geräte und Virtualisierung. Meine Beiträge gibt es auch bei Google+ und Facebook.

2 thoughts on “Dimming the wordclock”

  1. Hi Gerald,
    For a nice effect you can use a IR sensor to enable “gesture control” to regulate the dimming of the clock display.
    I use a Sharp (4 cm to 30 cm) GP2D120 IR range sensor as input for a menu structure (30 cm = jump menu items, 5 to 20 cm = options like set clock hour/minute/AMPM, force DCF77,…).
    Best regards,


Leave a Reply

Your email address will not be published. Required fields are marked *