raspbian headless setup wifi code example

Example 1: raspberry pi set wifi headless

crate a file in the root folder of the sd card ("boot") called 
wpa_supplicant.conf
===========contents of file:=================
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<Insert 2 letter ISO 3166-1 country code here>

network={
 ssid="<Name of your wireless LAN>"
 psk="<Password for your wireless LAN>"
}

Example 2: enable wifi raspberry pi headless

Make new file /boot/wpa_supplicant.conf:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country="{Your countries' ISO 3166-1 code}" 

network={
 ssid="{Name of Network}"
 psk="{Password}"
}