There is an increasing need to incorporate an actively controlled drug delivery system (DDS) into the next generation of capsule endoscopy in order to treat diseases in the gastrointestinal tract in a noninvasive way. Despite a number of attempts to magnetically actuate drug delivery mechanisms embedded in endoscopic capsules, longer operating distances and further miniaturization of on-board components are still drawbacks of such systems. In this paper, we propose an innovative magnetic system that consists of an array of magnets, which activates a DDS, based on an overly miniaturized slider-crank mechanism. We use analytical models to compare the magnetic fields generated by cylindrical and arc-shaped magnets. Our experimental results, which are in agreement with the analytical results, show that an optimally configured array of the magnets enhances the magnetic field and also the driving magnetic torque and subsequently, it imposes a high enough force on the piston of the DDS to expel a required dose of a drug out of a reservoir. We conclude that the proposed magnetic field optimization method is effective in establishing an active DDS that is designed to deliver drug profiles with accurate control of the release rate, release amount, and number of doses.