Populations of artificial organisms live in an environment in which light is cyclically present (day) or absent (night). Since being active during night is non-adaptive (activity consumes energy which is not compensated by the food found at night) the organisms evolve a sleep/wake behavioral pattern of being active during daytime and sleeping during nighttime. When the population moves to a different environment that contains "caves", they have to get out of a cave although the dark conditions of the cave may tend to induce sleep. We study various solutions to these problems: evolving a light sensor, evolving a biological clock, evolving both a light sensor and a biological clock. The best solution appears to be evolving a light sensor that modulates a biological clock, a solution which may also be appropriate to solve other problems such as adapting to seasonal changes in daytime length.