Arduino/C3/Sending-data-to-the-cloud-using-IoT-devices/English
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
|
Slide 3:
Pre-Requisites |
To follow this tutorial, you should have a basic knowledge of:
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:
|
Slide 5:
External Components DHT11.jpg MB102 Power Supply.jpg |
We also require some external components such as
|
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.
|
Slide 6:
MQTT Protocol |
* We will be using the MQTT protocol to send data over the network.
|
We will see the circuit connection of DHT11 and WiFi module with Arduino. | |
Image DHT-Arduino.png
Image Data Pin-GPIO2.png |
* Connect the VCC pin of the DHT11 sensor to the 5V pin of Arduino.
Note: The ESP8266 module works on 3.3V only. 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 |
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. |
MB102_setup2.jpg | Keep the white button of the module towards the right side of the breadboard as shown in the image. |
MB102_setup3.jpg MB102_setup4.jpg |
There 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_setup5.jpg |
We can see a power jack point on the MB102 module.
Plug in a 9V-1A adapter in this power jack. |
MB102_setup6.jpg | To turn ON or OFF the MB102 module, we have to press the white button. |
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. |
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.
|
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: |
|
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 |
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. |
Click File => Preferences | Next we will configure the ESP8266 module to communicate.
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 the Board Manager option. 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. | |
Download Following Library in Arduino IDE. | Click on the Sketch option.
Select Include Library and then click on Manage Libraries. A new window will open. Type Simple DHT on the search box. Select the latest version and install the Simple DHT by Winlin. |
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>
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 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 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 uploaded successfully. |
Rx-Tx Connection.png | After Uploading the code, disconnect the GPIO pin 0 of ESP8266 module from ground. |
Slide:
Working of ThingSpeak channel |
|
Let's see the 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 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. |
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 |
|
This brings us to the end of this tutorial. Let us summarize. | |
Slide 11:
Summary |
In this tutorial, we learnt to:
|
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
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. |