The pineal gland is a tiny endocrine gland found in the brain. It produces and secretes the hormone melatonin, which is a hormone that helps regulate biological rhythms such as sleep and wake cycles. The secretion of melatonin is inhibited by light and triggered by darkness.
The responses generated by the pineal Gland and its secretions make it the biological clock of the body.
it regulates the melatonin production in your body via the amount of light detected by your retina. when it's dark the gland releases the melatonin which lets your body go to sleep.