How To Set Up a USB WiFi Adapter with the Raspberry Pi

Connect to the internet with your Raspberry Pi

Raspberry Pi board with WiFi adapters
Se up a USB WiFi adapter with your Raspberry Pi. Image: 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 WiFi adapter.

Whilst I own a shiny new Pi 3, I tend to avoid using it for prototyping or electronic projects, relying on my older boards for those slightly more risky projects.  For these older models, I use USB WiFi adapters, which require a few steps to set up before they can be used.

This article will show you how to set up a USB WiFi adapter with your Pi. I'm using an Edimax EW-7811Un in this example.

Connect Hardware

Turn off your Raspberry Pi and fit your WiFi adapter into any of the Pi's available USB ports, It doesn't matter which port you use.

Now is also the time to connect your keyboard and screen if you haven't done so already.

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 WiFi, 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 WiFi 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 WiFi 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. WiFi 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? Check if it's listed here.
  • 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