Had the same problem about one year ago. Was told by Hyundai service manager that the car contains a computer program that checks the gas cap at a random time. If the cap is not in the correct position at a random time the check engine light will come on. The trick is to have a factory gas cap and turn until you hear one click after adding gas. The computer will look at a random time at the gas cap and shut the light off. I was told this is part of an air pollution law. I have a 2013 elantra. Nothing about this in the owners manual ,but it is a common problem.