Knock sensors are the units in vehicles that monitor the pinging in the motor and help control the timing of the engine. The computer uses the input from the knock sensor along with the O2 sensors and air fuel ratio sensor to adjust the timing and fuel mixture in the pistons.
The engine in a modern vehicle has to be kept in perfect timing to ensure the top of efficiency and performance. This is done by toeing the line between running perfect and detonation. The perfect ignition of the air / fuel mixture happens at the exact moment that the piston is about to reach the top of its stroke. The timing is set this way to ensure the pressure has time to begin pushing the piston back down. When the spark plug is fired with the incorrect ignition timing or fuel mixture the pressure waves move out from the flame wall faster than the explosion itself. When this happens they impact the side wall at the incorrect time and a sound wave is created and detected. The element in the knock sensor is designed to detect this sound and alert the computer to adjust the timing.
All sensors in a vehicle are extremely important and are generally overlooked on basic maintenance. During automotive check ups it is important to remember to check the smaller parts such as sensors and filters to ensure protection from future issues.