The Doppler effect occurs when there's relative motion between a wave source and an observer. Simply put: waves get compressed when the source moves toward you, and stretched when it moves away. This changes the frequency—and for sound waves, the pitch—that you perceive.
Think of it like this: imagine throwing tennis balls at regular intervals while running toward someone. The balls bunch up because each throw starts from a position closer to the target. Now run away while throwing—the balls spread out more. Waves behave similarly.