Connecting a speaker is super smple. You just need one output pin and one ground pin. I first test all my circuits with an Arduino before integrating them in my board so that I know the connections and the component are correct.
Playing music with speaker
I got the code for the super mario theme song here. There is a melody, tempo and note definition, which defines the music to play.
I played twinkle twinkle little star melody using the guidelines on this Arduio website page. You can see some useful screenshots here.
I integrated the speaker with my input devices and used it with a Atmega328p. You may see full details of this integration on my final project updates page