A swim timer for night swimmers

I swim with a triathlete group in an outdoor pool at 6AM three days a week. For half the year I can see stars when I start swimming. What I can’t see in the dark is the analog clock to check my pace on 100 meter laps.

To solve this problem I designed and built a portable digital timer with LED display. The 4-digit 7-segment display is large enough to see from 10 feet away so I can read it without stopping. The timer is encased in a transparent and waterproof polycarbonate tube so that I don’t have to worry about it getting wet or falling in the pool. In fact you can take it to the bottom of the pool and it won’t leak. Normally it just sits on the edge of the pool where I can see it.

There are a variety of LCD swim timers available that are fine for day swimmers. This timer is for night swimmers.

The electronics
Electronically the timer is very simple. The circuit has only three active components:

1. LP2950Z low-dropout 5V regulator
2. ATmega328P microcontroller (of Arduino fame). You need to buy one with a pre-programmed bootloader (for example) so that you can load the swim timer program from your computer.
3. Lumex LDQ-M516R1 4-digit seven segment LED common anode display.

The ATmega328 microcontroller takes care of all aspects of timing and display including driving the LEDs. Two toggle switches control the circuit. One switches battery power on and off, the other selects between two timing display modes. One mode displays total time since power-on in minutes and seconds. The other mode resets the display to zero for timing individual workout sets.

You could also build this timer with LEDs emitting colors other than red. I also tried a green LED which was easy to read in the dark. I found the red LED a little brighter and easier to read as the daylight increases.

The timer is powered by four AA batteries through a low-dropout LP2950Z regulator that maintains the voltage at or below 5Vdc. As the batteries are gradually depleted and the voltage drops below 5V, the low-dropout regulator only adds about 200mV additional drop.

I’ve reduced the crystal timebase for the ATmega328 from the typical 16 MHz to 8 MHz for two reasons. The first is that the low clock rate significantly reduces the power used by the microcontroller. Although about 80% of the power draw for the circuit is for driving the LEDs, I like to save power where I can.

The second reason is that the microcontroller running at 8 MHz will operate below 2.7Vdc. At that voltage the current drive through the LEDs should be so low that the display will be fading and difficult to read. This means I will replace the batteries long before the timer quits operating. I compute the current design should operate for at least 100 hours on a set of batteries. That gives me half a year of operation at 4 hours of swimming per week.

A six-pin male header lets me program the device in-circuit from a USB port on my computer with the proper interface cable. To do this I have to change the 8 MHz crystal to a 16 MHz crystal. For that reason I have mounted the crystal in a socket for easy swapping. The other alternative is to remove the ATmega328P from its socket, program it elsewhere (such as in an Arduino board that sockets the device), and then replace it.

During initial software development I just left the 16 MHz crystal installed. There is only one line of code that has to change when changing the crystal to or from 8 MHz to make one second of time the correct length. Otherwise you’ll see two seconds instead of one when using the 8 MHz crystal.


Because the timer uses the same ATmega328P used on an Arduino, I developed the program on the free and easy to use Arduino integrated development environment. For programming this device you select the board type that corresponds to the bootloader on your ATmega328 device. Typically that will be anĀ  Arduino Uno or Duemilanove or Nano w/ ATmega328 on the board selection list. You can download the code I used here.

Here’s what the code does

After dividing down the millisecond clock on the ATmega328 to one second, it performs the appropriate division for each digit. For example, the 10 second digit would be:

tenSeconds = (timeSeconds % 60) / 10;
Where the % signifies modulo division. This causes the 10 second digit to count from zero to 5 and repeat. All the other digits count from 0 to 9.

After computing all four digits it translates that information into which segments are illuminated for each digit. Finally the code drives the multiplexed display illuminating appropriate segments.

The mode switch code reads a digital input line and adds control logic to switch between two different zero-time references for total time and timing a workout set.

The complete program listing is available here.

Really waterproof

This project differs from most simple electronic projects in that I wanted the entire device to be absolutely waterproof. Although this timer is meant to sit on the edge of the pool, it can easily get knocked into the pool and it is splashed regularly. In cold weather the clear polycarbonate tube sometimes fogs up and I usually defog it by throwing a handful of water on it. I didn’t want to worry about the electronics getting wet.

To use this timer I needed two switches accessible from the outside. I also needed to see the LED display yet protect it from water. That led me to a design where the entire system is housed in a waterproof case made from a polycarbonate tube with acetal (a type of plastic) end caps. The two end caps are sealed with the polycarbonate tube by using two O-rings (the black rings in the photos). Only the switches need to penetrate the end caps.

Although you can buy waterproof switches, they are much more expensive. Even when switches are waterproof, the switch mounting provides another source of potential leaks where the switch penetrates the panel. I chose to seal the switches inside a waterproof enclosure and only have two stainless steel shafts exposed to water. The shafts each have their own O-ring seals.

The photo shows the knob for a switch on the right side of the end cap. A 1/8 inch shaft connected to the knob penetrates the end cap through an O-ring seal (not visible inside the end cap) and connects to a switch arm on the left side of the end cap. A set screw on the arm locks the arm to the shaft. A hole in the other end of the switch arm surrounds an ordinary mini-toggle switch lever. The shaft is located in line with the toggle switch pivot so that rotating the knob moves the toggle switch lever.

The switches are mounted on a “T”-shaped sheet metal piece that is bent to a 90 degree angle and screwed to the end cap. Because the toggle switches are housed in a waterproof case, I can use ordinary inexpensive toggle switches.

The two switch knobs have a different appearance and tactile feel to help avoid turning the wrong switch in the dark.

code listing