The Doppler effect refers to an apparent shift in the frequency of a wave emitted by a source when the source, the observer, or both are moving. To simplify the explanation, we will exam the effect as it relates to the production of sound in air and how it is heard. However, one should understand that the basic principle can be applied to any wave including electromagnetic waves.
A source of a sound produces a series of waves which travel out from the source. For sound, these waves are alternating regions of high pressure and low pressure in the air through which the waves travel. An observer hears these waves as the pressure of the air changes due to the passing wave which caused the eardrum to vibrate. The frequency of the wave is determined by the distance between successive regions of high pressure and the speed that the waves are moving through the air. The sound the ear "hears" is what we call the pitch of the sound. The quicker the regions of high pressure strike the ear drum, the higher the pitch is perceived to be.
Suppose now that a stationary source is producing sound at a specific pitch (frequency) which is being heard by a stationary observer some distance away. The pitch will remain constant because the high pressure regions hit the ear drum at regular time intervals.
Now allow the source to be moving toward the observer. The source creates a high pressure region (a wave) that heads to the observers ear. Because the source has moved closer to the observer when the next wave is created, that new wave doesn't have as far to go to reach the ear and so it gets their quicker than if it had come from the stationary source. "Getting there quicker" means that the high pressure region between the two waves are striking the ear quicker than if the source were stationary. This makes the observer's ear drum vibrate quicker which is heard as a higher pitch. So as a source moves toward the observer (or as the observer moves toward the source, or both) the waves strike the ear more quickly than if the source (or observer, or both) is stationary. Source and observer heading toward each other produce a shift in the frequency to a higher pitch.
The opposite happens when the source and observer are moving away from each other: the waves have further to go because the source and observer are getting further apart. The result is a shift in the frequency which makes the pitch sound lower.
So, when a train approaches, the frequency is shifted higher and as it passes the observer it shifts lower as it moves away. This shift is what is called the Doppler effect.