No start? overheat? Temp Needle NOT Past half

So I have this problem where I will drive for awhile then turn my car off. When I come back maybe 2 minutes later I get a CEL and it just cranks and cranks but wont turn over. Temp needle is just a hair under half way. Why wont it let me start the car but the car isn’t really over heated? I wait maybe 10-15 min and it starts right up.

Any help is appreciated

-Ive installed my fan through a manual switch so I can turn it on when the car gets hot. Still scratching my head…Any ideas?

untill you pull that check engine code. theres not much we can help with…