Skip to content

Digital clock code for Arduino Nano and Nano 33 IoT, to drive nixie or LED matrix displays

License

Notifications You must be signed in to change notification settings

clockspot/arduino-clock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

arduino-nixie

Nixie clocks

A digital clock for the Arduino Nano and a nixie tube display.

  • Features perpetual calendar with day counter/sunrise/sunset, alarm with skip/snooze, and chrono/timer.
  • Supports four- or six-digit displays of Nixie tubes multiplexed in pairs via two SN74141 driver chips.
  • Can do auto DST change, tube shutoff, and chimes, and can control PWM LEDs, piezo beeper, and/or relay.
  • Timekeeping requires a DS3231 real-time clock via I2C, which is battery-backed and thermocompensated.
  • Written for RLB Designs’ Universal Nixie Driver Board (UNDB), with LED control for v8+ and relay for v9+.

The latest release can be downloaded here. Skip to Hardware Configuration for details on tweaking the sketch.

Operating instructions, v1.7+

The clock displays its software version when powered up (as of v1.6). Instructions for earlier versions are here.

Time of day

The time of day can be set to show in 12h or 24h format, but when setting, it is shown in 24h so you can tell AM from PM. When exiting setting, seconds will reset to zero, unless the time was not changed.

Calendar

The calendar cycles through several displays, before returning to the time of day:

  • The date. Several formats are available. When setting, it will ask for the year, then the month, then the date.
  • Day counter. This will count down to, or up from, a date of your choice, repeating every year. When setting, it will ask for the month, then the date, then the direction (0 = count down, 1 = count up).
    • TIP: To display the day of the year, set it to count up from December 31.
  • Sunrise/sunset. These two displays show the previous and next apparent sunrise/sunset times (indicated by 1 or 0 on the seconds tubes – during the day, it shows sunrise then sunset; at night, sunset then sunrise), in the same 12h/24h format as the time of day.
    • Specify your latitude, longitude, and UTC offset in the options menu. (From v1.8.1, sunrise/sunset is not displayed if latitude/longitude are left at 0.)
    • NOTE: At this writing, the times may be incorrect by a few minutes, depending on your longitude and time of year. I believe this to be a rounding error(s) in the Dusk2Dawn library (compared to the NOAA Solar Calculator it’s based on) and plan to investigate.

Alarm

The alarm is always shown in 24h format so you can tell AM from PM.

  • Use Up/Down to switch the alarm between on, skip, and off (indicated by 1/01/0 on the seconds tubes, and/or high/medium/low beeps).
    • If your clock has an Alt button and it’s set as the alarm preset, it will switch the alarm as well – so you can check and switch it with a few presses of a single button.
  • Skip silences the next alarm in advance – useful if you’re taking a day off, or you wake up before your alarm. You can set the alarm to skip automatically during the work week or on weekends – and when this is active, you can also unskip the next alarm by simply switching it back on.
  • When the alarm sounds, press any button – once to snooze, and again to cancel the snooze / silence the alarm for the day (it will give a short low beep, and the display will blink once).
    • In Fibonacci mode, snooze will not take effect; any button press will silence the alarm for the day, even if the set alarm time hasn’t been reached yet.

Hardware variations

  • If your clock has a switched relay and the alarm is set to use it, it will work like a clock radio, and switch on for two hours. In this case, the Alt button will “switch off” the relay immediately, without triggering snooze (as the other buttons will still do).

Chrono/Timer

This feature can count up (chrono) or down (timer), up to 100 hours each way. When idle, it displays 0 (or if you have leading zeros enabled, 000000).

  • To start and stop, press Up.
    • When at 0, this will start the chrono.
    • While the chrono is running, Down will briefly display a lap time.
  • To reset to 0, press Down when stopped.
  • To set the timer, hold Select. It will prompt for hours/minutes first, then seconds. For convenience, it will recall the last-used time – to reuse this time, simply press Select twice. Once the timer is set, press Up to start it.
    • While the timer is running, Down will cycle through the runout options (what the timer will do when it runs out – clocks with beeper only):
      • 1 beep: simply stop, with a long signal (default)
      • 2 beeps: restart, with a short signal (makes a great interval timer!)
      • 3 beeps: start the chrono, with a long signal
      • 4 beeps: start the chrono, with a short signal
  • When the timer signal sounds, press any button to silence it.
  • You can switch displays while the chrono/timer is running, and it will continue to run in the background. It will reset to 0 if you switch displays while it’s stopped, if it’s stopped for an hour, if the chrono reaches 100 hours, or if power is lost.

Hardware variations

  • If your clock has a switched relay and the chrono/timer is set to use it, it will switch on while the timer is running, like the “sleep” function on a clock radio. The runout options will still work, but won’t signal.
  • If your clock does not have a beeper, the runout options cannot be set.
  • If your clock uses a rotary encoder for Up/Down rather than buttons, Down will stop the chrono/timer, and Up will display lap times (chrono) and cycle through runout options (timer).

The Alt button

  • If your clock has an Alt button, it typically works as a preset button. While viewing the display you want quick access to (such as the alarm or chrono/timer), hold Alt until it beeps and the display blinks once; then you can use Alt to jump straight there.
    • TIP: If Alt is set as the alarm preset, it will switch the alarm as well – so you can check and switch it with a few presses of a single button.

Hardware variation

  • If your clock has a switched relay with soft power switch enabled, Alt acts as that switch, like the power button on a clock radio. This is why, if the alarm is set to use the relay as well, Alt will “switch off” the alarm without triggering snooze.

Options menu

  • To enter the options menu, hold Select for 3 seconds until you see a single 1 on the hour tubes. This indicates option number 1.
  • Use Up/Down to go to the option number you want to set (see table below); press Select to open it for setting (display will blink); use Up/Down to set; and Select to save.
  • When all done, hold Select to exit the options menu.
Option Settings
General
1 Time format 1 = 12-hour
2 = 24-hour
(time-of-day display only; setting times is always done in 24h)
2 Date format 1 = month/date/weekday
2 = date/month/weekday
3 = month/date/year
4 = date/month/year
5 = year/month/date
The weekday is displayed as a number from 0 (Sunday) to 6 (Saturday).
Four-tube clocks will display only the first two values in each of these options.
3 Display date during time? 0 = never
1 = date instead of seconds
2 = full date each minute at :30 seconds
3 = same as 2, but scrolls in and out
4 Leading zeros 0 = no
1 = yes
5 Digit fade 0–20 (in hundredths of a second)
6 Auto DST Add 1h for daylight saving time between these dates (at 2am):
0 = off
1 = second Sunday in March to first Sunday in November (US/CA)
2 = last Sunday in March to last Sunday in October (UK/EU)
3 = first Sunday in April to last Sunday in October (MX)
4 = last Sunday in September to first Sunday in April (NZ)
5 = first Sunday in October to first Sunday in April (AU)
6 = third Sunday in October to third Sunday in February (BZ)
If the clock is not powered at the time, it will correct itself when powered up.
If you observe DST but your locale’s rules are not represented here, leave this set to 0 and set the clock manually (and the DST offset if applicable).
7 LED behavior 0 = always off
1 = always on
2 = on, but follow night/away shutoff if enabled
3 = off, but on when alarm/timer sounds
4 = off, but on with switched relay (if equipped)
(Clocks with LED lighting only)
8 Anti-cathode poisoning Briefly cycles all digits to prevent cathode poisoning
0 = once a day, either at midnight or when night shutoff starts (if enabled)
1 = at the top of every hour
2 = at the top of every minute
(Will not trigger during night/away shutoff)
Alarm
10 Alarm auto-skip 0 = alarm triggers every day
1 = work week only, skipping weekends (per settings below)
2 = weekend only, skipping work week
11 Alarm signal 0 = beeper (uses pitch and pattern below)
1 = relay (if in switch mode, will stay on for 2 hours)
(Clocks with both beeper and relay only)
12 Alarm beeper pitch Note number, from 49 (A4) to 88 (C8).
(Clocks with beeper only)
13 Alarm beeper pattern 0 = long (1/2-second beep)
1 = short (1/4-second beep)
2 = double (two 1/8-second beeps)
3 = triple (three 1/12-second beeps)
4 = quad (four 1/16-second beeps)
5 = cuckoo (two 1/8-second beeps, descending major third)
(Clocks with beeper only)
14 Alarm snooze 0–60 minutes. 0 disables snooze.
15 Fibonacci mode 0 = off
1 = on
To wake you more gradually, the alarm will start about 27 minutes early, by beeping at increasingly shorter intervals per the Fibonacci sequence (610 seconds, then 337, then 233...). In this mode, snooze does not take effect; any button press will silence the alarm for the day, even if the set alarm time hasn’t been reached yet. Has no effect when alarm is set to use switched relay.
(Clocks with beeper and/or pulse relay only)
Chrono/Timer
21 Timer signal 0 = beeper (uses pitch and pattern below)
1 = relay (if in switch mode, will stay on until timer runs down)
(Clocks with both beeper and relay only)
22 Timer beeper pitch Note number, from 49 (A4) to 88 (C8).
(Clocks with beeper only)
23 Timer beeper pattern Same options as alarm beeper pattern.
(Clocks with beeper only)
Chime
30 Chime Make noise on the hour:
0 = off
1 = single pulse
2 = the pips (overrides pitch and pattern settings)
3 = pulse the hour (1 to 12)
4 = ship’s bell (hour and half hour)
Will not sound during night/away shutoff (except when off starts at top of hour)
(Clocks with beeper or pulse relay only)
31 Chime signal 0 = beeper (uses pitch and pattern below)
1 = relay
(Clocks with both beeper and pulse relay only)
32 Chime beeper pitch Note number, from 49 (A4) to 88 (C8).
(Clocks with beeper only)
33 Chime beeper pattern Same options as alarm beeper pattern. Cuckoo recommended!
(Clocks with beeper only)
Night/away shutoff
40 Night shutoff To save tube life and/or preserve your sleep, dim or shut off tubes nightly when you’re not around or sleeping.
0 = none (tubes fully on at night)
1 = dim tubes at night
2 = shut off tubes at night
When off, you can press Select to illuminate the tubes briefly.
41 Night starts at Time of day.
42 Night ends at Time of day. Set to 0:00 to use the alarm time.
43 Away shutoff To further save tube life, shut off tubes during daytime hours when you’re not around. This feature is designed to accommodate your work schedule.
0 = none (tubes on all day every day, except for night shutoff)
1 = clock at work (shut off all day on weekends)
2 = clock at home (shut off during work hours only)
When off, you can press Select to illuminate the tubes briefly.
44 First day of work week 0–6 (Sunday–Saturday)
45 Last day of work week 0–6 (Sunday–Saturday)
46 Work starts at Time of day.
47 Work ends at Time of day.
Geography
50 Latitude Your latitude, in tenths of a degree; negative (south) values are indicated with leading zeroes. (Example: Dallas is at 32.8°N, set as 328.)
51 Longitude Your longitude, in tenths of a degree; negative (west) values are indicated with leading zeroes. (Example: Dallas is at 96.7°W, set as 00967.)
52 UTC offset Your time zone’s offset from UTC (non-DST), in hours and minutes; negative (west) values are indicated with leading zeroes. (Example: Dallas is UTC–6, set as 0600.)
If you observe DST but set the clock manually rather than using the auto DST feature, you must add an hour to the UTC offset during DST, or the sunrise/sunset times will be an hour early.

To reset the clock to “factory” defaults, hold Select while powering up the clock.

Hardware configuration

A number of hardware-related settings are specified in config files, so you can easily maintain multiple clocks with different hardware, by including the correct config file at the top of the sketch before compiling.

These settings include:

  • Number of digits in the display module. Default is 6; small display adjustments are made for 4-tube clocks.
  • Which functions are enabled (calendar, alarm, etc).
  • Which pins are associated with the inputs (controls) and outputs (displays and signals).
    • If your clock includes LED backlighting (e.g. UNDB v8+), specifying an LED pin will enable the LED-related options in the options menu. LEDs should be connected to a PWM pin.
  • What type of Up/Down controls are equipped: pushbuttons (default) or rotary encoder (TBD).
  • What type of signal outputs are equipped: a piezo beeper (default) and/or a relay.
    • Signal duration (default 3min) and piezo pulse duration (default 500ms)
    • If your clock includes a relay (e.g. UNDB v9+), specifying a relay pin will enable the relay-related options in the options menu. You can also specify the relay mode:
      • In switched mode (default), the relay will be switched to control an appliance like a radio or lamp. If used with timer, it will switch on while timer is running (like the “sleep” function on a clock radio). If used with alarm, it will switch on when alarm trips and stay on for relay switch duration (default 2 hours). In this case, the Alt button (if equipped) will shut it off immediately, skipping snooze. This mode also enables the option for the LED backlighting, if equipped, to switch with the relay (great for a radio!).
      • In pulse mode, the relay will be pulsed, like the beeper is, to control an intermittent signaling device like a solenoid or indicator lamp; specify relay pulse duration (default 200ms).
  • Soft alarm switch enabled: default is yes; it is switched with Up (on) and Down (off) while viewing the alarm time. Change to no if the signal output/appliance has its own switch on this relay circuit; the software alarm will be permanently on.
  • Soft power switch enabled (switched relay only): default is yes; appliance can be toggled on/off with Alt. Change to no if the appliance has its own power switch (independent of this relay circuit) or does not need to be manually switched. (If set to no, or not using a switched relay, Alt acts as a function preset, as above.)
  • Various other durations for things like scrolling speed, set function/display timeouts, short and long button holds, “hold to set faster” thresholds, etc.

You can also set the defaults for the options menu (in main code, currently) to better suit the clock’s intended use.

Compiling the sketch

To compile the sketch, ensure these libraries are added and enabled in your Arduino IDE, via the Library Manager:

To upload the sketch to your clock, if it doesn’t appear in the IDE’s Ports menu (as a USB port), your UNDB may be equipped with an Arduino clone that requires drivers for the CH340 chipset.