Arduino/C2/Analog-to-Digital-Conversion/English

From Script | Spoken-Tutorial
Revision as of 19:03, 2 January 2020 by Nancyvarkey (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
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