A controller for a relay controls the pull-in time of the armature of the relay by controlling the power applied to the relay coil. To determine the actual pull-in time, the time of closure of the contacts is sensed and the time at which power is applied to the coil is subtracted from it. The actual pull-in time is then compared with a stored value of ideal pull-in time to produce an error signal. The error signal corrects the level of power applied to the relay coil upon the next actuation of the relay, to make the actual pull-in time approximately equal to the ideal pull-in time. In some embodiments to control the level of power on the coil, a Gray-code counter samples a duty-cycle register in a micro-computer and produces a train of pulses that is filtered to provide a DC control signal. The DC control signal controls the duty cycle of a pulse-width-modulated oscillator that rapidly switches (modulates) the power to the relay coil.