Getting an Arduino to 'sync' to a signal

Two things come to mind here.

  1. the pulsein function (see the reference)

  2. maybe even better use one of the pins that support an interrupt that will be triggered on every pin state change.