The present invention relates to a biocompatible device that integrates electromagnetic and mechanical elements and also allows the combination of different mechanisms for voluntary closing of the intestinal lumen. The device can be used in the presence of a stoma in order to control intestinal transit to the outside and dispense with the use of collection bags, or in the absence of a stoma in order to regulate intestinal transit for another medically necessary reason.