Why do you get erections?

The most probable reason you would get an erection is because you are turned on, whether it's because you are thinking of sex or see someone you think is hot your body is preparing to have sex.

The blood flows to your penis due to sexual excitement and becomes hard in preparation for sexual intercourse.

Of course, if you are a teenage boy you are likely to get erections for no reason at all. This is just a part of puberty, and will happen less often as you grow older.

Erections are natural and are caused by sexual stimulation or thoughts. It is in readiness for sexual intercourse. There is nothing much you can do to stop unwanted erections except think of something gross. This happens more in Puberty because this is a new phenomenon to you and you have not been able to train your body in self control yet. This will get less and less for you as time passes.