Mercury ion binding blocks potassium ion channels, which leads to toxicity in vivo. It is challenging to design a simple and efficient artificial system to mimic the sophisticated biological process of mercury poisoning. Herein, based on biomimetic strategies, a tunable mercury(ii) ion-gate modulated by mercaptoacetic acid-pillararene (MAP5) is reported. By virtue of the unique design of the host-guest competition, potassium ion transport can actualize the reversible switching between "on" and "off" in the absence and presence of mercury ions. Moreover, the MAP5-immobilized nanochannel is highly effective at distinguishing Hg2+ from other metal ions and can be used to detect Hg2+ and act as an excellent and robust gate valve for developing integrated circuits and nanoelectronic logic devices. This study paves a new way for better understanding the physiological phenomenon of mercury toxicity and shows great promise for biomedical research.