Why does my car stalls when I come to a stop when the heat is on. on 2007 Chevrolet Cobalt

The car seems to drive fine on an open rode it's just when I come to a stop the car dies,only if the heat is on it starts back up but the heat has to be off.If I don't run the heat and come to a stop it's fine.My check engine light is on also

Asked by for the 2007 Chevrolet Cobalt
most likely the cooling fan for the ac is not working or it has a bad camshaft actuator .
is the check engine light on?
2 answers 2 comments
What are the trouble codes?
Not sure they said my sensor in my gas pedal
Post the code(s) so we can help.