1. I remembered posting the letter = I posted the letter. Then, later, I remembered that I had done this.
= Mi sono ricordato di aver mandato la lettera.
I remembered to post the letter = I remembered that I needed to post the letter. Then I posted it.
= Mi sono ricordato di mandare la lettera.
2. I stopped drinking coffee = I drank coffee. Then, I stopped.
Mi sono smesso di bere caffè.
I stopped to drink coffee = I was working for (for example). Then, I stopped (working). I drank coffee.
(Per esempio) Mi sono smesso (di lavorare) allo scopo di bere il caffè.
3. I tried to sleep = My goal was to fall asleep. I attempted to fall asleep, but I wasn't able to do this. It was too difficult.
I tried counting sheep and drinking a glass of warm milk = My goal was to fall asleep. Counting sheep and drinking warm milk were experiments - these were possible solutions that I tried in an attempt to fall asleep.
Here's a couple more examples:
(i) I tried to contact my friend = Il mio obbiettivo
I tried phoning her. I tried texting her. I tried messaging her on Facebook = Esperimenti/Modi per raggiungere il mio obiettivo
Modi per raggiungere il mio obiettivo
(ii) I'm going to try to stop smoking = Il mio obbiettivo
I'll e-cigarettes. I'll try nicotine patches. I'll try hypnotherapy = Esperimenti/Modi per raggiungere il mio obiettivo
Spero di essere stata d'aiuto.
Gerunds and infinitives come from verb forms but function as nouns. A gerund or an infinitive can be a direct object of a verb.
use a gerund after a following verb:avoid, cant stand,discuss,dislike,dont mind,enjoy,feel like,practice,stop,quit,suggest,finish,keep,go on
infinitive after:agree,be sure,decide,choose,expect,hope,learn,need,seem,plan,
other verbs can be followed by both of them:begine,continue,hate,like,love,prefer,start