Optogenetics is a powerful tool that enables the spatiotemporal control of neuronal activity and circuits in behaving animals. Here, we describe our protocol for optical activation of neurons in Drosophila larvae. As an example, we discuss the use of optogenetics to activate larval nociceptors and nociception behaviors in the third-larval instar. We have previously shown that, using spatially defined GAL4 drivers and potent UAS (upstream activation sequence)-channelrhodopsin-2∷YFP transgenic strains developed in our laboratory, it is possible to manipulate neuronal populations in response to illumination by blue light and to test whether the activation of defined neural circuits is sufficient to shape behaviors of interest. Although we have only used the protocol described here in larval stages, the procedure can be adapted to study neurons in adult flies--with the caveat that blue light may not sufficiently penetrate the adult cuticle to stimulate neurons deep in the brain. This procedure takes 1 week to culture optogenetic flies and ~1 h per group for the behavioral assays.