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

Connect to the internet with your Raspberry Pi

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

Here's how to set up a USB Wi-Fi adapter with your Pi, using an Edimax EW-7811Un as the example.

Connect Hardware

To connect the Raspberry Pi hardware components, turn off the Raspberry Pi and fit the Wi-Fi adapter into any of the Pi's available USB ports. It doesn't matter which port you use. Next, connect the keyboard and screen if you haven't done so already. When that's done, turn on the 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.

Open terminal on Raspberry Pi

If your Pi boots to the Raspberry Pi OS desktop (LXDE), select 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, you'll tell it what to connect to.

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

    sudo nano /etc/network/interfaces
  2. The file will have some lines of text in it, which can be different depending on the Raspberry Pi OS version. Regardless, make sure you have the following four lines—some may be there:

    auto wlan0
    allow-hotplug wlan0
    iface wlan0 inet manual
    wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
    Raspberry Pi network interfaces configuration
  3. Press Ctrl+X to exit and save the file. You're asked if you want to save the modified buffer. In other words, you are prompted to save the file. Press Y and then press Enter to save the file under the same name.

Edit the WPA Supplicant File

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

  1. Before you edit the wpa_supplicant configuration, encrypt your network password and send it to the file. You can do this with the wpa_passphrase command.

    wpa_passphrase generate encrypted key on Raspberry Pi
  2. Give the command the name of your network (SSID) and your password. Then, direct the output to the wpa_supplicant file. It looks something like this:

    sudo sh -c "wpa_passphrase yourssid yourpassword >> /etc/wpa_supplicant/wpa_supplicant.conf"
  3. In the terminal, type the following command, and press Enter:

    sudo nano /etc/wpa_supplcant/wpa_supplicant.conf
  4. If the Pi is connected to a Wi-Fi network, you may see two network blocks. If not, you'll only have the one you created with wpa_passphrase. The one you created has psk equal to a long string of characters, and the plain text password is commented out. Delete the plain text password line.

    Delete any previous network blocks to ensure that the Pi connects to the right one.

    wpa_supplicant configuration on Raspberry Pi
  5. Inside the network block with the encrypted psk, add the following lines below the psk to tell the Pi how to connect to the wireless network.

    wpa_supplicant configuration on Raspberry Pi
  6. With that set up, save and exit the file. Press Ctrl+X, Y, then press Enter.

Optional Step: Turn Off Power Management

If you experience issues with the Wi-Fi adapter dropping connections or becoming unresponsive, the driver's power management setting may be the cause of the problem.

To turn off power management, create 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

Press Ctrl+X to exit the file, then save the file under the same name.

Reboot Your Raspberry Pi

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

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

sudo reboot

The Pi should restart and connect to the network within a minute or so.


If your Pi doesn't connect, there are a few 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 tight at first use.
  • Adapter: Is it compatible?
  • Network: Is your network on? Are other devices connected?
  • Network: Double-check the details you entered in the supplicant file.
  • Reboot: Try again, just in case.
Was this page helpful?