Check engine light on with a loud clicking noise from engine while driving. on 2006 Hyundai Sonata

The check engine light has been going off and on for a few weeks. The loud clicking noise is coming from the engine and started a few days ago. What could it be?

Asked by for the 2006 Hyundai Sonata
Beware of the clicking noise - I would hate to think that driving your vehicle may be causing engine damage due to a problem. Seek a diagnosis as soon as possible.

The check engine light will offer clues also as to what may be happening.