0
0
Iot-protocolsHow-ToBeginner · 3 min read

How to Use WiFi on Raspberry Pi: Simple Setup Guide

To use wifi on Raspberry Pi, you can configure the network by editing the /etc/wpa_supplicant/wpa_supplicant.conf file with your WiFi details or use the desktop's network icon to connect. After setup, restart the network service or reboot to activate the connection.
📐

Syntax

To connect Raspberry Pi to WiFi via command line, you edit the wpa_supplicant.conf file with your network details. The basic syntax inside this file is:

  • ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev: Defines control interface.
  • update_config=1: Allows updates to the config.
  • network={...}: Contains your WiFi network info.
  • ssid="YourNetworkName": Your WiFi name.
  • psk="YourPassword": Your WiFi password.

This file tells the Pi how to connect to your WiFi.

conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="YourNetworkName"
    psk="YourPassword"
    key_mgmt=WPA-PSK
}
💻

Example

This example shows how to connect Raspberry Pi to a WiFi network named HomeWiFi with password mypassword123 by editing the wpa_supplicant.conf file and restarting the service.

bash
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

# Add the following lines at the end of the file:
network={
    ssid="HomeWiFi"
    psk="mypassword123"
    key_mgmt=WPA-PSK
}

# Save and exit, then run:
sudo wpa_cli -i wlan0 reconfigure

# Or reboot the Pi:
sudo reboot
Output
No direct output; WiFi connects if credentials are correct.
⚠️

Common Pitfalls

Common mistakes when setting up WiFi on Raspberry Pi include:

  • Typing the wrong ssid or psk (password).
  • Not saving the wpa_supplicant.conf file properly.
  • Forgetting to restart the network service or reboot after changes.
  • Using incorrect file permissions or editing the wrong file.
  • Trying to connect to hidden networks without proper settings.

Always double-check your WiFi name and password and ensure the file format is correct.

conf
Wrong way:
network={
    ssid=HomeWiFi
    psk=mypassword123
}

Right way:
network={
    ssid="HomeWiFi"
    psk="mypassword123"
    key_mgmt=WPA-PSK
}
📊

Quick Reference

Summary tips for WiFi setup on Raspberry Pi:

  • Edit /etc/wpa_supplicant/wpa_supplicant.conf to add your network.
  • Use double quotes around ssid and psk.
  • Restart network with sudo wpa_cli -i wlan0 reconfigure or reboot.
  • Check WiFi status with iwconfig or ifconfig wlan0.
  • Use Raspberry Pi OS desktop network icon for easy setup if available.

Key Takeaways

Edit /etc/wpa_supplicant/wpa_supplicant.conf with your WiFi name and password to connect via command line.
Always use double quotes around ssid and psk values in the config file.
Restart the network service or reboot the Raspberry Pi after changes to apply them.
Check your WiFi connection status with commands like iwconfig or ifconfig wlan0.
Use the desktop network icon for a simple graphical way to connect if using Raspberry Pi OS with GUI.