“Moses ascends Mt. Sinai for the third time to pray and beseech G-d to forgive the people. He will remain there for 40 days, descending on Yom Kippur, when he finally succeeds in his mission.
The shofar was sounded when Moses ascended on Rosh Chodesh Elul and every day afterwards.
This is why we sound the shofar every day of Elul. We recreate these 40 days beginning from the first day of Rosh Chodesh Elul. These 40 are hinted to in the 4 yuds (4 x 10) at the end of the words ani l’dodi v’dodi li.”