A sensor in electronic devices works by detecting and measuring physical input from the environment, such as light, temperature, motion, or pressure. The sensor then converts this physical input into an electrical signal that can be processed by the device's circuits. This allows the electronic device to respond or react to changes in its surroundings based on the data collected by the sensor.