Many animals detect light because they have eyes that contain light receptors. Earthworms lack eyes, but they do have light receptors—called photoreceptors—on their skin.
Earthworm photoreceptors are located in nerve fibers in the skin. These nerve fibers are connected to special nerves called ganglia, which connect to an earthworm's version of a brain. The brain, called a ganglion, helps trigger chemical reactions to control the entire body of the worm.
Earthworms soon dry out and die if exposed to warmth and sunlight. They need to stay underground in moist dirt to survive. If any part of a worm is exposed to light as it tunnels, the worm is alerted through the photoreceptors and can quickly react to get back to safer ground.
Earthworm photoreceptors can detect the intensity of different colored lights. Earthworms move away from white or blue light, but they do not react to red light.