An optical device includes a carrier including a light transmitting layer and a light shielding layer disposed on the light transmitting layer. The optical device further includes a light emitter disposed on the carrier and a light detector disposed on the carrier. The optical device further includes a light transmitting encapsulant encapsulating the light emitter and the light detector, and a light shielding wall disposed in the light transmitting encapsulant and in contact with the light transmitting encapsulant and the light shielding layer.