Introduction: Interace Arduino WiFi Shield

About: Im a tech enthusiast

The Arduino WiFi shield allows an Arduino board to connect to the internet using the WiFi library and to read and write an SD card using the SD library.

The WiFi Library is included with the most recent version of the Arduino IDE. The firmware for the WiFi shield has changed in Arduino IDE 1.0.4. It is strongly recommended to install this update per these instructions

To use the shield, mount it on top of an Arduino board (e.g. the Uno). To upload sketches to the board, connect it to your computer with a USB cable as you normally would. Once the sketch has been uploaded, you can disconnect the board from your computer and power it with an external power supply.

Digital pin 7 is used as a handshake pin between the WiFi shield and the Arduino, and should not be used.

Step 1: Using the Shield With Older Boards


If you are using the WiFi shield with an Arduino earlier than the Uno rev3, you need to make the connection below for the board to work. The WiFi board uses the IOREF pin on newer Arduino pin layouts (Uno rev3, Mega2560 rev3, and later) to sense the reference voltage for the I/O pins of the board to which it is attached. If you are using the shield with an older board, you need to connect the shield's IOREF pin to 3.3V. You can do this either with a jumper wire connecting IOREF to 3.3V as shown in the photo below, or by soldering the IOREF jumper on the bottom of the shield, shown below. WARNING: If you use the solder jumper, do not connect the shield to a rev3 or later board. To be safe, remove the IOREF pin on the shield. Otherwise, you will be shorting 3.3V to 5V through the IOREF pin.

Step 2: Scan for Available Networks


The sketch below is a good one to run the first time you use the board in a new area. This sketch will not connect to a network, but it will show you what networks the shield can view. Your WiFi shield will probably not see as many networks as a computer with a larger WiFi antenna. Once you have downloaded the sketch to your Arduino, open the serial port to see available networks.

CODE

#include <WiFi.h>

#include <SPI.h>

void setup() {

// initialize serial and wait for the port to open:

Serial.begin(9600);

while(!Serial) ;

// attempt to connect using WEP encryption:

Serial.println("Initializing Wifi...");

printMacAddress();

// scan for existing networks:

Serial.println("Scanning available networks...");

listNetworks();

}

void loop() {

delay(10000);

// scan for existing networks:

Serial.println("Scanning available networks...");

listNetworks();

}

void printMacAddress() {

// the MAC address of your Wifi shield

byte mac[6];

// print your MAC address:

WiFi.macAddress(mac);

Serial.print("MAC: ");

Serial.print(mac[5],HEX);

Serial.print(":");

Serial.print(mac[4],HEX);

Serial.print(":");

Serial.print(mac[3],HEX);

Serial.print(":");

Serial.print(mac[2],HEX);

Serial.print(":");

Serial.print(mac[1],HEX);

Serial.print(":");

Serial.println(mac[0],HEX);

}

void listNetworks() {

// scan for nearby networks:

Serial.println("** Scan Networks **");

byte numSsid = WiFi.scanNetworks();

// print the list of networks seen:

Serial.print("number of available networks:");

Serial.println(numSsid);

// print the network number and name for each network found:

for (int thisNet = 0; thisNet

Serial.print(thisNet);

Serial.print(") ");

Serial.print(WiFi.SSID(thisNet));

Serial.print("\tSignal: ");

Serial.print(WiFi.RSSI(thisNet));

Serial.print(" dBm");

Serial.print("\tEncryption: ");

Serial.println(WiFi.encryptionType(thisNet));

}

}

Step 3: ​ Open Network Example


The sketch below shows you how to initiate a connection with an open network named "yourNetwork".

CODE

#include <WiFi.h>

char ssid[] = "yourNetwork"; // the name of your network

int status = WL_IDLE_STATUS; // the Wifi radio's status

void setup() {

// initialize serial:

Serial.begin(9600);

// attempt to connect to an open network:

Serial.println("Attempting to connect to open network...");

status = WiFi.begin(ssid);

// if you're not connected, stop here:

if ( status != WL_CONNECTED) {

Serial.println("Couldn't get a wifi connection");

while(true);

}

// if you are connected :

else {

Serial.print("Connected to the network");

}

}

void loop() {

}

Step 4: WPA Network Example


The example below shows how to connect to a WPA/WPA2 Personal encrypted network named "yourNetwork" with a password "12345678".

#include <WiFi.h>

char ssid[] = "yourNetwork"; // your network SSID (name)

char pass[] = "12345678"; // your network password

int status = WL_IDLE_STATUS; // the Wifi radio's status

void setup() {

// initialize serial:

Serial.begin(9600);

// attempt to connect using WPA2 encryption:

Serial.println("Attempting to connect to WPA network...");

status = WiFi.begin(ssid, pass);

// if you're not connected, stop here:

if ( status != WL_CONNECTED) {

Serial.println("Couldn't get a wifi connection");

while(true);

}

// if you are connected, print out info about the connection:

else {

Serial.println("Connected to network");

}

}

void loop() {

}