For example, pH of stomach is around 3, so how can I make sure that the drug doesn't get released at a pH 4? How can I make sure exactly that it gets released at a particular said pH, and not anywhere else?
I don't know enough about your system to say for sure, but a couple of approaches can be considered.
If you are doing dissolution experiments, you can perform the release or dissolution in a USP or other vessel, and use sampling fluids contained in small dialysis bags or other small volume vesses.. they key is to separate the dissolution medium from the collecting medium by cellulose membranes or something similar (MW cutoff of 2000 or so), which will allow the free drug to collect while excluding the gel and bound drug. Just make sure the surface to volume of the collecting medium is as large as possible (i.e,, largest surface area and smallest volume).
An interesting read along this line is the dynamic dialysis approach of Meyer and Guttman, who published two papers around 1970. This might work if you keep the bags small or use rapidly equilibrating devices.
there are different approaches to find that at what pH the drug will release from the specific drug delivery system. one is to evaluate the release of the drug through your formulation by performing the dissolution at different pH including the one which is desired one. you can prepare the dissolution media of pH, 1.2, 4, 6.8 etc. In this way you can find that at what pH the drug will release. further more there are some pH sensitive polymers are available that release the drug at a specific pH like the one that used in enteric coated tablets, that has the ability to release the drug small intestine not in the stomach.