The correct use of the pedal is the study of a lifetime! In the situation you show here, it's good to first learn the pure legato pedalling, which is well described by Sgisela. But other forms of pedalling can also be used: you just need to be very aware of the differences they make in the sound.
If you lift the pedal just a split second before you play the next note, there will be a very slight gap in the sound. This makes the chords sound just a bit articulated. If you compare it to a bowed string instrument such as the violin, it's like a change of bow direction.
If you lift the pedal just after having played the note, there will be blurring. I wouldn't consider such blurring appropriate here, but in other music it may be just what you need.
There are more subtle techniques that you'll learn later, but if you master these three, which might be called "quasi-legato", "legato" and "legatissimo", you will be off to a good start.
One really important thing: once you have lifted the pedal, you do not need to depress it again immediately. Many pianists get into the habit of making a very fast up-down movement at each harmony change. There are two drawbacks to doing this:
- If you depress the pedal again too soon, you may not give the dampers the time to completely stop the vibrations of the strings. This muddies the sound.
- Depressing the pedal very fast can be noisy. in the worst cases, you can hear the pianist stamp on the pedal.
In the example you give, you have lots of time to depress the pedal. Try waiting at least for the duration of an eighth note, then depress it slowly.