Electronics Hub

projects | tutorials | reviews | kits

  • HOME
  • PROJECTS
    • MINI PROJECTS
      • TOP ELECTRONICS
      • MICROCONTROLLER
    • ELECTRICAL
      • TOP ELECTRICAL
    • ELECTRONICS
      • TOP
      • LATEST
      • LED
      • VLSI
      • MATLAB
      • SENSOR
    • HOME AUTOMATION
    • RASPBERRY PI
    • IOT
    • EMBEDDED
      • 8051
      • AVR
      • PIC
    • COMMUNICATION
      • DTMF
      • GSM
      • RFID
      • WIRELESS
    • POWER ELECTRONICS
    • ARM PROJECTS
    • ROBOTICS
    • SOLAR
  • MINI PROJECTS
  • ARDUINO
  • FREE CIRCUITS
    • MINI PROJECTS
    • ELECTRONICS
      • 555 TIMER
    • EMBEDDED
      • 8051
      • AVR
    • COMMUNICATION
    • ELECTRICAL
    • ROBOTICS
    • SOLOR
    • SENSOR
  • TUTORIALS
    • CAPACITORS
    • RESISTORS
    • FILTERS
    • OPERATIONAL AMPLIFIERS
    • DIODES
    • TRANSISTORS
    • NUMBER SYSTEMS
    • IO DEVICES
    • MISCELLANEOUS
    • DC CIRCUIT THEORY
    • THYRISTORS
    • SEQUENTIAL LOGIC CIRCUITS
  • SYMBOLS
  • DIY
  • REVIEWS
  • CONTACT US
    • FOLLOW US
      • FACEBOOK
      • YOUTUBE
      • INSTAGRAM
      • GOOGLE PLUS
      • TWITTER
You are here: Home / Raspberry pi / How to setup WiFi on Raspberry Pi 2 using USB Dongle

How to setup WiFi on Raspberry Pi 2 using USB Dongle

July 7, 2017 By Anusha 5 Comments

Setting up WiFi on Raspberry Pi 2 is different from setting up on Raspberry Pi 3 as Raspberry Pi 2 or earlier models doesn’t have on board WiFi Adapter like Raspberry Pi 3 does. Hence, in order to access WiFi using Raspberry Pi 2, we need to use an external adapter like a WiFi Dongle.

In previous tutorial, I’ve explained how to connect Raspberry Pi 3 to a WiFi Network using the on – board WiFi Adapter. In this tutorial, I’ll show you how to setup WiFi on Raspberry Pi 2 using a WiFi Dongle and get connected to a WiFi network.

Raspberry Pi 2 WiFi Dongle

We have already seen how to setup a Raspberry Pi Computer in headless fashion i.e. without using monitor and keyboard. We have also seen how to enable and configure the WiFi in Raspberry Pi 3.

In order to connect a Raspberry Pi 2 or older devices (which doesn’t have on – board WiFi Adapter), we need to use an USB type WiFi Dongle.

The WiFi Dongle used in this project is a Tenda W311MI USB Adapter. This particular adapter supports IEEE 802.11b/g/n protocols with speeds up to 150Mbps.

Tenda WiFi Dongle

We will now see how to configure the Raspberry Pi 2 to access a WiFi network. The following steps are common whether your Raspberry Pi is connected to a Monitor and Keyboard or it is accessed using a remote SSH Client like Putty in a headless fashion.

Table of Contents

  • Connect the Hardware
  • Check for USB WiFi Dongle Hardware
  • Edit the Network Interfaces File
  • Edit the WPA Supplicant File
  • Reboot the Raspberry Pi
  • Troubleshooting

Connect the Hardware

If your Raspberry Pi is already turned on, turn it off and connect the USB WiFi Dongle to any of the USB ports on the Raspberry Pi. If you are using your Raspberry Pi with monitor or TV, connect the Raspberry Pi to your monitor and keyboard.

Also connect an Ethernet cable (optional, if you are using monitor and keyboard) to the Raspberry Pi and have a computer (with internet connection) ready. Now you can turn on the Raspberry Pi and wait till it boots up.

Check for USB WiFi Dongle Hardware

If you are using Putty (headless setup), login to Raspberry Pi using the username and password. If you are using a monitor, open the Terminal from the desktop.

Putty Login

To check whether the Raspberry Pi detected the WiFi Dongle hardware that is plugged in to the USB port, type the following command in the terminal and hit enter.

dmesg | more

Hit space bar multiple times to jump to next page of the list. If you scroll down, you can see few lines related to the WiFi Dongle, something similar to the following.

[ 1.872459] usb 1-1.2: new high-speed USB device number 4 using dwc_otg

[ 1.992963] usb 1-1.2: New USB device found, idVendor=148f, idProduct=5370

[ 1.992997] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3

[ 1.993014] usb 1-1.2: Product: 802.11 n WLAN Adapter

[ 1.993029] usb 1-1.2: Manufacturer: Ralink

This means that the Raspbian OS has detected the USB WiFi Dongle. But the Dongle doesn’t work yet as we need to configure it.

Check for USB Dongle

Edit the Network Interfaces File

We need to edit the network interfaces file that is located at /etc/network/interfaces. This file sets up the WiFi Dongle we are going to use. In order to open the network interfaces file, type the following command and hit enter.

sudo nano /etc/network/interfaces

Depending on the version of the Raspbian Operating system you have installed, the network interfaces file will already have few lines of text. Regardless of the content, make sure the following lines of code are present. If not, add these lines to the existing code.

auto lo

iface lo inet loopback

iface eth0 inet manual

auto wlan0

allow-hotplug wlan0

iface wlan0 inet manual

wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

Your updated code should look something like this.


Press CTRL+X to exit the editor. It will ask you whether to save changes to the file or not. Type y and hit enter. You will go back to the terminal. We are done with editing the Network Interfaces File.

Edit the WPA Supplicant File

The WPA or WiFi Protected Access Supplicant file consists of the details regarding the WiFi network like the name, password, security, type etc.

We need to edit this file and add the details of your personal WiFi network. In order to open the WPA Supplicant File, type the following command and hit enter.

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Add the following lines of code to the existing code (if any). Make necessary changes to the following code as per your WiFi network details.

network={

ssid=”Name of WiFi Network”

psk=”Password of the WiFi Network”

proto=RSN

key_mgmt=WPA-PSK

pairwise=CCMP TKIP

group=CCMP TKIP

id_str=”Name of WiFi Network”

}

The edited file will look something like this.

WPA Config
Replace Name of WiFi Network with the actual name of your WiFi Network. In our case, it is SLNP. Similarly, enter the password of the WiFi network corresponding to psk.

In order to exit and save the file with the same name, press CTRL+X and then Y and finally hit enter.

Reboot the Raspberry Pi

If you are done with the above steps, you can reboot the Raspberry Pi. In the Putty Terminal, just the following command.

sudo poweroff

After the Raspberry Pi is shut down, switch of the power supply and disconnect the Ethernet cable. Now, boot the Raspberry Pi and scan for the IP Address. If the WiFi is configured correctly, you should get the IP Address associated with the WiFi Dongle connected to the Raspberry Pi.

Using this new IP Address, you can login in to the Raspberry Pi with the help of SSH Client Putty.

Putty Login New
To test the WiFi connection, we can use different commands. First, you can use the following command to get details of all the network connections.

ifconfig

This will return the IP Address, Transmitted bytes, Received bytes etc.

Test Ifconfig

Another command is iwconfig. It is similar to ifconfig but it is associated only with wireless networks.

iwconfig

Test Iwconfig
This command will return details like SSID, frequency, bit rate, power, link quality etc. If the Link Quality option reads 0/70 (0/Maximum), then the WiFi adapter didn’t get connected to the WiFi Network properly.

Another way to test the connection is using Ping command. Use the following command and see if you get any reply.

sudo ping www.google.co.in

Test Ping

To come out of the Ping, press CTRL+C.

Troubleshooting

If you are facing any trouble connecting to WiFi using the USB WiFi Dongle check for the following. These might be the problem (but not limited to these).

  • Power: WiFi Adapters might require more power and if your power supply cannot provide enough power to it, it might not function properly.
  • Compatibility: Check for the list of compatible external WiFi adapters and buy one.
  • USB Adapter: Check if the Dongle is perfectly fitted in to the USB Port.
  • WiFi Network: Check if your WiFi network is up and running.
  • Network Interfaces and WPA Supplicant Files: Make sure that you have entered the correct commands in the corresponding files.
  • Power Down and Reboot: Power down the Raspberry Pi and reboot again.

Related Posts:

  • How to Connect ESP8266 to WiFi | A Beginner's Guide
  • WiFi Controlled LED using ESP8266 and Arduino
  • DIY PCB for ESP8266 WiFi Module
  • How to Blink an LED using Raspberry Pi and Python
  • How to Setup Static IP Address on Raspberry Pi?
  • How to Control ESP8266 over Internet?

Filed Under: Raspberry pi

Comments

  1. Watson Edwards says

    December 12, 2017 at 6:46 am

    I am so thankful to open this website because I also want to learn wifi setup using USB dongle.It is exactly what I was looking for.It’s your gratefulness for affixing and giving out your blog with all of us. Thank you very much for this write-up.

    Reply
  2. Ananthan S says

    September 3, 2018 at 5:19 am

    Will you please sent me a video tutorial ??

    Reply
  3. Niels says

    October 28, 2018 at 12:37 pm

    Thanks, its working straight away.

    Reply
  4. Don says

    March 14, 2019 at 10:58 pm

    Tutorial worked just as written… thank you!!

    Reply
  5. Matt Manzano says

    September 21, 2019 at 11:57 pm

    This tutorial saved me a ton of time setting up my wi-fi dongle on my Raspberry Shake! I searched all the popular forums and finally landed here! Thanks so MUCH!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Projects By Category

Arduino Projects (200+)
Electronics Projects (250+)
Mini Project Circuits (160+)
Mini Project Ideas (150+)
ECE Projects (150+)
EEE Projects (150+)
8051 Projects (110+)
Raspberry Pi Projects (101+)
Electrical Project Ideas (100+)
Embedded Projects (100+)
Latest Electronics Ideas (100+)
Microcontroller Mini Projects (100+)
Robotics Projects (100+)
VLSI Projects (100+)
Solar Projects (100+)
IOT Projects (100+)

Communication Projects (70+)
LED Projects (70+)
Power Electronics Projects (60+)
RFID Projects (60+)
Home Automation Projects (50+)
Matlab Projects (50+)
EIE Projects (50+)
Wireless Projects (50+)
LabView Projects (45+)
Zigbee Projects (45+)
GSM Projects (40+)
555 Timer Circuits (40+)
Sensor Projects (40+)
ARM Projects (60+)
DTMF Projects (30+)
PIC Projects (30+)
Electrical Mini Projects (25)
ESP8266 Projects (15)

Kits

Best Rgb Led Strip Light Kits
Arduino Starter Kit
Electronics Books Beginners
Breadboard Kits Beginners
Best Arduino Books
Diy Digital Clock Kits
Drone Kits Beginners
Best Brushless Motors
Raspberry Pi Books
Electronics Component Kits Beginners
Soldering Stations
Electronics Repair Tool Kit Beginners
Raspberry Pi Starter Kits
Best Waveform Generators
Arduino Robot Kits
Oscilloscope Kits Beginners
Raspberry Pi LCD Display Kits
Robot Cat Toys
FM Radio Kit Buy Online
Best Resistor Kits
Soldering Iron Kits
Best Power Supplies
Best Capacitor Kits
Arduino Sensors
Best Function Generator Kits
Led Christmas Lights
Best Iot Starter Kits
Best Gaming Headsets
Best Python Books
Best Robot Dog Toys
Best Robot Kits Kids
Best Solar Panel Kits
Led Strip Light Kits Buy Online
Top Robot Vacuum Cleaners
Digital Multimeter Kit Reviews
Solar Light Kits Beginners
Best Jumper Wire Kits
Best Gaming Earbuds
Best Wireless Routers
3d Printer Kits Buy Online
Best Gaming Mouse
Electric Lawn Mowers
Best Gaming Monitors

Subscribe for Updates

Enter your email address:

GENERAL

  • Tutorials
  • Symbols
  • Courses
  • Calculator
  • Contact
  • HomeZene
  • Best Arduino Kits
  • TechZene

PROJECTS

  • Electrical
  • Electronics
  • Embedded
  • Power
  • Robotics
  • ARM
  • IOT

PROJECTS

  • Mini projects
  • Microcontroller
  • Arduino
  • Solar
  • Free circuits
  • Home Automation
  • Seminar Topics
  • Electronics Questions

TUTORIALS

  • Capacitors
  • Resistors
  • Filters
  • Diodes
  • Transistors

TUTORIALS

  • Amplifiers
  • IO Devices
  • Thyristors
  • DC Circuits
  • Number System
  • TS EAMCET 2019

FOLLOW US

  • Instagram
  • Youtube
  • Facebook
  • Google Plus
  • Twitter
Affiliate Disclosure | Disclaimer | Terms and Conditions | Privacy Policy 

Copyright © 2020 Electronicshub.org