Around the web I’ve seen a few “lucid dream masks”, some commercial products, some DIY projects. The basic idea is to flash light in your face while you’re in REM sleep. In the dreaming state you perceive this flashing and take it as a cue to help realize that you are in fact dreaming. The commercial products are unreasonably expensive, and all the hobby project immitations I could find seemed kind of flimsy: they either had no method to detect REM, or the REM detection methods were dubious. I decided to design my own.
The above image shows the (very) crude prototype I’m currently working with. The first big problem to solve was the mechanical design of the eye movement sensor. Other projects I’ve found use an infrared LED and a type of IR detector with integrated circuitry which outputs a logic level digital signal. This is the kind of sensor I don’t trust to work reliably: it seems to me the varying IR reflection from a closed eye is too subtle. I went with a bare photodiode sampled by an analog input on an ATmega168.
In the detailed photo of the sensor above, from left to right, are a visible red LED (for delivering the flashing cue), an IR LED with a sheath to narrow its output beam, and a photodiode. The sheathed emitter coupled with the wide area sensor gave me the best results i.e. the greatest variance in sensor value in response to a closed, moving eye. I’m actually amazed by how much variance there is; I suspect that a significant amount of IR is penetrating the eyelid and reflecting off the sclera.
With a sensor clearly able to detect movement of a closed eye, the next major objective is an algorithm which can reliably discern REM cycles as those raw values come in. In order to work out that algorithm I needed to be able to do a lot of trial and error experimentation, so I set up the mask to dump raw sensor values to my PC, and I logged the data for several nights’ sleep. I settled on a sampling routine in the microcontroller that takes about 30 voltage readings over a period of about 3 seconds, calculates the mean value, and then sums the absolute values of the differences of the individual readings and the mean. This is similar to calculating the variance of the 30 or so values, except the differences are not squared. This is done repeatedly, continuously, and these “variances” are the values analyzed to detect REM. The sequence of these values looks like this:
Now, that looks absolutely indecipherable, but it’s actually pretty good data. The analysis method is extremely simple. An “activity” integer value, clamped to a small range, in this case 0 to 7, is incremented or decremented on each sample depending on a threshold sample value. In this case, if a variance sample is greater than 150 then “activity” is incremented, else it’s decremented. When “activity” hits its maximum value (7) that indicates that REM has been detected. For the data shown, this method detects REM at 147 and 245 minutes, and that time interval agrees well with an average human’s sleep cycle. So this REM detection apparently works.
The final piece of the puzzle is the flashing light, and this I haven’t yet cracked. The only way to experiment with the flash signal is to actually sleep with the mask on, which means only one trial per day is possible. So far I haven’t succeeded in inducing lucid dreaming with this device, but I have succeeded in ruining a night’s sleep, repeatedly waking up to a flashing light just before dream cycles. At least that’s confirmation that the REM detection works.