Complex animal behaviors are built from dynamical relationships between sensory inputs, neuronal activity, and motor outputs in patterns with strategic value. Connecting these patterns illuminates how nervous systems compute behavior. Here, we study Drosophila larva navigation up temperature gradients toward preferred temperatures (positive thermotaxis). By tracking the movements of animals responding to fixed spatial temperature gradients or random temperature fluctuations, we calculate the sensitivity and dynamics of the conversion of thermosensory inputs into motor responses. We discover three thermosensory neurons in each dorsal organ ganglion (DOG) that are required for positive thermotaxis. Random optogenetic stimulation of the DOG thermosensory neurons evokes behavioral patterns that mimic the response to temperature variations. In vivo calcium and voltage imaging reveals that the DOG thermosensory neurons exhibit activity patterns with sensitivity and dynamics matched to the behavioral response. Temporal processing of temperature variations carried out by the DOG thermosensory neurons emerges in distinct motor responses during thermotaxis. N avigation toward environmental conditions that improve survival and fitness is of near-universal importance in motile biological organisms. Quantitative analysis of such animal behaviors to defined sensory inputs is a powerful approach to elucidate how behavior is encoded in underlying neurons and circuits. The advantage of studying navigation in small, optically transparent, genetically modifiable animals like Caenorhabditis elegans (1) or Drosophila larvae (2) is the opportunity to dissect sensory, neuronal, and behavioral dynamics in live animals by using optical neurophysiology and optogenetics throughout the nervous system.The Drosophila melanogaster larva navigates gradients of many sensory cues, including light, temperature, odors, and tastes, but with fewer neurons in its sensory periphery and brain than the adult. Moreover, the simpler body plan and crawling movements of the larva facilitate the precise quantification of behavioral dynamics. Poikilotherms like C. elegans or Drosophila use sensitive thermosensory mechanisms to navigate moderate temperature ranges, thereby enabling them to use their environments to regulate their own body temperatures (3, 4). Here, we study sensory and behavioral dynamics during positive thermotaxis (i.e., cool avoidance) by the Drosophila larva. Tracking the movements of Drosophila exploring temperature, olfactory, or gaseous gradients has shown that their navigation is generated by a sequence of two alternating motor programs: runs involving peristaltic forward movement that are interrupted by turns involving probing side-to-side head sweeps until the initiation of a new run (5-8). Larvae negotiating temperature gradients stochastically transition between runs and turns by strategies that cause runs pointed in favorable directions to be more frequent and longer than runs pointed in unfavorable directions. These transitions b...