dht11 arduino tuto

Temperature and Humidity Displayed on 4 Digit 7 segment

In this Arduino Tutorial we will learn how the DHT11 Sensor works and how to use it with the Arduino Nano v3 Board. You can watch the following video or read the written tutorial below.
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. The only real downside of this sensor is you can only get new data from it once every 2 seconds, so when using our library, sensor readings can be up to 2 seconds old.
  • VCC - 5V
  • GND - GND
  • Data  - A0

Schema




download

Geekcreit® ATmega328P Nano V3 Controller Board Compatible Arduino Improved Version


16 In 1 Sensor Module Kit For Arduino Raspberry Pi 2 Pi2 Pi3

Code

Library

Code

#include "DHT.h"
#define DHT11_PIN A0     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11
DHT dht(DHT11_PIN, DHTTYPE);
int a = 2;
int b = 3;
int c = 4;
int d = 5;
int e = 7;
int f = 8;
int g = 12;
int GND1 = 6;
int GND2 = 9;
int GND3 = 10;
int GND4 = 11;
int dig1;
int dig2;
int dig3;
int dig4;
int Temp;
int Humi;
void setup()
{

  dht.begin();
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);
  pinMode(GND1, OUTPUT);
  pinMode(GND2, OUTPUT);
  pinMode(GND3, OUTPUT);
  pinMode(GND4, OUTPUT);
  pinMode(A0, INPUT); 
}

void loop()
{
  
  Temp = dht.readTemperature();
  Humi = dht.readHumidity();
    dig1 = Temp / 10;
    dig2 = Temp - (dig1 * 10);
    dig3 = Humi / 10;
    dig4 = Humi - (dig3 * 10);

    for (int i = 1; i <= 2000; i++)
    {
        digitalWrite( GND1, LOW);    //digit 1
        DisplayNumber(dig1);
        delay(4);
        digitalWrite( GND1, HIGH);

        digitalWrite( GND2, LOW);    //digit 2
        DisplayNumber(dig2);
        delay(4);
        digitalWrite( GND2, HIGH);

        digitalWrite( GND3, LOW);    //digit 3
        DisplayNumber(dig3);
        delay(4);
        digitalWrite( GND3, HIGH);

        digitalWrite( GND4, LOW);    //digit 4
        DisplayNumber(dig4);
        delay(4);
        digitalWrite( GND4, HIGH);
}
}
void DisplayNumber(int x) {
  switch (x) {
    case 0: zero(); break;
    case 1: one(); break;
    case 2: two(); break;
    case 3: three(); break;
    case 4: four(); break;
    case 5: five(); break;
    case 6: six(); break;
    case 7: seven(); break;
    case 8: eight(); break;
    case 9: nine(); break;
  }
}

void zero()
{
  digitalWrite( a, HIGH);
  digitalWrite( b, HIGH);
  digitalWrite( c, HIGH);
  digitalWrite( d, HIGH);
  digitalWrite( e, HIGH);
  digitalWrite( f, HIGH);
  digitalWrite( g, LOW);
}

void one()
{
  digitalWrite( a, LOW);
  digitalWrite( b, HIGH);
  digitalWrite( c, HIGH);
  digitalWrite( d, LOW);
  digitalWrite( e, LOW);
  digitalWrite( f, LOW);
  digitalWrite( g, LOW);
}

void two()
{
  digitalWrite( a, HIGH);
  digitalWrite( b, HIGH);
  digitalWrite( c, LOW);
  digitalWrite( d, HIGH);
  digitalWrite( e, HIGH);
  digitalWrite( f, LOW);
  digitalWrite( g, HIGH);
}

void three()
{
  digitalWrite( a, HIGH);
  digitalWrite( b, HIGH);
  digitalWrite( c, HIGH);
  digitalWrite( d, HIGH);
  digitalWrite( e, LOW);
  digitalWrite( f, LOW);
  digitalWrite( g, HIGH);
}

void four()
{
  digitalWrite( a, LOW);
  digitalWrite( b, HIGH);
  digitalWrite( c, HIGH);
  digitalWrite( d, LOW);
  digitalWrite( e, LOW);
  digitalWrite( f, HIGH);
  digitalWrite( g, HIGH);
}

void five()
{
  digitalWrite( a, HIGH);
  digitalWrite( b, LOW);
  digitalWrite( c, HIGH);
  digitalWrite( d, HIGH);
  digitalWrite( e, LOW);
  digitalWrite( f, HIGH);
  digitalWrite( g, HIGH);
}

void six()
{
  digitalWrite( a, HIGH);
  digitalWrite( b, LOW);
  digitalWrite( c, HIGH);
  digitalWrite( d, HIGH);
  digitalWrite( e, HIGH);
  digitalWrite( f, HIGH);
  digitalWrite( g, HIGH);
}

void seven()
{
  digitalWrite( a, HIGH);
  digitalWrite( b, HIGH);
  digitalWrite( c, HIGH);
  digitalWrite( d, LOW);
  digitalWrite( e, LOW);
  digitalWrite( f, LOW);
  digitalWrite( g, LOW);
}

void eight()
{
  digitalWrite( a, HIGH);
  digitalWrite( b, HIGH);
  digitalWrite( c, HIGH);
  digitalWrite( d, HIGH);
  digitalWrite( e, HIGH);
  digitalWrite( f, HIGH);
  digitalWrite( g, HIGH);
}

void nine()
{
  digitalWrite( a, HIGH);
  digitalWrite( b, HIGH);
  digitalWrite( c, HIGH);
  digitalWrite( d, HIGH);
  digitalWrite( e, LOW);
  digitalWrite( f, HIGH);
  digitalWrite( g, HIGH);
}

5 comments:

  1. Hello, thank you very much about your video. i just wanna ask what is the material you used for covering the 7 segment display?

    Thank you

    ReplyDelete
  2. Hello, thank you very much about your video. i just wanna ask what is the material you used for covering the 7 segment display?

    Thank you

    ReplyDelete
  3. i wanna to upload the code but is tell me error compiling for board arduinoMega pls tell me what to do thanks

    ReplyDelete
  4. hi sir first thank you for this project but iwanna ask i have'nt the library DHT please can you send to me this thanks sir

    ReplyDelete