Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
That is a quite tiny voltage. This is not a code issue, since you cannot do more that driving the pin to LOW (which is what happens, when you use analogWrite(pin,0). Please show us your circuit.
To be clear, setting a voltage this precise can be very hard (also because this is in the range of noise). I'm not sure, if this even comes from the Arduino. It might as well come from the opamp circuit itself, since they are not build perfectly either. Depending on your exact circuit it might be better to use an extra circuit part for turning the opamp circuit really off, instead of letting it amplify noise.
Where get's anything counted? I don't see something like this in your code. About the extra circuit: That was just a thought about cutting the power of the opamps (maybe through a MOSFET) or pulling the output of the opamp over a current limiting resistor to low (also with a MOSFET). Just a thought, not a full fletched circuit, that I could provide a link for
You probably won't get below 3mV even with a transistor (that's what the arduino already does). Do you really need to get below that tiny voltage, I mean, it's 4 times less than the pwm's (ideally filtered) resolution when running at 3V3. If so, the only chance I see is to use external circuitry
It doesn't output 0v because it's near impossible. 0.003v is in fact very low. The LOW output, according to the datasheet, can be as high as 0.8v (when powered by 5v) and still be considered valid.
LOW does not mean 0v. It means "below the voltage threshold that is considered a LOW".
analogWrite(pin,0). Please show us your circuit.