Difference between revisions of "Arduino/C2/Analog-to-Digital-Conversion/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with " {| style="border-spacing:0;" | style="background-color:#d9d2e9;border-top:1.5pt solid #000000;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:n...")
 
 
Line 16: Line 16:
  
 
* '''ADC i.e. Analog to Digital Conversion'''
 
* '''ADC i.e. Analog to Digital Conversion'''
* '''ADC pins''' in Arduino
+
* '''ADC pins''' in '''Arduino'''
 
* '''ADC Resolution'''
 
* '''ADC Resolution'''
 
* '''DHT11 Temperature and Humidity''' sensor
 
* '''DHT11 Temperature and Humidity''' sensor
Line 36: Line 36:
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| To record this tutorial, I am using:
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| To record this tutorial, I am using:
  
* '''Arduino Uno''' board
+
* '''Arduino Uno board'''
 
* '''Ubuntu Linux 16.04 OS'''
 
* '''Ubuntu Linux 16.04 OS'''
 
* '''Arduino IDE'''
 
* '''Arduino IDE'''
Line 46: Line 46:
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| We require few '''external components''' such as
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| We require few '''external components''' such as
  
* '''DHT11''' sensor
+
* '''DHT11 sensor'''
* Breadboard
+
* '''Breadboard'''
 
* '''Jumper wires'''
 
* '''Jumper wires'''
  
Line 58: Line 58:
  
 
Image '''DHT11_pin.jpg'''
 
Image '''DHT11_pin.jpg'''
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| This sensor collects analog values and gives it to '''Arduino Uno'''.
+
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| This '''sensor''' collects '''analog''' values and gives it to '''Arduino Uno'''.
  
'''Arduino ADC''' pins will convert these analog values to digital values.
+
'''Arduino ADC''' pins will convert these '''analog''' values to '''digital''' values.
  
 
|-
 
|-
Line 70: Line 70:
  
 
Image '''ADC_Resolution.png'''
 
Image '''ADC_Resolution.png'''
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| * '''Arduino Uno''' has'' '''''10-bit resolution'''.<br/>  
+
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"|'''Arduino Uno''' has '''10-bit resolution'''.<br/>  
  
 
This means, it can detect (2 to the power of 10) i.e. '''1024 discrete analog levels.'''
 
This means, it can detect (2 to the power of 10) i.e. '''1024 discrete analog levels.'''
  
 
* '''Resolution''' is the '''smallest change''' that can be measured
 
* '''Resolution''' is the '''smallest change''' that can be measured
* Arduino gives 5V output voltage, so 5V divided by 1024 levels gives '''4.89mV.'''
+
* '''Arduino''' gives 5V output voltage, so 5V divided by 1024 levels gives '''4.89mV.'''
* That means, '''Arduino Uno '''can be '''sensitive''' to a '''minimal change of 4.89mV.'''
+
* That means, '''Arduino Uno '''can be '''sensitive''' to a minimal change of '''4.89mV.'''
  
 
|-
 
|-
Line 87: Line 87:
  
 
* '''Arduino Uno''' has '''6 '''built-in''' ADC channels''' ('''A0 to A5''').
 
* '''Arduino Uno''' has '''6 '''built-in''' ADC channels''' ('''A0 to A5''').
* '''ADC channels''' read analog signal in the range of '''0-5V.'''
+
* '''ADC channels''' read '''analog signal''' in the range of '''0-5V.'''
 
* '''Pin 1 '''of the '''DHT11 sensor '''is connected to 5V pin of '''Arduino'''.
 
* '''Pin 1 '''of the '''DHT11 sensor '''is connected to 5V pin of '''Arduino'''.
* '''Pin 2 '''of the '''DHT11 sensor''' is''' '''the''' Data''' pin.
+
* '''Pin 2 '''of the '''DHT11 sensor''' is the''' Data''' pin.
* This''' Data pin '''of the sensor is connected to''' analog pin A0 '''of '''Arduino'''.
+
* This''' Data''' pin of the '''sensor''' is connected to''' analog''' pin '''A0 '''of '''Arduino'''.
* '''Pin 3 '''of the '''DHT11 sensor''' is connected to the ground''' '''pin of the '''Arduino'''.
+
* '''Pin 3 '''of the '''DHT11 sensor''' is connected to the '''ground''' pin of the '''Arduino'''.
  
 
|-
 
|-
Line 119: Line 119:
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| A new window will appear.
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| A new window will appear.
  
In the top right corner, we can see a search tab.
+
In the top right corner, we can see a '''search''' tab.
  
Here, type '''DHT11''' and press Enter.
+
Here, type '''DHT11''' and press '''Enter'''.
  
 
|-
 
|-
Line 129: Line 129:
  
 
Click on '''install''' button
 
Click on '''install''' button
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| We can see various libraries for''' DHT11 sensor.'''
+
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| We can see various '''libraries''' for''' DHT11 sensor.'''
  
 
Scroll down to the bottom of the screen and select '''SimpleDHT''' by '''Winlin.'''
 
Scroll down to the bottom of the screen and select '''SimpleDHT''' by '''Winlin.'''
  
In the '''version''' drop down box, we can select the latest version of the library.
+
In the '''version''' drop down box, we can select the latest version of the '''library'''.
  
Click on '''install''' button to install the library.  
+
Click on '''Install''' button to install the '''library'''.  
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:none;padding:0.176cm;"| Click on the Close button
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:none;padding:0.176cm;"| Click on the Close button
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| The '''DHT11''' library is now installed in the '''Arduino IDE'''.
+
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| The '''DHT11 library''' 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.
Line 145: Line 145:
 
|-
 
|-
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:none;padding:0.176cm;"| Click on the '''Sketch >>''' '''Include Library'''
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:none;padding:0.176cm;"| Click on the '''Sketch >>''' '''Include Library'''
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| Let us add this library to the program.
+
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| Let us add this '''library''' to the '''program'''.
  
 
Click on the '''Sketch '''menu and select '''Include Library.'''
 
Click on the '''Sketch '''menu and select '''Include Library.'''
  
Newly downloaded library usually appear at the end.
+
Newly downloaded '''library''' usually appear at the end.
  
 
So scroll down to the bottom of the list and select '''SimpleDHT.'''
 
So scroll down to the bottom of the list and select '''SimpleDHT.'''
Line 157: Line 157:
  
 
<nowiki>#include <SimpleDHT.h></nowiki>
 
<nowiki>#include <SimpleDHT.h></nowiki>
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| We can see the header file''' SimpleDHT.h '''added''' '''in the code window.
+
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| We can see the header file''' SimpleDHT.h '''added in the code window.
 
|-
 
|-
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:none;padding:0.176cm;"| int pinDHT11 = A0;
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:none;padding:0.176cm;"| int pinDHT11 = A0;
Line 167: Line 167:
 
Here we have initialized the data pin of '''DHT11 sensor''' which is connected to '''A0.'''
 
Here we have initialized the data pin of '''DHT11 sensor''' which is connected to '''A0.'''
  
This command creates a '''DHT''' object.
+
This '''command''' creates a '''DHT object'''.
  
 
|-
 
|-
Line 184: Line 184:
 
}
 
}
  
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| Inside '''void setup''' function, type the code as shown:
+
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| Inside '''void setup function''', type the code as shown:
  
'''Serial.begin()''' function initiate the serial communication.
+
'''Serial.begin() function''' initiate the '''serial communication'''.
  
 
It sets the '''data rate''' in''' bits per second''' for '''serial data transmission.'''
 
It sets the '''data rate''' in''' bits per second''' for '''serial data transmission.'''
  
9600 represents the baud rate.
+
'''9600''' represents the '''baud rate'''.
  
'''delay(500)''' is the delay time for the sensor to boot.
+
'''delay(500)''' is the '''delay time''' for the '''sensor''' to '''boot'''.
  
'''Serial.print''' command prints the header as specified here.
+
'''Serial.print command''' prints the '''header''' as specified here.
  
 
|-
 
|-
Line 222: Line 222:
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| Now we will write the code for '''void loop.'''
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| Now we will write the code for '''void loop.'''
  
We have created two variables '''temperature''' and '''humidity''' for '''DHT sensor''' output.
+
We have created two '''variables temperature''' and '''humidity''' for '''DHT sensor''' output.
  
'''dht11.read,''' reads the data from the sensor.
+
'''dht11.read,''' reads the '''data''' from the '''sensor'''.
  
 
It stores the result in '''microcontroller’s register.'''
 
It stores the result in '''microcontroller’s register.'''
  
These lines prints the temperature in degrees celsius and humidity in percentage.
+
These lines prints the temperature in '''degree Celsius''' and humidity in '''percentage'''.
  
 
'''delay(2000)''' updates the current humidity and temperature readings every''' 2 seconds.'''
 
'''delay(2000)''' updates the current humidity and temperature readings every''' 2 seconds.'''
  
This code is available in the code files link of this tutorial
+
This code is available in the '''Code files''' link of this tutorial.
  
 
You can download and use it.
 
You can download and use it.
Line 239: Line 239:
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:none;padding:0.176cm;"| Click on compile and upload button on the toolbar
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:none;padding:0.176cm;"| Click on compile and upload button on the toolbar
  
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| '''Click''' on the''' compile''' button to verify your''' program.'''
+
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| Click on the''' compile''' button to verify your''' program.'''
  
A pop up window will appear to save the current program.
+
A pop up window will appear to save the current '''program'''.
  
Save the program as '''DHT11.'''
+
Save the '''program''' as '''DHT11.'''
  
 
Now click on '''upload''' button to upload the current '''program''' on''' Arduino.'''
 
Now click on '''upload''' button to upload the current '''program''' on''' Arduino.'''
Line 254: Line 254:
 
For this, click on the''' Tools '''menu and select '''Serial monitor.'''
 
For this, click on the''' Tools '''menu and select '''Serial monitor.'''
  
The serial monitor window opens.
+
The '''serial monitor''' window opens.
  
 
Temperature and humidity of the current place is displayed as expected.
 
Temperature and humidity of the current place is displayed as expected.
Line 263: Line 263:
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:none;padding:0.176cm;"| Go to '''Arduino IDE'''.
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:none;padding:0.176cm;"| Go to '''Arduino IDE'''.
  
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| Next we will see the output in the serial plotter.
+
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| Next we will see the output in the '''serial plotter'''.
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:none;padding:0.176cm;"| Type double slash
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:none;padding:0.176cm;"| Type double slash
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| Let us modify the program.
+
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| Let us modify the '''program'''.
  
Comment the line '''Serial.print( “Temperature & Humidity :”);''' as shown.
+
'''Comment''' the line '''Serial.print( “Temperature & Humidity :”);''' as shown.
  
 
This will not print the text '''Temperature''' and '''Humidity'''.
 
This will not print the text '''Temperature''' and '''Humidity'''.
Line 277: Line 277:
 
|-
 
|-
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:none;padding:0.176cm;"| Click upload
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:none;padding:0.176cm;"| Click upload
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| Let us upload the current program to see the results on serial plotter.
+
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| Let us upload the current '''program''' to see the results on '''serial plotter'''.
  
 
Click on the''' tools menu''' and select '''serial plotter. '''
 
Click on the''' tools menu''' and select '''serial plotter. '''
Line 287: Line 287:
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| We can see two lines simultaneously plotting the points.
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| We can see two lines simultaneously plotting the points.
  
The blue line indicates the temperature which is around 28 to 30 *C
+
The blue line indicates the temperature which is around 28 to 30 °C.
  
 
The red line is the humidity reading which is near to 45%.
 
The red line is the humidity reading which is near to 45%.
Line 293: Line 293:
 
The readings will vary depending upon where the experiment is done.
 
The readings will vary depending upon where the experiment is done.
  
Now cover the sensor with your hands and you will see the fluctuating readings.
+
Now cover the '''sensor''' with your hands and you will see the fluctuating readings.
  
 
Close the window.
 
Close the window.
Line 301: Line 301:
  
 
Features of DHT11
 
Features of DHT11
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| * It is useful for '''humidity''' readings between '''20%-80% '''with''' ∓5%''' '''RH i.e.''' '''(Relative Humidity)'''
+
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"|  
* It is useful for''' temperature '''readings between''' 0-50°C '''with''' ∓2 °C'''
+
* It is useful for '''humidity''' readings between '''20%-80% '''with''' ∓5% RH''' i.e. '''(Relative Humidity)'''
 +
* It is useful for temperature readings between''' 0-50 °C '''with''' ∓2 °C'''
  
 
|-
 
|-
Line 317: Line 318:
 
* '''ADC pins''' in '''Arduino'''
 
* '''ADC pins''' in '''Arduino'''
 
* '''ADC Resolution'''
 
* '''ADC Resolution'''
* '''DHT11 Temperature and Humidity''' sensor
+
* '''DHT11 Temperature''' and '''Humidity sensor'''
 
* '''Serial Monitor '''and''' Serial Plotter'''
 
* '''Serial Monitor '''and''' Serial Plotter'''
  
Line 328: Line 329:
 
# Raise an alarm by glowing the built in '''LED''' '''pin 13''' of the '''Arduino'''  
 
# Raise an alarm by glowing the built in '''LED''' '''pin 13''' of the '''Arduino'''  
 
# Modify the above existing code.
 
# Modify the above existing code.
#:'''Hint: '''
+
#:Hint: Use '''If-else statement'''.
# Use '''If-else '''statement.
+
  
 
|-
 
|-
Line 337: Line 337:
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"|  
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"|  
  
# Add 1 or 2 deg C to the temperature value that you get on the serial monitor.
+
# Add 1 or 2 °C to the temperature value that you get on the '''serial monitor'''.
 
# To increase the temperature reading, cover the '''DHT11 sensor '''with your hands.
 
# To increase the temperature reading, cover the '''DHT11 sensor '''with your hands.
 
# Refer to the '''Assignment''' link of this tutorial for the source code.
 
# Refer to the '''Assignment''' link of this tutorial for the source code.
Line 346: Line 346:
 
About Spoken Tutorial Project
 
About Spoken Tutorial Project
  
*
+
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| The video at the following link summarizes the '''Spoken Tutorial Project'''
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| The video at the following '''link''' summarizes the '''Spoken Tutorial Project'''
+
  
Please '''download''' and watch it
+
Please download and watch it.
  
 
|-
 
|-
Line 356: Line 355:
 
Spoken-Tutorial Workshop
 
Spoken-Tutorial Workshop
  
*
 
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| The '''Spoken Tutorial Project''' Team:
 
  
* Conducts '''Workshops''' &
+
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| The '''Spoken Tutorial Project''' Team conducts workshops and gives certificates.
* Gives Certificates
+
  
 
|-
 
|-
Line 380: Line 375:
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| This tutorial has been contributed by '''FOSSEE''' and Spoken Tutorial Project, IIT Bombay.  
 
| style="border-top:none;border-bottom:1.5pt solid #000000;border-left:1.5pt solid #000000;border-right:1.5pt solid #000000;padding:0.176cm;"| This tutorial has been contributed by '''FOSSEE''' and Spoken Tutorial Project, IIT Bombay.  
  
And this is''' Saurabh''' signing off.  
+
And this is Saurabh signing off.  
  
 
Thanks for joining.
 
Thanks for joining.
  
 
|}
 
|}

Latest revision as of 19:03, 2 January 2020

Visual Cue Narration
Slide 1: Welcome to the Spoken Tutorial on Analog to Digital Conversion using Arduino.
Slide 2:

Learning objectives

In this tutorial, we will learn about :
  • ADC i.e. Analog to Digital Conversion
  • ADC pins in Arduino
  • ADC Resolution
  • DHT11 Temperature and Humidity sensor
  • Serial Monitor and Serial Plotter
Slide 3:

Pre-requisites

To follow this tutorial, you should have a basic knowledge of:
  • Electronics and
  • C or C++ programming language
Slide 4:

System Requirement

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

External Components Required

We require few external components such as
  • DHT11 sensor
  • Breadboard
  • Jumper wires
Narration only In this tutorial, we will detect the temperature and humidity using DHT11 sensor.
Slide 6:

Image DHT11_pin.jpg

This sensor collects analog values and gives it to Arduino Uno.

Arduino ADC pins will convert these analog values to digital values.

Narration Next, we will understand the concept of resolution.
Slide 7:

Image ADC_Resolution.png

Arduino Uno has 10-bit resolution.

This means, it can detect (2 to the power of 10) i.e. 1024 discrete analog levels.

  • Resolution is the smallest change that can be measured
  • Arduino gives 5V output voltage, so 5V divided by 1024 levels gives 4.89mV.
  • That means, Arduino Uno can be sensitive to a minimal change of 4.89mV.
Slide 8:

Image DHT11_Interface.png

Point to the image as per narration

This shows the circuit connection for DHT11 with Arduino.
  • Arduino Uno has 6 built-in ADC channels (A0 to A5).
  • ADC channels read analog signal in the range of 0-5V.
  • Pin 1 of the DHT11 sensor is connected to 5V pin of Arduino.
  • Pin 2 of the DHT11 sensor is the Data pin.
  • This Data pin of the sensor is connected to analog pin A0 of Arduino.
  • Pin 3 of the DHT11 sensor is connected to the ground pin of the Arduino.
Slide 9:

Image Setup_Connection.jpg

This is the live setup of the connection, as shown in the circuit diagram.
Open Arduino IDE. Now we will write the program in Arduino IDE.

Open Arduino IDE.

narration First we need to download the DHT11 arduino library to run this program.
Click Sketch => Include Library => Manage Libraries Click on Sketch menu in the menu bar.

Select Include Library and then click on Manage Libraries option.

In the search tab, type DHT11 A new window will appear.

In the top right corner, we can see a search tab.

Here, type DHT11 and press Enter.

Select SimpleDHT by Winlin.

Click on version drop down box

Click on install button

We can see various libraries for DHT11 sensor.

Scroll down to the bottom of the screen and select SimpleDHT by Winlin.

In the version drop down box, we can select the latest version of the library.

Click on Install button to install the library.

Click on the Close button The DHT11 library is now installed in the Arduino IDE.

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

Click on the Sketch >> Include Library Let us add this library to the program.

Click on the Sketch menu and select Include Library.

Newly downloaded library usually appear at the end.

So scroll down to the bottom of the list and select SimpleDHT.

Point to the header file

#include <SimpleDHT.h>

We can see the header file SimpleDHT.h added in the code window.
int pinDHT11 = A0;

SimpleDHT11 dht11(pinDHT11);

Type the code as shown.

Here we have initialized the data pin of DHT11 sensor which is connected to A0.

This command creates a DHT object.

void setup()

{

Serial.begin(9600);

delay(500);

Serial.println("DHT11 Humidity & Temperature Sensor\n\n");

delay(1000);

}

Inside void setup function, type the code as shown:

Serial.begin() function initiate the serial communication.

It sets the data rate in bits per second for serial data transmission.

9600 represents the baud rate.

delay(500) is the delay time for the sensor to boot.

Serial.print command prints the header as specified here.

void loop()

{

byte temperature = 0;

byte humidity = 0;

dht11.read(pinDHT11, &temperature, &humidity, NULL);

Serial.print(" Temperature & Humidity : ");

Serial.print((int)temperature);

Serial.print(" *C ");

Serial.print((int)humidity);

Serial.println(" % H");

delay(2000);

}

Now we will write the code for void loop.

We have created two variables temperature and humidity for DHT sensor output.

dht11.read, reads the data from the sensor.

It stores the result in microcontroller’s register.

These lines prints the temperature in degree Celsius and humidity in percentage.

delay(2000) updates the current humidity and temperature readings every 2 seconds.

This code is available in the Code files link of this tutorial.

You can download and use it.

Click on compile and upload button on the toolbar Click on the compile button to verify your program.

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

Save the program as DHT11.

Now click on upload button to upload the current program on Arduino.

Point to the output in the video

Serial Monitor

We will see the output in the Serial monitor screen.

For this, click on the Tools menu and select Serial monitor.

The serial monitor window opens.

Temperature and humidity of the current place is displayed as expected.

Close the window.

Go to Arduino IDE. Next we will see the output in the serial plotter.
Type double slash Let us modify the program.

Comment the line Serial.print( “Temperature & Humidity :”); as shown.

This will not print the text Temperature and Humidity.

For plotting, we require only the values of temperature and humidity.

Click upload Let us upload the current program to see the results on serial plotter.

Click on the tools menu and select serial plotter.

The serial plotter window opens.

Point to the output We can see two lines simultaneously plotting the points.

The blue line indicates the temperature which is around 28 to 30 °C.

The red line is the humidity reading which is near to 45%.

The readings will vary depending upon where the experiment is done.

Now cover the sensor with your hands and you will see the fluctuating readings.

Close the window.

Slide 10:

Features of DHT11

  • It is useful for humidity readings between 20%-80% with ∓5% RH i.e. (Relative Humidity)
  • It is useful for temperature readings between 0-50 °C with ∓2 °C
This brings us to the end of this tutorial. Let us summarize.
Slide 11:

Summary

In this tutorial, we learnt about:
  • ADC i.e. Analog to Digital Conversion
  • ADC pins in Arduino
  • ADC Resolution
  • DHT11 Temperature and Humidity sensor
  • Serial Monitor and Serial Plotter
Slide 12:

Assignment

As an assignment:
  1. Raise an alarm by glowing the built in LED pin 13 of the Arduino
  2. Modify the above existing code.
    Hint: Use If-else statement.
Slide 12(B):

Assignment

  1. Add 1 or 2 °C to the temperature value that you get on the serial monitor.
  2. To increase the temperature reading, cover the DHT11 sensor with your hands.
  3. Refer to the Assignment link of this tutorial for the source code.
Slide 13:

About Spoken Tutorial Project

The video at the following link summarizes the Spoken Tutorial Project

Please download and watch it.

Slide 14:

Spoken-Tutorial Workshop


The Spoken Tutorial Project Team conducts workshops and gives certificates.
Slide 15:

Forum for specific questions

Please post your timed queries in this forum
Slide 16:

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.

Contributors and Content Editors

Nancyvarkey, Nirmala Venkat