A smartphone can be used for many physics experiments by using the sensors built into the phone. The complementary metal oxide semiconductor (CMOS) (charge-coupled device, CCD) sensor of the camera records the images of objects photographed in pixels. The width of the image can be read off with micron level accuracy with the help of software available freely from the internet. If the dimensions of the object in the direction transverse to the viewing direction of the camera are known, the magnification of the object photographed can be determined accurately. A smartphone camera is a compound lens comprising a number of very thin lenses. A single thin lens is equivalent, as far as the transverse magnification is concerned, to a compound lens of the smartphone, when the thin lens has the same focal length as the effective focal length of the compound lens and is placed at its first principal plane. This property allows us to find experimentally the effective focal length of the compound lens of the camera accurately, using the thin lens equation. Once the focal length of the camera is known, the distance of an object can be determined by finding its magnification from the photograph. We have determined the refractive index of water accurately by photographing the apparent position of an object immersed in it. By determining the magnifications, we have found the real and apparent depths of the object. The ratio of these depths gives the refractive index. We have determined the refractive index of glass also using some thin glass slides.