Once you beat the first gym, go to the bottom floor of any Pokemon Center and there should be a girl, who when you talk to, gives you the Pal Pad. Once you've connected to WiFi on Diamond or Pearl for the first time, you are given a Friend Code in the Pal Pad. Simply open your Pal Pad and select "______'s Code" to view it.
To use it, you have to exchange your 12 digit Friend Code with another individual's 12 digit Friend Code and register it into the Pal Pad by selecting "Register Friend Code". Once both of you have imputted eachother's Friend Codes, when you both go on WiFi at the same time, you can interact with eachother.