Optogenetics has been recently applied to manipulate the neural circuits of Caenorhabditis elegans (C. elegans) to investigate its mechanosensation and locomotive behavior, which is a fundamental topic in model biology. In most neuron-related research, free C. elegans moves on an open area such as agar surface. However, this simple environment is different from the soil, in which C. elegans naturally dwells. To bridge up the gap, this paper presents integration of optogenetic illumination of C. elegans neural circuits and muscular force measurement in a structured microfluidic chip mimicking the C. elegans soil habitat. The microfluidic chip is essentially a ∼1 × 1 cm2 elastomeric polydimethylsiloxane micro-pillar array, configured in either form of lattice (LC) or honeycomb (HC) to mimic the environment in which the worm dwells. The integrated system has four key modules for illumination pattern generation, pattern projection, automatic tracking of the worm, and force measurement. Specifically, two optical pathways co-exist in an inverted microscope, including built-in bright-field illumination for worm tracking and pattern generation, and added-in optogenetic illumination for pattern projection onto the worm body segment. The behavior of a freely moving worm in the chip under optogenetic manipulation can be recorded for off-line force measurements. Using wild-type N2 C. elegans, we demonstrated optical illumination of C. elegans neurons by projecting light onto its head/tail segment at 14 Hz refresh frequency. We also measured the force and observed three representative locomotion patterns of forward movement, reversal, and omega turn for LC and HC configurations. Being capable of stimulating or inhibiting worm neurons and simultaneously measuring the thrust force, this enabling platform would offer new insights into the correlation between neurons and locomotive behaviors of the nematode under a complex environment.