From Rimini you can easily reach San Marino by bus, i.e. by the Bonelli company bus that leaves from bus stop on the opposite side of the Rimini train station (just beside "EatItalia" snack bar).
We bought our ticets from the small ticket booth, where a lady kindly sold us two return tickets and slowly explained how we need to use them. So you get 4 tickets, exactly same ones, for 2 ppl. You just consume 2 of them on the way to San Marino and the rest when coming back. No matter which ones you give to the bus driver when you enter. The bus was around 15 minutes lates for starters, but the ticket booth lady came to the bus stop to explain this (in italian) and also did sell more tickets to anyone who would like to have one. The problem was that when the bus arrived, there were too many tickets sold, which caused that around 10 ppl needed to stand the whole trip. Not very nice for those who did not use some "brute force" when entering the bus, as this was needed if you wanted to assure a place to sit for you and your friend. You just need to be very unpolite, thats because everybody else does it. Nobody seems to care about other people, its just "me" and "I want to ensure a place to sit for me and my friend because we paid for the tickets". Well did not everyone else? Good thinking Bonnelli :) As the trip takes quite long time around 45 mins and the ride is quite "turbulent", I suggest you either sit or forget it :) The trip to San Marino was quite a rally up the winding roads, high up to the mountain. Breathtaking views and if your stomach is very sensitive, dont eat anything big or drink alcohol before the trip or I am sure you wont feel very well... XD. The trip back down from San Marino was ...hmmm...interesting... again nice views and not so many people. However, our local "F1-driver" made sure that my neck is still a bit sore and my stomach is ..well i think it is now turned on the correct side again...Well in all, the trip on both directions was efficient and the busses did have proper air conditioning.
From Rimini Bonelli run a regular service into the Republic of San Marino, Serravalle is the first town over the border. Buy a ticket before the bus arrives from the ticket booth opposite the bus stop.