Just face the two tamagotchis together with the infrared aligned - I've heard that you can have them side to side, but I usually just align the red parts at the top.
Then, go to the heart icon, which is fifth along in the top row, then choose if the tamagotchi you're connecting with is a version1 or version2. It'll say "standby" and then they will connect.