A knock sensor detects engine knock or detonation, which then controls the timing of the engine. Engine knock and detonation are usually harmful engine vibrations that are often caused when a spark plug does not ignite the fuel properly. This will cause the engine to run roughly, and may cause serious damage if not taken care of immediately.
There is a piezoelectric element inside the sensor which picks up the damaging vibrations and sends the signal back to the PCM/ECM. That means the sensor connects directly to the vehicle's onboard computer, and the two work in tandem to adjust the engine for maximum operating efficiency. However, when an adjustment to the engine operation is not enough, the onboard computer will display a trouble code. This indicates the vehicle needs repair.