Come to your senses
Meaning: to start to understand that you have been behaving stupidly, to start acting reasonably, intelligently
Example: He finally came to his senses, started to work hard, and passed his exams.
Example: He finally came to his senses, started to work hard, and passed his exams.