U1 Arduino Pro Mini. I chose the Pro over the Nano
because I do not expect to be re-programming it and the USB interface
could not be justified. The programming pins are accessible if needed.
L1 128x64 OLED display with I2C interface to display the settings and the
progress. Header pins and sockets to suit. This model OLED
uses a different colour for the top few rows, and the code takes advantage
of this.
SW1 Momentary SPDT switch for up/down control. Salvaged from an old CD
drive. Two single pole momentary switches could also be used, but
the 'rocker' style of this switch is very easy to use.
SW2 Momentary SPST switch for reset. Salvaged from somewhere.
SW3 SPST On/Off switch. Salvaged from the PCB of some old piece of gear.
D1 LED and matched R1 resistor (eg 220ohm).
Hookup wire and prototype board (see below).
Q1 Small NPN power transistor. (Eg 2N2222) and resistor as required for
the load to be driven (eg 1k)
B1 9v Battery with clip and leads.
3D printed case.
The
switches can be anything suitable, but the height needs to be considered if
they are all mounted at the same level on the prototype board. The
'rocker' style switch used for the up/down adjustment has five pins but only
three connections - each pair of outer pins is the same side of the
switch.
The OLED display is a common, easily available item. For this project I mounted it using the header pins inserted into a matching header socket mounted to the breadboard. These displays are also available with an ISP interface - either would work for this project, but the extra speed of ISP is not required. The display sits below the cutout in the lid and is supported by the header pins and a small packing piece under the substrate. I avoided a more solid mount because of the risk of fracturing the delicate glass face plate.
The prototype board I used is marked 2-110 and is similar to this. It is actually designed for the Pro module to straddle the centre row, but as I am only using a few pins for the module it was easier to put it at the bottom of the board and leave space for the other components at the top.
The 9v battery power is provided via the on/off
switch to VRaw of the Pro. Vcc from the Pro is wired to the
OLED. The grounds of both devices are tied to battery ground.
The up/down switch for setting the timer period is connected to data pins 2
and 3 (active low) and the start/stop button is connected to data pin 5
(active low). Output to the transistor and the relay is at data
pin 8 There is no particular reason for choosing these pins -
any data pins would work as well. The OLED is driven from the standard
UNO/Pro SDA and SCL pins.
The
Pro has header pins soldered on two edges and for the programming pins, but
not across the fourth side as this would make things too crowded on the
prototype board. I soldered leads to the prototype boards before
soldering the Pro on, as with this particular board the traces to the header
pins are only available between the header rows. Although this makes things
a bit tricky it saves a lot of board space and is much easier than trying to
solder on the trace side of the board. I also soldered some leads to
some of the unused pin traces in case I wanted to add new features later
on. The hookup wire came from an old parallel printer cable.
This wire is easily tinned and soldered, the covering is very heat
resistant, it is quite flexible, and the multitude of colours means that the
wire can indicate the function of the connection, reducing the risk of
mistakes.
The case is a simple two-part assembly, with a lid that
sits down into the base without any attachment. The lid would be a good
candidate for a magnetic attachment. The base is divided into two
parts - one is a tight fit for the prototyping board and the other is a
large area for the battery. I did not divide this area because I might
want to install the relay, which currently swings freely at the end of a
wire, inside the case at some time in the future. Foam spacers can be used
to stop the battery sliding around. The relay lead exits the case
through a hole near the bottom left corner of the prototype board.
I printed knobs for the reset and power switches so
they would match the case, and added a small surround for the LED to make
it look a bit neater. I filled the mounting holes for the OLED with plugs,
after deciding that I did not want to screw the device down to the lid.
The completed unit, with the lid pushed down into the
base. When the unit is is turned on the interval between ticks can be
set using the momentary rocker switch - right to increase and left to
decrease. Timing is started and stopped with the large momentary
switch to the left of the display. If this is pressed when the timer is
running then the display is inverted to show that timing is paused.
The current interval and the number of ticks are displayed. If
start/stop is pressed again the count is cleared to 0 and timing starts.The timer uses a timer library with interrupts. There are several timer libraries available for the Arduino, so substituting a different one would not be a problem. The interrupt-handling routine breaks most of the rules for using interrupts, but as the time interval is completely controlled by the code it doesn't create a problem. The timing interval can be set from one second to 9999 seconds. To make this possible with a simple user interface acceleration is used - each time the interval is increased or decreased the rate of change is raised by a factor of 1.2. So holding the switch in one direction or the other gradually increases the rate at which the interval increases or decreases. The full range of 1 to 9999 takes about 15s. If the switch goes back to neutral the step is reset to 1, so that at any point the interval can be set to an accuracy of 1s by briefly flicking the switch.
Code is included to save the currently selected interval to EEProm so that it can be retrieved at startup and set as the default.
/**************************************************************************}
This page last update 18 August 2024