Arduino/C3/Sending-data-to-the-cloud-using-IoT-devices/English-timed

From Script | Spoken-Tutorial
Revision as of 12:26, 17 June 2021 by Pratik kamble (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Time Narration
00:02 Welcome to the Spoken Tutorial on Sending data to the cloud using IoT devices.
00:08 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

00:25 Use ThingSpeak platform to store and visualize sensor readings and

Download the data in CSV file

00:35 To follow this tutorial, you should have a basic knowledge of:

Wireless Communication

C or C++ programming language

ThingSpeak account and

Write API Key

00:50 If not, then go through the relevant Arduino spoken tutorials on this website.
00:56 To record this tutorial, here I am using:

Ubuntu Linux 16.04 OS

Arduino UNO board

Arduino IDE

01:08 We also require some external components such as

DHT11 Sensor

MB102 Breadboard Power Supply Module

01:17 ESP8266-01 WiFi Module

Recall that we have learnt about the pins of ESP8266-01 WiFi module in the earlier tutorial.

01:28 This wifi module is widely used for the development of IoT applications.
01:34 It has a built-in System on Chip with integrated TCP/IP stack.
01:40 We will be using the MQTT protocol to send data over the network.
01:45 MQTT stands for Message Queuing Telemetry Transport.
01:50 It is a simple messaging protocol, designed for devices with low bandwidth.

We can read and publish data from sensors on the cloud.

02:00 We will see the circuit connection of DHT11 and WiFi module with Arduino.
02:06 Connect the VCC pin of the DHT11 sensor to the 5V pin of Arduino.
02:12 Connect the ground pin of the DHT11 sensor to the ground pin of Arduino.
02:17 Connect Data pin of DHT11 sensor to GPIO2 of ESP8266 Module.
02:24 Note: The ESP8266 module works only on 3.3V.

Connecting it to 5V may damage the Wi-Fi module.

02:34 Next we will see how to set up the MB102 module on Breadboard.
02:40 We need to use the 3.3V supply to power up the wifi module.
02:45 Make sure that the yellow coloured jumpers in the modules are fixed on the 3.3V and OFF pins.
02:53 Keep the white button of the module towards the right side of the breadboard as shown in the image.
02:59 These are pins in pairs at the bottom of the MB102 module.
03:04 Place these pins of the module on the power rails of the breadboard as shown in the image.
03:10 We can see a power jack point on the MB102 module.
03:14 Plug in a 9V-1A adapter in this power jack.
03:19 To turn ON or OFF the MB102 module, we have to press the white button.
03:25 When the green light is turned on, it means the module is switched on.
03:29 Now the setup of the MB102 module is completed.
03:34 Let us see the other circuit connections.
03:37 Connect VCC and CH_PD pins of ESP8266 to 3.3V pin of MB102 power supply module.
03:48 Connect GND pin of ESP8266 to ground pin of MB102 power supply module.
03:55 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.

04:05 Connect the other end of the push button to the ground terminal of Arduino

Connect GPIO pin 0 of ESP8266 module to ground.

04:16 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.

04:29 This is the live setup of the connection, as shown in the circuit diagram.
04:34 Now we will write the program in Arduino IDE for interfacing WiFi module and DHT11 Sensor.
04:40 The files used in this tutorial are available in the Code files link on this tutorial page.

Please download and extract them. Make a copy and then use them while practising

04:52 Open Arduino IDE.
04:56 Connect your Arduino board to your PC.
04:59 First, we need to know the name of the port to which Arduino is connected.
05:03 In the menu bar, go to the Tools menu. Select port option.
05:08 In my case, the port is ttyUSB0. Note down your port name.
05:16 Windows users can skip the steps below as the port is detected automatically.
05:23 Open theterminal by pressingCtrl+Alt+t keys simultaneously.
05:30 Type, sudo space chmod space a+rw space slash dev slash ttyUSB0
05:45 In my case, the port name is ttyUSB0
05:50 You have to specify your port name. Press Enter.
05:55 Enter the password for the system and press Enter.
06:00 The above command gives read-write permission to the USB port.
06:05 Switch back to Arduino IDE.
06:08 Next we will configure the ESP8266 module to communicate.
06:13 Click on the File menu. Select Preferences.
06:17 New window will appear. In the Settings tab, go to the Additional Boards Manager URLs section.
06:26 Add this json URL. This will help to download ESP8266 WiFi module in Arduino IDE.
06:35 Click on the OK button at the bottom of the window.
06:39 In the menu bar, click on the Tools menu and select Board. Then select the Board Manager option.
06:47 A new window will appear.
06:49 In the top right, we can see a search tab.
06:53 Here, type ESP8266 and press Enter.
06:58 Select ESP8266 by ESP8266 Community.
07:04 In the version drop down box, select the latest version of the module.
07:09 Click on the Install button to install the module.
07:13 Installation will take few minutes to complete. Wait until it is installed successfully.
07:19 The ESP8266 module is now installed in the Arduino IDE.
07:24 Click on the Close button at the right bottom of the window.
07:28 Next, we need to download a DHT sensor library to successfully run the code.
07:33 Click on the Sketch option. Select Include Library and then click on Manage Libraries.
07:41 A new window will open.
07:43 Type Simple DHT on the search box.
07:47 Select the latest version and install the Simple DHT by Winlin.
07:53 Make sure that the above steps are done successfully before proceeding further.
07:58 Click on the Close button at the right bottom of the window.
08:02 Type the code as shown. We have included the DHT and ESP8266 libraries to the code.
08:11 Here, we have to enter our channel Write API key which we generated already.
08:19 SSID is the name of the Wi-Fi module.
08:22 Pass is the passcode to join the Wi-Fi network.
08:26 You have to give a unique ssid and password. This is the Thingspeak api server, where we will be uploading the data.
08:36 Define the data pin of DHT11 sensor connected to ESP8266 module as shown here.
08:44 This code sets the DHT11 data pin.
08:48 This line of code creates a client to the specified IP address or server.
08:56 Type this code in the void setup function.
09:00 Here, the baud rate is set to 115200 as the WiFi module works on 115200 baud rate.
09:10 The connection is established with the ssid and password which we declared earlier.
09:18 We will establish a connection between ThingSpeak server and ESP8266 WiFi module.
09:24 Type this code in the void loop function.
09:28 We have declared two variables for humidity and temperature. This will read the temperature and humidity values.
09:37 First check whether the connection is established between the ThingSpeak cloud and WiFi module.
09:43 Then the data including humidity, temperature and API keys will be sent to the server.
09:50 Based on the API key value, the ThingSpeak server automatically selects the channel.
09:56 This prints the data on the ThingSpeak server where the WiFi module will be connected.
10:10 We are done with the required coding.
10:13 Let us compile and save the program.
10:16 Click on the Compile button to verify the program.
10:21 A pop up window will appear to save the current program.
10:25 Name the program as DHT11_IoT and click on the Save button to save the program.
10:35 Now, before uploading the program we have to select the ESP8266 module.
10:41 Click on the Tools option and select board. Scroll down and select Generic ESP8266 Module.
10:49 Next step is to select the Reset option.
10:53 In the menu bar, select Tools. Go to the Reset Method.
10:58 Select no dtr (aka ck). This will help to reset the wifi module manually.
11:07 Next we need to set the built in LED of ESP8266 Module.
11:12 Again select Tools. Go to the Builtin LED option. Set the Builtin LED to 1.
11:20 Now click on the Upload button to upload the current program on ESP8266-01.
11:27 We can see the program getting uploaded at the bottom of the screen.
11:31 Now the program has been successfully uploaded.
11:35 After uploading the code, disconnect the GPIO pin 0 of ESP8266 module from ground.
11:43 First, the DHT11 module will get connected to the WiFi network.
11:47 It will read temperature and humidity data from the sensor.

After a few seconds, these values will be uploaded to ThingSpeak channel

11:59 Let's see our output on our channel created on ThingSpeak. Go to the ThingSpeak page.
12:07 We can see a graph of temperature and humidity values from the DHT11 sensor.
12:13 Next, we will see how to export the current data of DHT11 sensor.
12:18 Click on the Data Import/Export option on the GUI of your channel.
12:24 Scroll down to see the Export option on the left side. Select the time zone as shown here.
12:32 Now click on Download button. Click on the Save button.
12:38 Let us open the downloaded CSV file.
12:41 Go to the Downloads folder and open the CSV file.
12:46 Click on the OK button at the bottom of the window.
12:50 This is the temperature and humidity data that is collected from the sensor.
12:55 With the ThingSpeak platform, it is possible to fetch the device reading in CSV file.
13:01 This is useful to help data analytics using R or Matlab.

Go through the R Spoken tutorials for data analytics.

13:10 This brings us to the end of this tutorial. Let us summarize.
13:15 In this tutorial, we learnt to:

Establish connection between ESP8266-01 and DHT11 sensor

Collect Temperature and Humidity values given by DHT11 Sensor

13:25 Use ThingSpeak platform to store and visualize sensor readings and

Download the data in CSV file

13:39 The video at the following link summarizes the Spoken Tutorial project. Please download and watch it.
13:45 The Spoken Tutorial Project Team conducts workshops and gives certificates.

For more details, please write to us.

13:54 Please post your timed queries in this forum.
13:58 The Spoken Tutorial project is funded by MHRD, Government of India.
14:04 This tutorial has been contributed by FOSSEE and Spoken Tutorial Project, IIT Bombay.
14:10 This is Saurabh signing off. Thanks for watching.

Contributors and Content Editors

Pratik kamble