Real-time control of neural circuits in freely moving animals is a powerful tool for understanding behavior. This study demonstrates a closed-loop optogenetics system using a BrainVTA ChR2 construct. The system monitors neural activity and delivers light pulses in response to specific patterns, allowing precise modulation of circuit dynamics. We describe the experimental setup, including the optical fiber implant, real-time analysis software, and behavioral assays. The results show that closed-loop stimulation can alter behavior in a circuit-specific manner, opening new avenues for investigating causal relationships between neural activity and behavior.