Animals have developed the ability to sense the water content in their habitats, including hygrosensation (sensing humidity in the air) and hydrosensation (sensing the water content in other microenvironments), and they display preferences for specific water contents that influence their mating, reproduction and geographic distribution. We developed and employed four quantitative behavioural test paradigms to investigate the molecular and cellular mechanisms underlying sensing the water content in an agar substrate (hydrosensation) and hydrotaxis in Caenorhabditis elegans. By combining a reverse genetic screen with genetic manipulation, optogenetic neuronal manipulation and in vivo Ca(2+) imaging, we demonstrate that adult worms avoid the wetter areas of agar plates and hypo-osmotic water droplets. We found that the cGMP signalling pathway in ciliated sensory neurons is involved in hydrosensation and hydrotaxis in Caenorhabditis elegans.