Arduino/C2/Wireless-Connectivity-to-Arduino/English
Visual Cue | Narration |
Slide 1: | Welcome to the Spoken Tutorial on Wireless Connectivity to Arduino |
Slide 2:
Learning objectives |
In this tutorial, we will learn to:
|
Slide 3:
Pre-requisites |
To follow this tutorial, you should have a basic knowledge of:
|
Slide 4:
System Requirement |
To record this tutorial, I am using:
|
Slide 5:
External Components Required |
We will require a few external components such as
|
Slide 6:
Image ESP8266-01 module.jpg |
In this tutorial we will use ESP8266-01 WiFi module.
VCC, RST, CH_PD, Tx, Ground, GPIO2, GPIO0, Rx are the pins of the Wi-Fi module. Power LED indicates whether the module is ON or OFF. COMM LED is the built-in blue LED of the WiFi module. In this tutorial, we will see how to control this built-in LED using WiFi. |
Slide 7:
About ESP8266 - 01 Module |
* This WiFi module has a built-in System on Chip with integrated TCP/IP stack.
|
Slide 8:
Image ESP Connection.png |
This is the circuit connection of ESP8266 - 01 module with Arduino.
Note: The ESP8266-01 module works on 3.3V only. Connecting it to 5V may damage the Wi-Fi module.
|
Slide 9:
Live Setup Image Setup Connection.jpg |
This is the live setup of the connection, as shown in the circuit diagram.
Do the connection as shown here. We will establish a connection between WiFi module and a laptop or a mobile phone. |
Open Arduino IDE | Now we will write a program in Arduino IDE.
Open Arduino IDE. |
Narration | Connect your Arduino board to your PC. |
Go to the Tools menu. Select port option.
Tools => Port. |
First, we need to know the name of the port to which arduino is connected.
Go to the Tools menu. Select port option. In my case, the port is ttyUSB0. Note down your port name. Windows users can skip the steps below as the port is detected automatically. |
Type, sudo chmod a+rw /dev/ttyUSB0 | Open the terminal by pressing Ctrl+Alt+t keys simultaneously.
Type, sudo space chmod space a+rw space slash dev slash ttyUSB0 In my case, the port name is ttyUSB0 You have to specify your port name. Press Enter. Enter your password for the system and press Enter. The above command gives read-write permission to the usb port. |
Switch back to Arduino IDE | Switch back to Arduino IDE. |
Next we will configure the ESP8266 module to communicate. | |
Click File => Preferences | In the menu bar, click on the File menu.
Select Preferences. A new window will appear. In the Settings tab, go to the Additional Boards Manager URLs section. Add this json URL. This will help to download ESP8266 WiFi module in Arduino IDE. Click on the OK button at the bottom of the window. |
Click Tools => Board => Boards Manager | In the menu bar, click on the Tools menu and select Board.
Then select Boards Manager option. A new window will appear. In the top right corner, we can see a search tab. Here, type ESP8266 and press enter. |
Select ESP8266 Community Module
Click on version drop down box Click on install button |
Select ESP8266 by ESP8266 Community.
In the version drop down box, select the latest version of the module. Click on install button to install the module. Installation will take few minutes to complete. Wait until it is installed successfully. |
Point to Installed button
Click on the Close button |
The ESP8266 module is now installed in the Arduino IDE.
Click on the Close button at the right bottom of the window. |
Tools => Board => Generic 8266 Module
Select ESP8266 module to upload the program. |
Now, before uploading the program we have to select the ESP8266 module.
Click on the Tools option and select board. Scroll down and select Generic ESP8266 Module. |
Tools => Builtin LED = 1. | Next we need to set the built in LED of ESP8266 Module.
Again select Tools. Go to Builtin LED option. Set the Builtin LED to 1. |
Tools => Reset Method = no dtr (aka ck). | Next we will set the Reset option.
In the menu bar, select Tools. Go to Reset Method. Select Reset method to no dtr (aka ck). This will help to reset the wifi module manually. |
#include <ESP8266WiFi.h> | Now we will write the code.
Type the code as shown. We have included the ESP8266 library. |
const char* ssid = "WIFI_ESP8266_Pratik"; | SSID is the name of a Wi-Fi module.
Here, I have named the wifi network as WIFI_ESP8266_Pratik. |
const char* password = "12345678"; | Password is the passcode to join the Wi-Fi network.
And the password for the module is 12345678. You have to give your unique ssid and password. Password parameter is not mandatory. If you don’t give password parameter, Wi-Fi network will be open. It will be accessible to everyone nearby. |
WiFiServer server(80); | This command will enable the default IP Address of the module.
The default IP Address of the module is 192.168.4.1 |
void setup()
{ delay(1000); WiFi.softAP(ssid, password); server.begin(); delay(2000); |
Inside the setup function, write the code as shown.
This command will enable the SSID and Password for the ESP8266 module. server.begin will enable the Wi-Fi network for the given SSID and Password. A delay of 2 seconds is given to boot the module. |
pinMode(BUILTIN_LED, OUTPUT);
delay(100); digitalWrite(BUILTIN_LED, HIGH); } |
Built-In LED of the ESP8266 module is set to OUTPUT mode. |
void loop()
{ // Check if a client has connected WiFiClient client = server.available(); if (!client) { return; } |
Copy and paste the code inside void loop function.
This code is available in the Code files link of this tutorial You can download and use it. |
while(!client.available())
{ delay(1); } String req = client.readStringUntil('\r'); client.flush(); |
|
if (req.indexOf("/LED_1/off") != -1)
digitalWrite(BUILTIN_LED, HIGH); else if (req.indexOf("LED_1/on") != -1) digitalWrite(BUILTIN_LED, LOW);
else { client.stop(); return; } client.flush(); |
|
HTML += "<h3>Blue LED is now ";
client.print(HTML); delay(10); } Image HTML_Page.png |
This HTML code will generate a web page as shown here.(image to be shown)
When LED ON or LED OFF button is pressed, the value is passed to the program. The program checks the value and controls the built-in LED of the ESP8266-01 module. |
Click on the compile button on the toolbar | Click on the compile button to verify the program.
A pop up window will appear to save the current program Name the program as WiFi_ESP8266 and click on the save button to save the program. |
Click on the upload button on the toolbar
Press push button when the program is getting uploaded |
Now click on upload button to upload the current program on ESP8266-01.
We can see the program getting uploaded at the bottom of the screen. When the state changes to connecting, press the push button on the breadboard. Release it after 2 to 3 seconds. |
We will see a message as Leaving…. Soft resetting as shown here.
This indicates that the program is uploaded successfully. | |
WiFi => Search for available network nearby => Select your WiFi module => enter password => join the network. | Switch off your mobile internet.
Open Wi-Fi option of your mobile phone. Search for nearest network to connect. In my case, I am getting WIFI_ESP8266_Pratik since I have given this name in the code. Select the WiFi. Enter the password and check if it is connected to WiFi. |
Go to Web Browser => enter the IP address i.e. 192.168.4.1 | Open Web Browser in your mobile phone.
Enter the IP address 192.168.4.1 This is the default IP Address of ESP8266-01 Wi-Fi module by the manufacturer. |
Web Page => Press LED ON to turn on the built-in LED.
Press LED OFF to turn off the built-in LED. Image Module_OFF.jpg Image Module_ON.jpg |
The web page opens as per the HTML code.
We can see, the LED of ESP8266-01 module is OFF. Click on LED ON button which will turn on the blue LED of the Wi-Fi module. It will be ON until we press the LED OFF button. Click on LED OFF button which will turn off the blue LED of the Wi-Fi module. |
This brings us to the end of this tutorial. Let us summarize. | |
Slide 10:
Summary |
In this tutorial, we learnt to
|
Slide 11:
Assignment |
As an assignment:
|
You should see the output of the assignment as shown here. | |
Slide 12:
About Spoken Tutorial Project |
The video at the following link summarizes the Spoken Tutorial Project
Please download and watch it |
Slide 13:
Spoken-Tutorial Workshop |
The Spoken Tutorial Project Team:
|
Slide 14:
Forum for specific questions |
Please post your timed queries in this forum |
Slide 15:
Acknowledgement |
Spoken Tutorial Project is funded by MHRD, Government of India. |
This tutorial has been contributed by FOSSEE and Spoken Tutorial Project, IIT Bombay.
And this is saurabh signing off. Thanks for joining. |