How to Set up a USB Wi-Fi Adapter With the Raspberry Pi

Connect to the internet with your Raspberry Pi

Raspberry Pi board with WiFi adapters

Richard Saville

For every version of Raspberry Pi prior to the latest Pi 3, connecting to the internet was achieved in one of two ways; connecting via the Ethernet port or using a USB Wi-Fi adapter.

This article will show you how to set up a USB Wi-Fi adapter with your Pi, using an Edimax EW-7811Un in this example.

Connect Hardware

  1. Turn off your Raspberry Pi and fit your Wi-Fi adapter into any of the Pi's available USB ports, It doesn't matter which port you use.
  2. Now is also the time to connect your keyboard and screen if you haven't done so already.
  3. Turn on your Raspberry Pi and give it a minute to boot up.

Open the Terminal

If your Pi boots to the terminal by default, skip this step.

If your Pi boots to the Raspbian desktop (LXDE), click the Terminal icon in the taskbar. It looks like a monitor with a black screen.

Edit the Network Interfaces File

The first change to make is to add a few lines to the network interfaces file. This sets up the USB adapter to be used, and later on, we will tell it what to connect to.

In the terminal, type in the following command and press Enter:

sudo nano /etc/network/interfaces

Your file will already have some lines of text in it, which can be different depending on your version of Raspbian. Regardless, you need to make sure you have the following four lines—some may already be there:

auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

Press Ctrl+X to exit and save the file. You'll be asked if you want to "save modified buffer;" this just means "Do you want to save the file?" Press Y and then hit Enter to save under the same name.

Edit the WPA Supplicant File

This supplicant file is where you tell your Pi which network to connect to, and the password for that network.

In the terminal, type in the following command and press Enter:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

There should already be a couple of lines of text in this file. After these lines, enter the following block of text, adding your specific network details where required:

pairwise=CCMP TKIP

YOUR_SSID is the name of your network. This is the name that comes up when searching for Wi-Fi, like BT-HomeHub12345 or Virgin-Media-6789'.

YOUR_PASSWORD is the password for your network.

You can add multiple blocks if you need your Pi to connect to different networks depending on your location.

Optional Step: Turn off Power Management

If you have any issues with your Wi-Fi adapter dropping connections or becoming unresponsive, it may be the driver's power management setting causing you problems.

You can turn off power management by simply creating a new file with a line of text inside it.

Enter the following command to create this new file:

sudo nano /etc/modprobe.d/8192cu.conf

Then enter the following line of text:

options 8192cu rtw_power_mgnt=0 rtw_enusbss=0 rtw_ips_mode=1

Once again exit the file using Ctrl+X and save under the same name.

Reboot Your Raspberry Pi

That's everything you need to do to set up a Wi-Fi adapter, so now we need to reboot the Pi to put all of these changes into effect.

Type the following command in the terminal to reboot, then hit Enter:

sudo reboot

Your Pi should restart and connect to your network within a minute or so.


If your Pi doesn't connect, there are a few obvious things you should check:

  • Power Supply: Try a different, stronger power supply. Wi-Fi can be demanding on power.
  • Adapter: is it fitted properly? The Pi's USB ports can be quite tight at first use.
  • Adapter: Is it compatible?
  • Network: Is your network up? Are other devices connected?
  • Network: Double-check the details you entered in the supplicant file.
  • Reboot: Try again, just in case.