Sleep is very important for the health. Analyzing the polysomnography (PSG) helps us get valuable information to assess the quality of sleep. In this work, we develop a program to automatically detect the transition from wakefulness to sleep in adults. The accurate detection of the point of sleep onset occurs in the first time is useful for assessing the micro-structure of sleep. The proposed method is analyzed polysomnography of 30 healthy volunteers, using data of one channel Electroencephalography, Electrooculography and chin Electromyography. The algorithm automatically analyzes every second according to American Academy of Sleep Medicine (AASM) standards with the latest version. The results obtained under two levels: identify and list the epoch occurred the transition, and exact the time of the shift occurred. With more than 85% in accuracy, the study shows the feasibility to provide timely warning. This approach opens up developing a system in real-time warning: doze off in student, drowsiness, sleepiness when driving or working. It helps us to examine the brain's response to external stimuli to reduce the time of sleep latency.