From Bulbapedia, the community-driven Pokémon encyclopedia.
Infrared interaction between a Pokémon Pikachu 2 GS and a Game Boy Color
The infrared (Japanese: 赤外線通信 infrared communication) feature allows communication between the Pokémon games and certain accessories. It was first used in the Generation I spin-off game Pokémon Trading Card Game.
In Pokémon Trading Card Game, there's a feature called Card Pop! that takes advantage of the Game Boy Color's infrared port to allow each player to receive a random card. However, using the Card Pop! feature between the same two players is only possible once.
In Generation II, the infrared port at the top of the Game Boy Color allows players to obtain Mystery Gifts via Pokémon Pikachu 2 GS or other Game Boy Colors.
The Pokémon mini also has an infrared port. It uses this to have multiplayer games of up to 10 players (number of players varies per game). The games which utilize this feature are Pokémon Party mini, Pokémon Zany Cards, Pokémon Tetris, Pokémon Race mini, and Pichu Bros. mini.
In HeartGold and SoulSilver, an infrared sensor is used to link the Nintendo DS and the Pokéwalker.
In Black and White and Black 2 and White 2, an infrared-capable feature is accessed via the C-Gear and in the Multi Battle Lines in the Battle Subway; this is used to quickly identify which player will be communicated with, after which DS Wireless Communications are used. Official tournaments sometimes use infrared for the duration of the battle. Event Pokémon that are distributed using infrared can be obtained multiple times.
In X and Y, the infrared port on the top of the 3DS is used to quickly identify which player will be communicated with, after which 3DS Wireless Communications are used.