Two optimum pinhole diameter equations exist. One is optimized for resolution d = sqrt(3.66*lambda*f), the other for sharpness d = sqrt(2.44*lambda*f), lambda being the wavelength of light and f being the focal length. In your case, the former returns d = 0.29 mm for resolution and the latter d = 0.23 mm for sharpness, assuming a wavelength of 555 nm and a focal length of 40 mm. Most people, subjectively, prefer sharpness over resolution.

You'll find more here:

http://www.waybeyondmonochrome.com/W...ographyEd2.pdf

It's not a big deal, but you may want to experiment with both and see which you like best.