There are two ways (modes):
Mode 1 is very simplistic, it is a program that delivers flashes every 90 minutes (if you examine the code you can see it's a bit finetuned) hoping that it will coincide with your REM state. Unfortunately REM cycles differ from night to night making it very unreliable.
Mode 2 uses an amazing app for the iPhone called The Singularity Experience that integrates timing of your sleep cycles (similar to mode 1) and movement via the accelerometer of the device (in REM state you sleep still due to sleep paralysis ) providing a very good determination of the sleep state as experienced by the developer in comparison to a Zeo band. The app iluminates the iPhone screen when you are in REM and via a LDR the arduino gets the trigger signal to deliver the flashes through my bedside lamp.