A device and method are provided for treating obesity by implanting an electrode in the duodenum and stimulating the duodenum with a stimulator, causing the pylorus to contract.