Difference between revisions of "Arduino/C3/Sending-data-to-the-cloud-using-IoT-devices/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with " {| border="1" |- || Visual Cue || Narration |- || Slide 1: || Welcome to the''' '''Spoken Tutorial on '''Sending data to the cloud using IoT devices.''' |- ||Slide 2: Learni...")
 
Line 13: Line 13:
  
 
|| In this tutorial, we will learn how to
 
|| In this tutorial, we will learn how to
* Establish connection between '''ESP8266-01''' and '''DHT11 '''sensor
+
* Establish connection between '''ESP8266-01''' and '''DHT11 sensor'''
* Collect '''Temperature''' and '''Humidity''' values given by '''DHT11''' sensor
+
* Collect '''Temperature''' and '''Humidity''' values given by '''DHT11 sensor'''
* Use '''ThingSpeak''' platform to store and visualize sensor readings and
+
* Use '''ThingSpeak''' platform to store and visualize '''sensor''' readings and
* Download the data in '''CSV''' file
+
* Download the '''data''' in '''CSV''' file
 
|-
 
|-
 
||Slide 3:
 
||Slide 3:
Line 26: Line 26:
 
* '''C or C++ '''programming language
 
* '''C or C++ '''programming language
 
* '''ThingSpeak''' account and
 
* '''ThingSpeak''' account and
* Write '''API''' Key
+
* Write '''API Key'''
  
 
If not, then go through the relevant '''Arduino''' spoken tutorials on this website.
 
If not, then go through the relevant '''Arduino''' spoken tutorials on this website.
Line 35: Line 35:
 
||To record this tutorial, here I am using:
 
||To record this tutorial, here I am using:
 
* '''Ubuntu Linux 16.04''' OS
 
* '''Ubuntu Linux 16.04''' OS
* '''Arduino UNO''' board
+
* '''Arduino UNO board'''
 
* '''Arduino IDE'''
 
* '''Arduino IDE'''
 
|-
 
|-
Line 51: Line 51:
  
 
Point to Tx Rx
 
Point to Tx Rx
|| * '''ESP8266-01 WiFi Module'''
+
|| '''ESP8266-01 WiFi Module'''
Recall that we have learnt about the pins of '''ESP8266-01 WiFi '''module in the earlier tutorial.
+
*Recall that we have learnt about the '''pins''' of '''ESP8266-01 WiFi module''' in the earlier tutorial.
* This wifi module is widely used for the development of '''IoT '''applications.
+
* This '''wifi module''' is widely used for the development of '''IoT applications'''.
* It has a built-in '''System on Chip''' with integrated '''TCP/IP stack.'''
+
* It has a '''built-in System on Chip''' with integrated '''TCP/IP stack.'''
 
|-
 
|-
 
||Slide 6:
 
||Slide 6:
 
MQTT Protocol
 
MQTT Protocol
|| * We will be using the '''MQTT''' protocol to send data over the network.
+
||  
* MQTT stands for '''Message Queuing Telemetry Transport.'''
+
* We will be using the '''MQTT protocol''' to send '''data''' over the '''network'''.
* It is a simple messaging protocol, designed for devices with low bandwidth.
+
* '''MQTT''' stands for '''Message Queuing Telemetry Transport.'''
* We can read and publish data from sensors on the cloud.
+
* It is a simple '''messaging protocol''', designed for devices with low '''bandwidth'''.
 +
* We can read and publish '''data''' from '''sensors''' on the cloud.
 
|-
 
|-
 
||  
 
||  
||We will see the circuit connection of''' DHT11 '''and''' WiFi '''module with '''Arduino'''.
+
||We will see the circuit connection of''' DHT11 '''and''' WiFi module''' with '''Arduino'''.
 
|-
 
|-
 
||Image '''DHT-Arduino.png'''
 
||Image '''DHT-Arduino.png'''
Image '''Data Pin-GPIO2.png'''
+
 
|| * Connect the '''VCC '''pin of the '''DHT11''' sensor to the 5V''' '''pin of Arduino.
+
Highlight the individual connections
* Connect the '''ground '''pin of the '''DHT11''' sensor to the ground pin of Arduino.
+
|| Connect the '''VCC pin''' of the '''DHT11 sensor''' to the '''5V pin''' of '''Arduino'''.
* Connect '''Data pin''' of '''DHT11''' sensor to '''GPIO2''' of '''ESP8266''' Module.
+
 
 +
Connect the '''ground pin''' of the '''DHT11 sensor''' to the '''ground pin''' of '''Arduino'''.
 +
|-
 +
||Image '''Data Pin-GPIO2.png'''
 +
 
 +
Highlight the individual connections
 +
 
 +
 
 +
 
 +
||Connect '''Data pin''' of '''DHT11 sensor''' to '''GPIO2''' of '''ESP8266 Module'''.
 +
 
 
Note:  
 
Note:  
The '''ESP8266''' module works on 3.3V only.
+
The '''ESP8266 module''' works only on '''3.3V'''.
Connecting it to 5V may '''damage''' the''' Wi-Fi''' module.
+
Connecting it to '''5V''' may damage the''' Wi-Fi module'''.
 
|-
 
|-
 
||  
 
||  
|| Next we will see how to set up the''' MB102 '''module on Breadboard.
+
|| Next we will see how to set up the''' MB102 module''' on '''Breadboard'''.
 
|-
 
|-
 
||'''MB102 folder:'''
 
||'''MB102 folder:'''
 
MB102_setup1.jpg
 
MB102_setup1.jpg
||We need to use the 3.3V supply to power up the '''wifi''' module.
 
  
Make sure that the yellow coloured jumpers in the module are fixed on the 3.3V and '''OFF''' Pins.
+
Highlight the jumpers
 +
||We need to use the '''3.3V''' supply to power up the '''wifi module'''.
 +
 
 +
Make sure that the yellow coloured '''jumpers''' in the '''modules''' are fixed on the '''3.3V''' and '''OFF pins'''.
 
|-
 
|-
 
|| MB102_setup2.jpg
 
|| MB102_setup2.jpg
|| Keep the white button of the module towards the right side of the breadboard as shown in the image.
+
 
 +
Highlight the white button
 +
|| Keep the white button of the '''module''' towards the right side of the '''breadboard''' as shown in the image.
 
|-
 
|-
 
||
 
||
Line 91: Line 106:
 
MB102_setup3.jpg
 
MB102_setup3.jpg
  
MB102_setup4.jpg
+
Highlight the pins
||There are pins in pairs at the bottom of the '''MB102''' module.  
+
||These are '''pins''' in pairs at the bottom of the '''MB102 module'''.  
  
Place these pins of the module on the power rails of the breadboard as shown in the image.
+
|-
 +
||MB102_setup4.jpg
 +
 
 +
Highlight the pins
 +
||Place these '''pins''' of the '''module''' on the '''power rails''' of the '''breadboard''' as shown in the image.
 
|-
 
|-
 
||
 
||
 
MB102_setup5.jpg
 
MB102_setup5.jpg
||We can see a power jack point on the '''MB102''' module.
+
 
Plug in a '''9V-1A''' adapter in this power jack.
+
Highlight the power jack
 +
||We can see a '''power jack point''' on the '''MB102 module'''.
 +
Plug in a '''9V-1A adapter''' in this '''power jack'''.
 
|-
 
|-
 
|| MB102_setup6.jpg
 
|| MB102_setup6.jpg
|| To turn ON or OFF the '''MB102''' module, we have to press the white button.
+
 
 +
Highlight the white button
 +
|| To turn '''ON''' or '''OFF''' the '''MB102 module''', we have to press the white button.
 
|-
 
|-
 
|| MB102_setup7.jpg
 
|| MB102_setup7.jpg
||When the green light is turned on, it means the module is switched on.
 
  
Now the setup of the '''MB102''' module is completed.
+
Green light is on
 +
||When the green light is turned '''on''', it means the '''module''' is switched '''on'''.
 +
 
 +
Now the setup of the '''MB102 module''' is completed.
 
|-
 
|-
 
||  
 
||  
Line 113: Line 138:
 
|-
 
|-
 
||Image '''ESP-Power Supply Module 3.3V.png'''
 
||Image '''ESP-Power Supply Module 3.3V.png'''
 +
 +
 
Image '''ESP-Power Supply Module GND.png'''
 
Image '''ESP-Power Supply Module GND.png'''
 +
 +
 
Image '''RST-GND.png'''
 
Image '''RST-GND.png'''
 +
 +
 
Image '''GPIO0-GND.png'''
 
Image '''GPIO0-GND.png'''
 +
 +
 
Image '''Rx-Tx Connection.png'''
 
Image '''Rx-Tx Connection.png'''
|| * Connect '''VCC and CH_PD''' pins of '''ESP8266''' to 3.3V pin of '''MB102 power supply module'''.
+
||  
* Connect '''GND''' pin of '''ESP8266''' to '''ground''' pin of '''MB102 '''power supply module.
+
* Connect '''VCC''' and '''CH_PD pins''' of '''ESP8266''' to '''3.3V pin''' of '''MB102 power supply module'''.
* Connect the '''RST''' pin of '''ESP8266''' module to one end of the '''push button'''.
+
* Connect '''GND''' pin of '''ESP8266''' to '''ground pin''' of '''MB102 power supply module'''.
* This push button is used for resetting the '''WiFi''' module.
+
* Connect the '''RST''' that is '''Reset pin''' of '''ESP8266 module''' to one end of the '''push button'''.
* Connect the other end of the push button to the '''ground '''terminal of '''Arduino'''
+
* This '''push button''' is used for '''reset'''ting the '''WiFi module'''.
* Connect GPIO pin 0 of '''ESP8266''' module to ground.
+
* Connect the other end of the '''push button''' to the '''ground terminal''' of '''Arduino'''
* Connect the '''Tx pin''' of '''ESP8266''' to the '''Tx pin''' of the Arduino.
+
* Connect '''GPIO pin 0''' of '''ESP8266 module''' to '''ground'''.
* Connect the '''Rx pin''' of '''ESP8266''' to the''' Rx pin''' of the Arduino.
+
* Connect the '''Tx pin''' of '''ESP8266''' to the '''Tx pin''' of the '''Arduino'''.
 +
* Connect the '''Rx pin''' of '''ESP8266''' to the''' Rx pin''' of the '''Arduino'''.
  
 
|-
 
|-
Line 140: Line 174:
 
Code Files:
 
Code Files:
 
||
 
||
* Thefiles used in this tutorial are available in the'''Code Files '''link on this tutorial page.
+
* The files used in this tutorial are available in the'''Code files '''link on this tutorial page.
 
* Please download and extract them   
 
* Please download and extract them   
 
* Make a copy and then use them while practising
 
* Make a copy and then use them while practising
Line 148: Line 182:
 
|-
 
|-
 
|| Narration
 
|| Narration
|| Connect your Arduino board to your PC.
+
|| Connect your '''Arduino board''' to your PC.
 
|-
 
|-
 
||
 
||
Line 154: Line 188:
 
Go to the Tools menu. Select '''port''' option.
 
Go to the Tools menu. Select '''port''' option.
 
Tools => Port.
 
Tools => Port.
||First, we need to know the name of the port to which arduino is connected.
+
||First, we need to know the name of the '''port''' to which '''Arduino''' is connected.
 +
 
 
In the menu bar, go to the '''Tools''' menu. Select '''port''' option.
 
In the menu bar, 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.
+
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.
 
|-
 
|-
 
|| Open the'''terminal'''
 
|| Open the'''terminal'''
Line 164: Line 201:
 
||
 
||
  
Type,'''sudo chmod a+rw /dev/ttyUSB0'''
+
Type,'''sudo chmod a+rw /dev/ttyUSB0''' => press Enter
 
||Type, '''sudo space chmod space a+rw space slash dev slash ttyUSB0'''
 
||Type, '''sudo space chmod space a+rw space slash dev slash ttyUSB0'''
 +
 
In my case, the '''port''' name is '''ttyUSB0'''
 
In my case, the '''port''' name is '''ttyUSB0'''
 +
 
You have to specify your '''port''' name.
 
You have to specify your '''port''' name.
 +
 
Press '''Enter'''.
 
Press '''Enter'''.
Enter your '''password''' for the '''system''' and press '''Enter'''.
+
|-
 +
||Type password => press Enter
 +
 
 +
 
 +
 
 +
||Enter the '''password''' for the system and press '''Enter'''.
 +
 
 
The above '''command''' gives '''read-write permission''' to the '''USB port.'''
 
The above '''command''' gives '''read-write permission''' to the '''USB port.'''
 
|-
 
|-
Line 180: Line 226:
  
 
Click on the '''File''' menu. Select '''Preferences'''.
 
Click on the '''File''' menu. Select '''Preferences'''.
A new window will appear.
+
|-
 +
||New window => Settings => Additional Boards Manager URLs
 +
 
 +
 
 +
 
 +
 
 +
Click on Ok button
 +
||A new window will appear.
 +
 
 
In the '''Settings''' tab, go to the '''Additional Boards Manager URLs '''section.
 
In the '''Settings''' tab, go to the '''Additional Boards Manager URLs '''section.
Add this '''json''' '''URL'''.
+
 
 +
Add this '''json URL'''.
 
This will help to download '''ESP8266 WiFi module '''in''' Arduino IDE.'''
 
This will help to download '''ESP8266 WiFi module '''in''' Arduino IDE.'''
  
Line 189: Line 244:
 
||Click Tools => Board => Boards Manager
 
||Click Tools => Board => Boards Manager
 
||In the menu bar, click on the '''Tools''' menu and select '''Board'''.
 
||In the menu bar, click on the '''Tools''' menu and select '''Board'''.
 +
 
Then select the '''Board Manager''' option.
 
Then select the '''Board Manager''' option.
A new window will appear.
+
|-
 +
||New windown => Search tab => type ESP8266
 +
||A new window will appear.
 +
 
 
In the top right, we can see a '''search tab'''.
 
In the top right, we can see a '''search tab'''.
Here, type '''ESP8266''' and press enter.
+
 
 +
Here, type '''ESP8266''' and press '''Enter'''.
 
|-
 
|-
 
||Select ESP8266 Community Module
 
||Select ESP8266 Community Module
 +
 
Click on version drop down box
 
Click on version drop down box
Click on '''install''' button
+
 
 +
Click on '''Install''' button
 
||Select '''ESP8266 by ESP8266 Community'''.
 
||Select '''ESP8266 by ESP8266 Community'''.
  
In the version drop down box, select the '''latest version '''of the module.
+
In the version drop down box, select the '''latest version '''of the '''module'''.
  
Click on the '''install '''button to install the module.  
+
Click on the '''Install '''button to install the '''module'''.  
  
 
Installation will take few minutes to complete.  
 
Installation will take few minutes to complete.  
Line 210: Line 272:
  
 
Click on the Close button
 
Click on the Close button
||The '''ESP8266''' module is now installed in the '''Arduino IDE'''.
+
||The '''ESP8266 module''' is now installed in the '''Arduino IDE'''.
  
 
Click on the '''Close''' button at the right bottom of the window.
 
Click on the '''Close''' button at the right bottom of the window.
 
|-
 
|-
 
||  
 
||  
|| Next, we need to download a''' DHT sensor''' library to successfully run the code.
+
|| Next, we need to download a''' DHT sensor library''' to successfully run the code.
 
|-
 
|-
||Download Following Library in Arduino IDE.
+
||Click on Sketch => select Include Library => Manage Libraries
 
||Click on the '''Sketch''' option.
 
||Click on the '''Sketch''' option.
  
 
Select '''Include Library''' and then click on '''Manage Libraries'''.
 
Select '''Include Library''' and then click on '''Manage Libraries'''.
A new window will open.
+
|-
 +
||New window => Search box => type Simple DHT => select the latest version and install
 +
||A new window will open.
  
Type '''Simple DHT''' on the search box.
+
Type '''Simple DHT''' on the '''search''' box.
  
 
Select the latest version and install the '''Simple DHT by Winlin'''.
 
Select the latest version and install the '''Simple DHT by Winlin'''.
 
|-
 
|-
 
||  
 
||  
 +
 +
Click on Close button
 
||Make sure that the above steps are done successfully before proceeding further.
 
||Make sure that the above steps are done successfully before proceeding further.
 
Click on the '''Close''' button at the right bottom of the window.  
 
Click on the '''Close''' button at the right bottom of the window.  
Line 238: Line 304:
 
String apiKey = "N9FEWDVPBUFUII32";  
 
String apiKey = "N9FEWDVPBUFUII32";  
  
||We have included the '''DHT and ESP8266 '''libraries to the code.
+
||We have included the '''DHT and ESP8266 libraries''' to the code.
  
Here, we have to enter our channel '''Write API key '''which we generated already.
+
Here, we have to enter our '''channel Write API key '''which we generated already.
 
|-
 
|-
 
||char *ssid = "Pratik";  
 
||char *ssid = "Pratik";  
 +
 
char *pass = "Pratikjb@";
 
char *pass = "Pratikjb@";
 +
 
char* server = "api.thingspeak.com";
 
char* server = "api.thingspeak.com";
  
||'''SSID''' is the '''name''' of the '''Wi-Fi''' module.
+
||'''SSID''' is the '''name''' of the '''Wi-Fi module'''.
  
Pass is the '''passcode '''to join the '''Wi-Fi''' network
+
'''Pass''' is the '''passcode '''to join the '''Wi-Fi network'''.
  
You have to give a unique ssid and password.
+
You have to give a unique '''ssid''' and '''password'''.
  
This is the Thingspeak api server, where we will be uploading the data.
+
This is the '''Thingspeak api server''', where we will be uploading the '''data'''.
 
|-
 
|-
 
||#define pinDHT11 2
 
||#define pinDHT11 2
Line 260: Line 328:
 
WiFiClient client;
 
WiFiClient client;
  
||Define the data pin of '''DHT11''' sensor connected to '''ESP8266''' module as shown here.
+
||Define the '''data pin''' of '''DHT11 sensor''' connected to '''ESP8266 module''' as shown here.
This code sets the DHT11 data pin.
+
 
This line of code creates a client to the specified IP address or server.
+
This '''code''' sets the '''DHT11 data pin'''.
 +
 
 +
This line of '''code''' creates a '''client''' to the specified '''IP address''' or '''server'''.
 
|-
 
|-
 
||void setup()
 
||void setup()
Line 274: Line 344:
 
}
 
}
  
||Type this code in the void setup function.
+
||Type this '''code''' in the '''void setup function'''.
  
Here, the baud rate is set to 115200 as the WiFi module works on 115200 baud rate.
+
Here, the '''baud rate''' is '''set''' to '''115200''' as the '''WiFi module''' works on '''115200 baud rate'''.
  
The connection is established with the '''ssid''' and password which we declared earlier.
+
The connection is established with the '''ssid''' and '''password''' which we declared earlier.
  
 
We will establish a connection between '''ThingSpeak server '''and''' ESP8266 WiFi module. '''
 
We will establish a connection between '''ThingSpeak server '''and''' ESP8266 WiFi module. '''
  
 
|-
 
|-
||
+
||Type the code from the Code files provided or copy-paste in the IDE
||Type this code in the void loop function.
+
||Type this '''code''' in the '''void loop function'''.
  
We have declared two variables for humidity and temperature.
+
We have '''declared''' two '''variables''' for '''humidity''' and '''temperature'''.
  
This will read the temperature and humidity values.
+
This will read the '''temperature''' and '''humidity''' values.
  
First check whether the connection is established between the '''ThingSpeak cloud and WiFi module.'''
+
First check whether the connection is established between the '''ThingSpeak cloud''' and '''WiFi module.'''
  
Then the data including humidity, temperature and API keys will be sent to the server.
+
Then the '''data''' including '''humidity, temperature''' and '''API keys''' will be sent to the '''server'''.
  
Based on the API key value, the ThingSpeak server automatically selects the channel.
+
Based on the '''API key''' value, the '''ThingSpeak server''' automatically selects the '''channel'''.
  
This prints the data on the '''ThingSpeak''' server where the WiFi module will be connected.
+
This prints the '''data''' on the '''ThingSpeak server''' where the '''WiFi module''' will be connected.
  
 
We are done with the required coding.
 
We are done with the required coding.
 
|-
 
|-
||Click on the compile button to save the program
+
||Click on the '''Compile''' button => follow the intuitive steps to save the program.
  
||Let us compile and save the program.
+
||Let us '''compile''' and save the program.
  
Click on the''' compile''' button to verify the''' program.'''
+
Click on the''' Compile''' button to verify the''' program.'''
  
A pop up window will appear to save the current program.
+
A pop up window will appear to save the current '''program'''.
  
Name the program as '''DHT11_IoT '''and click on the save button to save the program.
+
Name the '''program''' as '''DHT11_IoT '''and click on the '''Save''' button to save the '''program'''.
 
|-
 
|-
 
||Tools => Board => Generic ESP8266 Module
 
||Tools => Board => Generic ESP8266 Module
 +
  
 
Select ESP8266 module to upload the program.
 
Select ESP8266 module to upload the program.
||Now, before uploading the program we have to select the '''ESP8266''' module.
+
||Now, before uploading the '''program''' we have to select the '''ESP8266 module'''.
  
 
Click on the '''Tools''' option and select '''board'''.
 
Click on the '''Tools''' option and select '''board'''.
Line 322: Line 393:
 
||Next step is to select the '''Reset''' option.  
 
||Next step is to select the '''Reset''' option.  
  
In the menu bar, select '''Tools'''. Go to the Reset''' Method'''.
+
In the menu bar, select '''Tools'''. Go to the '''Reset Method'''.
  
 
Select '''no dtr (aka ck).'''
 
Select '''no dtr (aka ck).'''
  
This will help to reset the wifi module manually.
+
This will help to '''reset''' the '''wifi module''' manually.
 
|-
 
|-
|| Tools => Builtin LED = 1
+
||  
||Next we need to set the built in LED of '''ESP8266 Module'''.
+
 
 +
 
 +
Tools => Builtin LED = 1
 +
||Next we need to '''set''' the '''built in LED''' of '''ESP8266 Module'''.
 +
 
 
Again select '''Tools'''.
 
Again select '''Tools'''.
 +
 
Go to the '''Builtin LED '''option. Set the''' Builtin LED''' to '''1.'''
 
Go to the '''Builtin LED '''option. Set the''' Builtin LED''' to '''1.'''
 
|-
 
|-
||Click on the upload button
+
||Click on the Upload button
  
||Now click on the upload button to upload the current program on''' ESP8266-01. '''
+
||Now click on the '''Upload''' button to upload the current '''program''' on''' ESP8266-01. '''
We can see the program getting uploaded at the bottom of the screen.
+
 
Now the program has been uploaded successfully.
+
We can see the '''program''' getting uploaded at the bottom of the screen.
 +
 
 +
Now the '''program''' has been successfully uploaded.
 
|-
 
|-
||Rx-Tx Connection.png
+
||Rx-Tx Connection.png => disconnect
|| After Uploading the code, disconnect the '''GPIO pin 0''' of '''ESP8266''' module from ground.
+
|| After uploading the '''code''', disconnect the '''GPIO pin 0''' of '''ESP8266 module''' from ground.
 
|-
 
|-
 
||Slide:
 
||Slide:
Line 346: Line 424:
 
Working of '''ThingSpeak''' channel
 
Working of '''ThingSpeak''' channel
 
||
 
||
* First, the DHT11 module will get connected to the WiFi network.
+
* First, the '''DHT11 module''' will get connected to the '''WiFi network'''.
* It will read temperature and humidity data from the sensor.
+
* It will read '''temperature''' and '''humidity''' data from the '''sensor'''.
* After a few seconds, these values will be uploaded to '''ThingSpeak''' channel
+
* After a few seconds, these values will be uploaded to '''ThingSpeak channel'''
 
|-
 
|-
||  
+
|| ThingSpeak''' page => graphs
||Let's see the output on our channel created on '''ThingSpeak'''.
+
||Let's see our output on our '''channel''' created on '''ThingSpeak'''.
  
 
Go to the '''ThingSpeak''' page.
 
Go to the '''ThingSpeak''' page.
  
We can see a graph of temperature and humidity values from the DHT11 sensor.
+
We can see a graph of '''temperature''' and '''humidity''' values from the '''DHT11 sensor'''.
 
|-
 
|-
 
||  
 
||  
|| Next, we will see how to export the current data of''' DHT11''' sensor.
+
|| Next, we will see how to export the current data of''' DHT11 sensor'''.
 
|-
 
|-
||
+
||Download the Data in CSV file
 +
 
 +
 
 +
 
 +
Click on Data Import/Export => scroll down => Export => select time zone => click on Download button => click on Save button
 +
||Click on the '''Data Import/Export''' option on the '''GUI''' of your '''channel'''.
 +
 
 +
Scroll down to see the '''Export''' option on the left side.
 +
 
 +
Select the time zone as shown here.
 +
 
 +
Now click on '''Download''' button.
  
Download the Data in CSV file
+
Click on the '''Save''' button.  
||Click on the '''Data Import/Export''' option on the GUI of your channel.
+
Scroll down to see the '''Export''' option on the left side
+
Select the time zone as shown here
+
Now Click on '''Download''' button
+
Click on the save button.  
+
 
|-
 
|-
||  
+
|| Go to Downloads folder => locate and open CSV
||Let us open the downloaded CSV file.
+
||Let us open the downloaded '''CSV''' file.
 +
 
 
Go to the '''Downloads''' folder and open the '''CSV''' file.
 
Go to the '''Downloads''' folder and open the '''CSV''' file.
This is the temperature and humidity data that is collected from the sensor.  
+
 
 +
This is the '''temperature''' and '''humidity data''' that is collected from the '''sensor'''.  
 
|-
 
|-
 
||Slide 10:CSV File
 
||Slide 10:CSV File
  
 
||  
 
||  
* With the '''ThingSpeak''' platform, it is possible to fetch the device reading in CSV file.
+
* With the '''ThingSpeak''' platform, it is possible to fetch the device reading in '''CSV''' file.
* This is useful to do data analytics using R or Matlab.
+
* This is useful to help '''data analytics''' using '''R''' or '''Matlab'''.
* Go through the R Spoken tutorials for data analytics.
+
* Go through the '''R Spoken tutorials''' for '''data analytics'''.
  
 
|-
 
|-
Line 390: Line 476:
 
||In this tutorial, we learnt to:
 
||In this tutorial, we learnt to:
 
* Establish connection between '''ESP8266-01''' and '''DHT11 sensor'''
 
* Establish connection between '''ESP8266-01''' and '''DHT11 sensor'''
* Collect '''Temperature''' and '''Humidity''' values given by '''DHT11''' Sensor
+
* Collect '''Temperature''' and '''Humidity''' values given by '''DHT11 Sensor'''
* Use '''ThingSpeak''' platform to store and visualize sensor readings and
+
* Use '''ThingSpeak''' platform to store and visualize '''sensor''' readings and
* Download the data in '''CSV''' file
+
* Download the '''data''' in '''CSV''' file
  
 
|-
 
|-
Line 404: Line 490:
  
 
Spoken Tutorial workshops
 
Spoken Tutorial workshops
||The''' Spoken Tutorial Project''' Team:* conducts workshops and
+
||The''' Spoken Tutorial Project''' Team conducts workshops and gives certificates.
* gives certificates.
+
 
For more details, please write to us.
 
For more details, please write to us.
 
|-
 
|-

Revision as of 08:29, 30 January 2021


Visual Cue Narration
Slide 1: Welcome to the Spoken Tutorial on Sending data to the cloud using IoT devices.
Slide 2:

Learning Objectives

In this tutorial, we will learn how to
  • Establish connection between ESP8266-01 and DHT11 sensor
  • Collect Temperature and Humidity values given by DHT11 sensor
  • Use ThingSpeak platform to store and visualize sensor readings and
  • Download the data in CSV file
Slide 3:

Pre-Requisites

To follow this tutorial, you should have a basic knowledge of:
  • Wireless Communication
  • C or C++ programming language
  • ThingSpeak account and
  • Write API Key

If not, then go through the relevant Arduino spoken tutorials on this website.

Slide 4:

System Requirements

To record this tutorial, here I am using:
  • Ubuntu Linux 16.04 OS
  • Arduino UNO board
  • Arduino IDE
Slide 5:

External Components DHT11.jpg

MB102 Power Supply.jpg

We also require some external components such as
  • DHT11 Sensor
  • MB102 Breadboard Power Supply Module
ESP8266-01 WiFi Module.jpg

Point to Tx Rx

ESP8266-01 WiFi Module
  • Recall that we have learnt about the pins of ESP8266-01 WiFi module in the earlier tutorial.
  • This wifi module is widely used for the development of IoT applications.
  • It has a built-in System on Chip with integrated TCP/IP stack.
Slide 6:

MQTT Protocol

  • We will be using the MQTT protocol to send data over the network.
  • MQTT stands for Message Queuing Telemetry Transport.
  • It is a simple messaging protocol, designed for devices with low bandwidth.
  • We can read and publish data from sensors on the cloud.
We will see the circuit connection of DHT11 and WiFi module with Arduino.
Image DHT-Arduino.png

Highlight the individual connections

Connect the VCC pin of the DHT11 sensor to the 5V pin of Arduino.

Connect the ground pin of the DHT11 sensor to the ground pin of Arduino.

Image Data Pin-GPIO2.png

Highlight the individual connections


Connect Data pin of DHT11 sensor to GPIO2 of ESP8266 Module.

Note: The ESP8266 module works only on 3.3V. Connecting it to 5V may damage the Wi-Fi module.

Next we will see how to set up the MB102 module on Breadboard.
MB102 folder:

MB102_setup1.jpg

Highlight the jumpers

We need to use the 3.3V supply to power up the wifi module.

Make sure that the yellow coloured jumpers in the modules are fixed on the 3.3V and OFF pins.

MB102_setup2.jpg

Highlight the white button

Keep the white button of the module towards the right side of the breadboard as shown in the image.

MB102_setup3.jpg

Highlight the pins

These are pins in pairs at the bottom of the MB102 module.
MB102_setup4.jpg

Highlight the pins

Place these pins of the module on the power rails of the breadboard as shown in the image.

MB102_setup5.jpg

Highlight the power jack

We can see a power jack point on the MB102 module.

Plug in a 9V-1A adapter in this power jack.

MB102_setup6.jpg

Highlight the white button

To turn ON or OFF the MB102 module, we have to press the white button.
MB102_setup7.jpg

Green light is on

When the green light is turned on, it means the module is switched on.

Now the setup of the MB102 module is completed.

Let us see the other circuit connections.
Image ESP-Power Supply Module 3.3V.png


Image ESP-Power Supply Module GND.png


Image RST-GND.png


Image GPIO0-GND.png


Image Rx-Tx Connection.png

  • Connect VCC and CH_PD pins of ESP8266 to 3.3V pin of MB102 power supply module.
  • Connect GND pin of ESP8266 to ground pin of MB102 power supply module.
  • Connect the RST that is Reset pin of ESP8266 module to one end of the push button.
  • This push button is used for resetting the WiFi module.
  • Connect the other end of the push button to the ground terminal of Arduino
  • Connect GPIO pin 0 of ESP8266 module to ground.
  • Connect the Tx pin of ESP8266 to the Tx pin of the Arduino.
  • Connect the Rx pin of ESP8266 to the Rx pin of the Arduino.
Slide 9:

Live Setup

This is the live setup of the connection, as shown in the circuit diagram.
Now we will write the program in Arduino IDE for interfacing WiFi module and DHT11 Sensor.
Slide:

Code Files:

  • The files used in this tutorial are available in theCode files link on this tutorial page.
  • Please download and extract them
  • Make a copy and then use them while practising
Open 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.

In the menu bar, 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.

Open theterminal Open theterminal by pressingCtrl+Alt+t keys simultaneously.

Type,sudo chmod a+rw /dev/ttyUSB0 => press Enter

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.

Type password => press Enter


Enter the 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.
Click File => Preferences Next we will configure the ESP8266 module to communicate.

Click on the File menu. Select Preferences.

New window => Settings => Additional Boards Manager URLs



Click on Ok button

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 the Board Manager option.

New windown => Search tab => type ESP8266 A new window will appear.

In the top right, 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 the 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.

Next, we need to download a DHT sensor library to successfully run the code.
Click on Sketch => select Include Library => Manage Libraries Click on the Sketch option.

Select Include Library and then click on Manage Libraries.

New window => Search box => type Simple DHT => select the latest version and install A new window will open.

Type Simple DHT on the search box.

Select the latest version and install the Simple DHT by Winlin.

Click on Close button

Make sure that the above steps are done successfully before proceeding further.

Click on the Close button at the right bottom of the window.

Type the code as shown.
#include <SimpleDHT.h>
  1. include <WiFi.h>

String apiKey = "N9FEWDVPBUFUII32";

We have included the DHT and ESP8266 libraries to the code.

Here, we have to enter our channel Write API key which we generated already.

char *ssid = "Pratik";

char *pass = "Pratikjb@";

char* server = "api.thingspeak.com";

SSID is the name of the Wi-Fi module.

Pass is the passcode to join the Wi-Fi network.

You have to give a unique ssid and password.

This is the Thingspeak api server, where we will be uploading the data.

#define pinDHT11 2

SimpleDHT11 dht11(pinDHT11);

WiFiClient client;

Define the data pin of DHT11 sensor connected to ESP8266 module as shown here.

This code sets the DHT11 data pin.

This line of code creates a client to the specified IP address or server.

void setup()

{

Serial.println("");

Serial.println("WiFi connected");

}

Type this code in the void setup function.

Here, the baud rate is set to 115200 as the WiFi module works on 115200 baud rate.

The connection is established with the ssid and password which we declared earlier.

We will establish a connection between ThingSpeak server and ESP8266 WiFi module.

Type the code from the Code files provided or copy-paste in the IDE Type this code in the void loop function.

We have declared two variables for humidity and temperature.

This will read the temperature and humidity values.

First check whether the connection is established between the ThingSpeak cloud and WiFi module.

Then the data including humidity, temperature and API keys will be sent to the server.

Based on the API key value, the ThingSpeak server automatically selects the channel.

This prints the data on the ThingSpeak server where the WiFi module will be connected.

We are done with the required coding.

Click on the Compile button => follow the intuitive steps to save the program. Let us compile and save the program.

Click on the Compile button to verify the program.

A pop up window will appear to save the current program.

Name the program as DHT11_IoT and click on the Save button to save the program.

Tools => Board => Generic ESP8266 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 => Reset Method = no dtr (aka ck). Next step is to select the Reset option.

In the menu bar, select Tools. Go to the Reset Method.

Select no dtr (aka ck).

This will help to reset the wifi module manually.


Tools => Builtin LED = 1

Next we need to set the built in LED of ESP8266 Module.

Again select Tools.

Go to the Builtin LED option. Set the Builtin LED to 1.

Click on the Upload button Now click on the Upload button to upload the current program on ESP8266-01.

We can see the program getting uploaded at the bottom of the screen.

Now the program has been successfully uploaded.

Rx-Tx Connection.png => disconnect After uploading the code, disconnect the GPIO pin 0 of ESP8266 module from ground.
Slide:

Working of ThingSpeak channel

  • First, the DHT11 module will get connected to the WiFi network.
  • It will read temperature and humidity data from the sensor.
  • After a few seconds, these values will be uploaded to ThingSpeak channel
ThingSpeak page => graphs Let's see our output on our channel created on ThingSpeak.

Go to the ThingSpeak page.

We can see a graph of temperature and humidity values from the DHT11 sensor.

Next, we will see how to export the current data of DHT11 sensor.
Download the Data in CSV file


Click on Data Import/Export => scroll down => Export => select time zone => click on Download button => click on Save button

Click on the Data Import/Export option on the GUI of your channel.

Scroll down to see the Export option on the left side.

Select the time zone as shown here.

Now click on Download button.

Click on the Save button.

Go to Downloads folder => locate and open CSV Let us open the downloaded CSV file.

Go to the Downloads folder and open the CSV file.

This is the temperature and humidity data that is collected from the sensor.

Slide 10:CSV File
  • With the ThingSpeak platform, it is possible to fetch the device reading in CSV file.
  • This is useful to help data analytics using R or Matlab.
  • Go through the R Spoken tutorials for data analytics.
This brings us to the end of this tutorial. Let us summarize.
Slide 11:

Summary

In this tutorial, we learnt to:
  • Establish connection between ESP8266-01 and DHT11 sensor
  • Collect Temperature and Humidity values given by DHT11 Sensor
  • Use ThingSpeak platform to store and visualize sensor readings and
  • Download the data in CSV file
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 workshops

The Spoken Tutorial Project Team conducts workshops and gives certificates.

For more details, please write to us.

Slide 14:

Forum for specific questions

Please post your timed queries in this forum.
Slide 15:

Acknowledgement

The Spoken Tutorial project is funded by MHRD, Government of India.
This tutorial has been contributed by FOSSEE and Spoken Tutorial Project, IIT Bombay.

This is Saurabh signing off.

Thanks for watching.

Contributors and Content Editors

Nancyvarkey, Nirmala Venkat