The Raspberry Pi 3 comes with on – board Wireless LAN (WLAN – 802.11n) i.e. WiFi and Bluetooth adapters. This means that all you need is your Raspberry Pi 3 for getting connected to WiFi or Bluetooth and there is no need for additional peripherals like USB Dongles (for WiFi or Bluetooth). In this tutorial, I will teach you how to setup WiFi on Raspberry Pi 3.
The WiFi setup will be explained for both SSH Connection (command line) in case of headless setup and from Raspbian Desktop in case of using Raspberry Pi with Monitor (or TV) and keyboard.
First, we will see the steps required for setting up WiFi on Raspberry Pi 3 using the Command Prompt (using SSH Connection). This type of setup is needed only if you setup Raspberry Pi in Headless Mode i.e. without monitor and keyboard.
We have already seen a tutorial on how to setup Raspberry Pi 3 without monitor and keyboard earlier. It is very important that you complete that setup first to proceed with WiFi setup.
Setup WiFi in Raspberry Pi from Terminal (Putty)
Before going in to the details of the setup of WiFi on Raspberry Pi 3, let us recap the important steps in the headless setup of Raspberry Pi.
- Format the microSD Card using SD Card Formatter
- Download the Raspbian Jessie OS
- Write the OS (.img file) on the microSD Card using Win 32 Disk Imager
- Enable SSH by creating a blank file with name SSH and no extension
- Insert the microSD Card in to Raspberry Pi, plug in the Ethernet cable and power on the Raspberry Pi
- Scan for IP Addresses and note down the IP Address of Raspberry Pi
- Start Putty and enter the IP Address of Raspberry Pi
- Login using the default username and password
NOTE: At this point, the IP Address assigned to the Raspberry Pi is 192.168.1.19 in our case. You can notice this in the second line as “firstname.lastname@example.org’s password:” in the above screen shot.
Please note this IP Address as we need to scan for IP Address again after setting up the WiFi.
Setup until this step is enough for setting up the WiFi. After initiating the WiFi and getting connected to a network, we can proceed with further steps like VNC Viewer.
After successful login in to the Raspberry Pi using any SSH Client like Putty, type the following command and hit enter.
This command will return a list of all the wireless networks that are available near the Raspberry Pi. The name of the network can be identified by the line ESSID. In our case, the name of the network is “SLNP”.
In this file, we need to add the name of the WiFi network and also the password. So, in order to open the file, type the following command and hit enter.
You can notice the file will already have some line like country=GB etc. Just below the existing content, enter the following command.
Here, in place of Name of the WiFi Network, enter the actual name of the network. In our case, it is SLNP. Type the password in the psk section.
NOTE: If the above commands are already present in the wpa_supplicant file, edit them with your current WiFi name and password.
After entering the command, press CTRL+X to exit. Then it will ask you whether to save the changes or not. Type y to save and hit enter.
Now, we need to turn on the WiFi Adapter. For that, type the following commands one after the other.
These commands will turn on the WiFi Adapter and connect the Raspberry Pi to the WiFi Network.
If the Raspberry Pi doesn’t get connected to the WiFi network, or if you are not sure whether the connection is successful or not, you can reboot the Raspberry Pi using one of the following commands.
Now you can disconnect the LAN Cable and restart the Raspberry Pi. It automatically gets connected to the WiFi Network. In order to check that, scan for the IP Address of the Raspberry Pi once again.
You will notice that the IP Address has changed and we need to use the new IP Address to login using SSH Client i.e. Putty. In our case, the new IP Address is 192.168.1.21.
To check the connection, type the following command in the Putty terminal. This will return the details of the connection like IP Address, transmitted and received bytes etc.
NOTE: The command ifconfig will return the details of both wired (Ethernet) and wireless (WiFi) connections.
After connecting to the WiFi network, we can proceed with further steps like installing VNC Server and Viewer on Raspberry Pi, enabling VNC, accessing the Raspberry Pi’s desktop using VNC Client, etc. which we have already seen in the earlier tutorial.
Setup WiFi in Raspberry Pi from Desktop
If your Raspberry Pi is connected to a monitor and keyboard, then configuring the WiFi is very easy. First, to turn ON the WiFi Adapter, click on the up – down arrow in top right corner of the Raspbian Desktop.
Click on the double arrow symbol once again to see the list of WiFi networks available near the Raspberry Pi. Select the WiFi network from the list. In our case, we have around 9 networks and our network is SLNP.
You will now be asked to enter the Pre Shared Key of the network. This is nothing but the password of the WiFi connection. Enter the password and click on OK.
You can see that the Raspberry Pi is connected to WiFi network of choice and is highlighted with a green check mark.