A merocyanine dye as a p-toluenesulfonate salt was synthesized. The structure of the dye was characterized using IR, NMR, HR-MS and single crystal X-ray crystallography. The X-ray crystallographic studies revealed the formation of a stacked aggregated structure of the merocyanine dye. The stacking interactions were investigated using the Crystal Explorer program, which estimated the strength of the interactions between different molecular pairs. The merocyanine dye was screened for affinity towards heavy metal ions, which revealed a color change from pink to colorless in the presence of mercuric ions, while other metal ions did not produce a similar change in color. In addition, the fluorescence spectroscopy indicated a change in the fluorescence intensity upon addition of mercuric ions. Both techniques displayed a good limit of detection value towards mercuric ions. In addition, the pixel intensity-based detection technique was also employed for the determination of limit of detection value with the help of a smartphone. The dynamic light scattering (DLS) studies indicated that the optical change occurred in the spectra of the receptor is due to the disaggregation of the receptor induced by mercuric ions. In addition, 1H-NMR studies were also used for investigating the mechanism of interaction between the receptor and the mercuric ions. The density functional theory (DFT) studies were used to investigate the formation of the complex at the molecular level, while time dependent density functional theory (TD-DFT) studies were used to understand the observed absorption spectra through the calculation of electronic excitation parameters, which indicated an increase in the energy difference between ground and the excited state.