Tilt switch uses a blob of mercury in a small tube. When the tube is tilted, the mercury runs down and forms a bridge across the two contacts turning the switch on. This type of switch is used in warning systems that alert people to an excessive angle of tilt, e.g. for drivers of farm vehicles. They can be used as a sensor to detect the position of an object. A tilt switch includes a housing body with a modular concavity, light emitting and receiving units disposed in the housing body. A modular insert body is inserted into the concavity. This has an entry hole for admitting entry of only a portion of a light beam-emitting unit so as to form a narrower beam of incident light that travels in a light path. It also contains an accommodation chamber, ball member, an optoelectronic sensor member and a modular cover. An optoelectronic sensor member shifts the state of the switch when the ball member is lurched as a result of tilting for interrupting or restoring the transmission of the light beam. Some tilt switches contain mercury, which is poisonous.