Tag Archive:Remove term: arduino kit

Byamber

Arduino lesson – DHT11 Sensor

Content

  1. Introduction
  2. Preparations
  3. About the DHT11
  4. Examples

Introduction

The digital temperature and humidity sensor DHT11 inside contains a chip that does analog to digital conversion and spits out a digital signal with the temperature and humidity, compatible with any MCUs, ideal for those who want some basic data logging stuffs. It’s very popular for electronics hobbyists because it is very cheap but still providing great performance.

In this lesson, we will first go into a little background about humidity, then we will explain how the DHT11 measures humidity. After that, we will show you how to connect the DHT11 to an Arduino and give you some example code so you can use the DHT11 in your own projects.

Preparations

Hardware

  • Osoyoo UNO Board (Fully compatible with Arduino UNO rev.3) x 1
  • DHT11 Sensor x 1
  • I2C LCD1602 x 1
  • 10k ohm Resistor x 1
  • Breadboard x 1
  • Jumpers
  • USB Cable x 1
  • PC x 1

Software

About DHT11

The DHT11 is a basic, ultra low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and spits out a digital signal on the data pin (no analog input pins needed). Its fairly simple to use, but requires careful timing to grab data.

Only three pins are available for use: VCC, GND, and DATA. The communication process begins with the DATA line sending start signals to DHT11, and DHT11 receives the signals and returns an answer signal. Then the host receives the answer signal and begins to receive 40-bit humiture data (8-bit humidity integer + 8-bit humidity decimal + 8-bit temperature integer + 8-bit temperature decimal + 8-bit checksum).

WHAT IS RELATIVE HUMIDITY?

The DHT11 measures relative humidity. Relative humidity is the amount of water vapor in air vs. the saturation point of water vapor in air. At the saturation point, water vapor starts to condense and accumulate on surfaces forming dew.

The saturation point changes with air temperature. Cold air can hold less water vapor before it becomes saturated, and hot air can hold more water vapor before it becomes saturated.

The formula to calculate relative humidity is:

RH = (\frac{\rho_{w}}{\rho_{s}}) \ x \ 100 \% \\ \\ RH: \ Relative \ Humidity \\ \rho_{w}: \ Density \ of \ water \ vapor\\ \rho_{s}: \ Density \ of \ water \ vapor \ at \ saturation

Relative humidity is expressed as a percentage. At 100% RH, condensation occurs, and at 0% RH, the air is completely dry.

HOW THE DHT11 MEASURES HUMIDITY AND TEMPERATURE

The DHT11 detects water vapor by measuring the electrical resistance between two electrodes. The humidity sensing component is a moisture holding substrate with electrodes applied to the surface. When water vapor is absorbed by the substrate, ions are released by the substrate which increases the conductivity between the electrodes. The change in resistance between the two electrodes is proportional to the relative humidity. Higher relative humidity decreases the resistance between the electrodes, while lower relative humidity increases the resistance between the electrodes.

The DHT11 measures temperature with a surface mounted NTC temperature sensor (thermistor) built into the unit.

With the plastic housing removed, you can see the electrodes applied to the substrate, an IC mounted on the back of the unit converts the resistance measurement to relative humidity. It also stores the calibration coefficients, and controls the data signal transmission between the DHT11 and the Arduino:

Diffrences Between DHT11 and DHT22

Dimension of DHT11

DHT11 Module

There are two different versions of the DHT11 you might come across. One type has four pins, and the other type has three pins and is mounted to a small PCB. The PCB mounted version is nice because it includes a surface mounted 10K Ohm pull up resistor for the signal line. Here are the pin outs for both versions:

Examples

Before you can use the DHT11 on the Arduino, you’ll need to install the DHT library. It has all the functions needed to get the humidity and temperature readings from the sensor. It’s easy to install, just download the DHT.zip file and open up the Arduino IDE. Then go to Sketch>Include Library>Add .ZIP Library and select the DHT.zip file.

Display Humidity and Temperature on the Serial Monitor

Connection

Build the circuit as below:

Simply ignore pin 3 of DHT11, its not used. You will want to place a 10K resistor between VCC and the data pin, to act as a medium-strength pull up on the data line. The Arduino has built in pullups you can turn on but they’re very weak, about 20-50K

This diagram shows how we will connect for the testing sketch. Connect data to pin 3, you can change it later to any pin.

Code Program

After above operations are completed, connect the Arduino board to your computer using the USB cable. The green power LED (labelled PWR) should go on. Load up the following sketch onto your Arduino.

#include<dht.h> dht DHT; 
// if you require to change the pin number, Edit the pin with your arduino pin. 
#define DHT11_PIN 3 
void setup() { 
Serial.begin(9600); 
Serial.println("The real time Temperature and Humidity is :"); 
} 
void loop() { // READ DATA int chk = DHT.read11(DHT11_PIN);
 Serial.print(" Humidity: " );
 Serial.print(DHT.humidity, 1);
 Serial.println('%');
 Serial.print(" Temparature ");
 Serial.print(DHT.temperature, 1);
 Serial.println('C');
 delay(2000); 
}

Running Result

A few seconds after the upload finishes, open the Serial Monitor, you should now see the humidity and temperature readings displayed at one second intervals.

Note: Please make sure you have choosed the correct port and the correct baudrate for you project.

Display Humidity and Temperature on the I2C 1602LCD

A nice way to display the humidity and temperature readings is on a 1I2C 1602LCD. To do this, first follow our tutorial on How to Set Up an LCD Display on an Arduino, then follow below operations and complete this project.

Connection

Build the circuit as below:

Code Program

After above operations are completed, connect the Arduino board to your computer using the USB cable. The green power LED (labelled PWR) should go on.Open the Arduino IDE and choose corresponding board type and port type for you project. Then load up the following sketch onto your Arduino.

 #include <Wire.h>
 #include <LiquidCrystal_I2C.h>
 #include <dht.h> dht DHT; 
LiquidCrystal_I2C lcd(0x27,16,2); 
// set the LCD address to 0x27 for a 16 chars and 2 line display
 #define DHT11_PIN 3 
void setup() { 
 lcd.begin(16,2); 
 lcd.init(); 
// initialize the lcd  
// Print a message to the LCD. lcd.backlight(); lcd.clear(); lcd.print("Humidity & temp");
 delay(3000);
 lcd.clear();
 lcd.print("Starting.....");
 delay(3000); }
 void loop() 
{ // READ DATA
 int chk = DHT.read11(DHT11_PIN);
 lcd.clear();
 delay(500); lcd.setCursor(0, 0); // print from 0 to 9:
 lcd.print("Temp: ");
 lcd.print(DHT.temperature, 1);
 lcd.print(" C"); // set the cursor to (16,1):
 lcd.setCursor(0,1);
 lcd.print("Humidity: ");
 lcd.print(DHT.humidity, 1);
 lcd.print(" %");
 delay(2000); }

Running Result

A few seconds after the upload finishes, you should now see the value of current humidity and temperature displayed on the LCD.

 

Byamber

Arduino lesson – MQ-7 Gas Sensor

Introduction

In this project, we will show what is MQ-5 Sensor and how to use it with the Arduino board.

Preparations

HARDWARE

  • Osoyoo UNO Board (Fully compatible with Arduino UNO rev.3) x 1
  • MQ-7 Sensor x 1
  • Jumpers
  • USB Cable x 1
  • PC x 1

SOFTWARE

  • Arduino IDE (version 1.6.4+)

About MQ-7 Gas Sensor

Description

MQ-7 Semiconductor Sensor for Combustible Gas

Sensitive material of MQ-7 gas sensor is SnO2, which with lower conductivity in clean air. It make detection by method of cycle high and low temperature, and detect CO when low temperature (heated by 1.5V). The sensors conductivity is more higher along with the gas concentration rising. When high temperature (heated by 5.0V), it cleans the other gases adsorbed under low temperature. Please use simple electrocircuit, Convert change of conductivity to correspond output signal of gas concentration.

MQ-7 gas sensor has high sensitity to Carbon Monoxide. The sensor could be used to detect different gases contains CO, it is with low cost and suitable for different application.

Character

  • High sensitivity to Combustible gas in wide range
  • High sensitivity to Natural gas
  • Fast response
  • Wide detection range
  • Stable performance, long life, low cost
  • Simple drive circuit

Technical Data

Introduction to MQ-7 Carbon Monoxide Sensor

According to its datasheet, the MQ-7 carbon monoxide sensor detects 20 to 2000 ppm of CO in air. Here is its sensitivity characteristic curve:

This is a graph of Rs/R0 vs. gas concentration in ppm. Rs is the resistance of the sensor in target gas while R0 is the resistance in clean air. We will use this graph later when we create our code.

This breakout board is more convenient as it converts resistance variations to voltage variations. Here is its schematic diagram:

There are two ways to read the output from the MQ-7. One is through the DOUT pin which gives a high when the concentration threshold is reached and low otherwise. The threshold can be varied by adjusting the trimmer on the breakout board which is Rp in the schematic.

Meanwhile, the AOUT pin gives varying voltage representing the CO concentration. We can convert the voltage reading to ppm if we look at the characteristic curve above. The relationship between concentration in ppm and RS/R0 is:

Example

Connection

Connect the MQ 7 Sensro and the Arduino Board as below digram:

Arduino Sketch for MQ-7

const int AOUTpin=0;//the AOUT pin of the hydrogen sensor goes into analog pin A0 of the arduino
const int DOUTpin=8;//the DOUT pin of the hydrogen sensor goes into digital pin D8 of the arduino
const int ledPin=13;//the anode of the LED connects to digital pin D13 of the arduino

int limit;
int value;

void setup() {
Serial.begin(115200);//sets the baud rate
pinMode(DOUTpin, INPUT);//sets the pin as an input to the arduino
pinMode(ledPin, OUTPUT);//sets the pin as an output of the arduino
}

void loop()
{
value= analogRead(AOUTpin);//reads the analaog value from the hydrogen sensor's AOUT pin
limit= digitalRead(DOUTpin);//reads the digital value from the hydrogen sensor's DOUT pin
Serial.print("Hydrogen value: ");
Serial.println(value);//prints the hydrogen value
Serial.print("Limit: ");
Serial.print(limit);//prints the limit reached as either LOW or HIGH 
delay(100);
if (limit == HIGH){
digitalWrite(ledPin, HIGH);//if limit has been reached, LED turns on as status indicator
}
else{
digitalWrite(ledPin, LOW);//if threshold not reached, LED remains off
}
}

The first block of code defines all the pin connections of the sensor and the LED. Since the AOUTpin connects to analog pin A0, it is initialized to 0. Since the DOUTpin connects to digital pin D8, it is initialized to 8. Since the LED connects to digital pin D13, it is initialized to 13. 2 variables, limit and value, are also declared. These will be used to store the value of the analog pin AOUT and digital pin DOUT.

The next block of code sets the baud rate and declares the DOUTpin as input and the ledPin as output. This is because the sensor is an input to the arduino for the arduino to read and process the sensor value. And the LED is an output will serves an indicator if the sensor has detected alcohol.

The next block of code reads the sensor pin AOUT and stores the value in the integer value. It also reads the sensor pin DOUT and stores the value in the integer limit. We then print the alcohol value, which will be a numeric value ranging from either 0 (no alcohol detected) to 1023 (maximum level of carbon monoxide that can be read). We will aslo print the limit which will either be HIGH or LOW. If the CO detected is under the threshold level, the value of limit returned will be low. If the CO detected is above the threshold, the value of limit returned will be HIGH.

If the value is HIGH, the LED will turn on. If the value is low, the LED will remain off.