Optogenetics is a powerful tool for manipulating neuronal activity with high temporal and spatial precision. In the nematode C. elegans optogentics is especially useful and easy to apply. This is because C. elegans is translucent, so its neurons are highly accessible to optic stimulation. In addition, many of its neurons can be exclusively targeted using cell-specific promoters. We have recently taken advantage of optogentics to deliver artificial patterns of prolonged activation to a class of mechanosensory neurons, called touch receptor neurons (TRNs) in worms that lack touch sensation due to a genetic mutation. Our aim was to examine whether we can counteract the effects of sensory loss by artificially activating the sensory neurons. Here we describe in detail the various components of the protocol that we used. This consists of exposing worms expressing the light-sensitive ion channel Channelrohdopsin 2 (ChR2) in TRNs to long-term random flashes of light.