We developed Carignan, a real-time calcium imaging software that can automatically detect activity patterns of neurons. Carignan can activate an external device when synchronized neural activity is detected in calcium imaging obtained by a one-photon (1p) miniscope. Combined with optogenetics, our software enables closed-loop experiments for investigating functions of specific types of neurons in the brain. In addition to making existing pattern detection algorithms run in real-time seamlessly, we developed a new classification module that distinguishes neurons from false-positives using deep learning. We used a combination of convolutional and recurrent neural networks to incorporate both spatial and temporal features in activity patterns. Our method performed better than existing neuron detection methods for false-positive neuron detection in terms of the F1 score. Using Carignan, experimenters can activate or suppress a group of neurons when specific neural activity is observed. Because the system uses a 1p miniscope, it can be used on the brain of a freely-moving animal, making it applicable to a wide range of experimental paradigms.