An electronic device includes a housing including an opening, and a camera module at least partially exposed to an exterior environment of the electronic device through the opening, wherein the camera module includes: a lens unit, an image sensor configured to convert light received through the lens unit into an electrical signal, a magnetic member, a coil unit disposed on a first surface of the magnetic member and oriented to face the magnetic member, a magnetic substance unit coupled to a second surface of the magnetic member, and a position sensor disposed adjacent to the magnetic member and oriented to face at least a portion of the magnetic substance unit.