In animals, noxious stimuli activate a neural process called nociception. Drosophila larvae perform a rolling escape locomotion behavior in response to nociceptive sensory stimuli. Noxious mechanical, thermal, and chemical stimuli each trigger this same escape response in larvae. The polymodal sensory neurons that initiate the rolling response have been identified based on the expression patterns of genes that are known to be required for nociception responses. The synaptic output of these neurons, known as class IV multidendritic sensory neurons, is required for behavioral responses to thermal, mechanical, and chemical triggers of the rolling escape locomotion. Importantly, optogenetic stimulation of the class IV multidendritic neurons has also shown that the activation of those cells is sufficient to trigger nociceptive rolling. Optogenetics uses light-activated ion channels expressed in neurons of interest to bypass the normal physiological transduction machinery so that the cell may be activated in response to light that is applied by the investigator. This protocol describes an optogenetic technique that uses channelrhodopsin-2 (ChR2) to activate larval nociceptors and trigger nociceptive rolling. First, we explain how to set up the necessary genetic crosses and culture the larval progeny. Next, we describe how to perform the optogenetic nociception assay on third-instar larvae.