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
|
Slide 6:
MQTT Protocol |
|
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
|
|
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 => 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
|
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>
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
|
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. |
|
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 |
|
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. Click on the OK button at the bottom of the window. 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 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. |