If you happen to take melatonin prescribed by your doctor, then realize the following:

Take melatonin for about half an hour before going to bed and then turn the lights off and wait for it to take effect. 

Sleeping even in a dimly lit bedroom after taking melatonin may result in unpleasant, fragmented sleep.

Taking melatonin during the daytime may sensitize the eyes to damage from bright light.