Wa Koodu

DHT22 Iwọn otutu ati Ọrinrin lori Ifihan 7-Segment pẹlu Arduino RJT43

DHT22 Iwọn otutu ati Ọrinrin lori Ifihan 7-Segment pẹlu Arduino RJT43

Iṣẹ́ yìí ṣàfihàn bí a ṣe lè kọ́ ètò tí ó rọrùn, ṣùgbọ́n tí ó gbéṣẹ́, fún ṣíṣàfihàn àwọn ìwọ̀n ìgbóná àti ọ̀rinrin lórí ẹ̀rọ̀ ìṣàfihàn 7-segment nípa lílo Arduino. Ìtòlẹ́sẹ̀ yìí wúlò fún ọ̀pọ̀lọpọ̀ àwọn ohun èlò níbi tí ìṣàkíyèsí àyíká ipò ti ṣe pàtàkì. Iṣẹ́ yìí darapọ̀ mọ́ ẹ̀rọ̀ ìwọ̀n ìgbóná àti ọ̀rinrin DHT22 pẹ̀lú ẹ̀rọ̀ ìṣàfihàn 7-segment TM1637, tí ó ń pèsè àbájáde tí ó ṣe kedere àti tí ó rọrùn láti kà.

DHT22 sensor with PCB-1
Arduino wriing DHT11 PCB module  module with TM1637

Àwọn Èrò Iṣẹ́:

  • Ṣíṣàkíyèsí àyíká ilé fún ìtùnú tí ó dára jùlọ.
  • Ṣíṣàkíyèsí ipò nínú ilé ẹ̀fọ̀ tàbí terrarium.
  • Kíkọ́ ibùdó ojú ọjọ́ tí ó rọrùn.
  • Ṣíṣàfihàn ìgbóná àti ọ̀rinrin nínú iṣẹ́ ìkọ̀wé data.

Ohun Èlò / Àwọn Ẹ̀yà

Láti kọ́ iṣẹ́ yìí, ìwọ yóò nílò àwọn ẹ̀yà wọ̀nyí:

  • Arduino Uno (tàbí bọ́ọ̀dù tí ó báramu)
  • Ẹ̀rọ̀ ìwọ̀n ìgbóná àti ọ̀rinrin DHT22
  • Ẹ̀rọ̀ ìṣàfihàn 7-segment TM1637
  • Àwọn okun ìsopọ̀
  • Breadboard (kì í ṣe dandan, ṣùgbọ́n a ṣe ìmọ̀ràn)

Ìtọ́sọ́nà Ìsopọ̀

Arduino wriing DHT11 PCB module  module with TM1637
Arduino wriing DHT11 PCB module module with TM1637
Arduino wriing DHT11 bare module  module with TM1637
Arduino wriing DHT11 bare module module with TM1637
Arduino wriing DHT11 bare module  module with TM1637
Arduino wriing DHT11 bare module module with TM1637

Ìsopọ̀ náà rọrùn. Wo fídíò náà (nínú fídíò ní 01:51) fún ìtọ́sọ́nà ojú. Àwọn ìsopọ̀ pàtàkì ni:

  • Ẹ̀rọ̀ ìṣàfihàn TM1637: VCC sí 5V, GND sí GND, CLK sí pin 2 Arduino, DIO sí pin 3 Arduino (nínú fídíò ní 02:00).
  • Ẹ̀rọ̀ ìwọ̀n DHT22: VCC sí 5V, GND sí GND, DATA sí pin 9 Arduino (nínú fídíò ní 02:20). Kíyèsi pé fídíò náà lo pin 8 Arduino láti pèsè 5V fún ẹ̀rọ̀ ìwọ̀n náà (nínú fídíò ní 02:41).

Àlàyé Kóòdù

Kóòdù Arduino lo àwọn ilé-ìkàwé méjì: TM1637Display fún ẹ̀rọ̀ ìṣàfihàn 7-segment àti DHT fún ẹ̀rọ̀ ìwọ̀n DHT22. Àwọn paramita tí a lè ṣàtúnṣe nínú kóòdù náà wà ní ìbẹ̀rẹ̀ pàtàkì:


// Module connection pins (Digital Pins)
#define CLK 2
#define DIO 3
#define DHTPIN 9     // DHT22 data pin
#define DHTTYPE DHT22   // DHT sensor type

Àwọn ìlà wọ̀nyí ṣàlàyé àwọn pin Arduino tí a sopọ̀ mọ́ ẹ̀rọ̀ ìṣàfihàn àti ẹ̀rọ̀ ìwọ̀n DHT22. Ìwọ lè ní láti ṣàtúnṣe wọ̀nyí bí o bá lo àwọn pin ọ̀tọ̀ọ̀tọ̀. Iṣẹ́ getTemp() (nínú fídíò ní 07:03) ṣe pàtàkì. Ó jẹ́ kí o gba àwọn iye ọ̀tọ̀ọ̀tọ̀ láti ọ̀dọ̀ ẹ̀rọ̀ ìwọ̀n DHT22 nípa gbígbé àríyànjiyàn okun kan:


float getTemp(String req) {
  // ... (Sensor reading code) ...
  if(req =="c"){ return t; } // Celsius
  else if(req =="f"){ return f; } // Fahrenheit
  // ... (Other options for Kelvin, humidity, heat index) ...
}

Iṣẹ́ yìí rọrùn láti kà àwọn data ọ̀tọ̀ọ̀tọ̀ láti ọ̀dọ̀ ẹ̀rọ̀ ìwọ̀n náà (Celsius, Fahrenheit, ọ̀rinrin, heat index). Lúùpù àkọ́kọ́ lo iṣẹ́ yìí láti gba data náà àti láti fi hàn lórí ẹ̀rọ̀ ìṣàfihàn 7-segment, ní yíyí àwọn iye floating-point padà sí odidi fún ìṣàfihàn (nínú fídíò ní 07:14).

Iṣẹ́ Ààyè / Ìfihàn

Fídíò náà (nínú fídíò ní 00:32) ṣàfihàn ìfihàn ààyè ti iṣẹ́ náà. Ẹ̀rọ̀ ìṣàfihàn 7-segment ṣàfihàn ìgbóná ní Fahrenheit kedere. Fídíò náà tún ṣàfihàn bí a ṣe lè yí kóòdù padà láti ṣàfihàn Celsius, Kelvin, ọ̀rinrin, àti àwọn iye heat index (nínú fídíò ní 08:21).

Àwọn Orí Ìpín

  • [00:06] Ìfáàrà àti Àkópọ̀ Iṣẹ́
  • [00:53] Bíbẹ̀rẹ̀ àti Àkópọ̀ Àwọn Ẹ̀yà
  • [01:51] Ìsopọ̀ Ẹ̀rọ̀ Ìṣàfihàn TM1637
  • [02:20] Ìsopọ̀ Ẹ̀rọ̀ Ìwọ̀n DHT22
  • [03:14] Àlàyé Kóòdù: Ìtòlẹ́sẹ̀ TM1637
  • [04:00] Àlàyé Kóòdù: Ìtòlẹ́sẹ̀ DHT22
  • [05:54] Àlàyé Kóòdù: Lúùpù Àkọ́kọ́ àti Iṣẹ́ Ìṣàfihàn
  • [07:03] Àlàyé Kóòdù: Iṣẹ́ getTemp()
  • [08:21] Ìfihàn àti Àwọn Àṣàyàn Àbájáde Ọ̀tọ̀ọ̀tọ̀

Aworan

DHT22 sensor with PCB-1
DHT22 sensor with PCB-1
DHT22 with PCB red
DHT22 with PCB red
DHT22 sensor no PCB
DHT22 sensor no PCB
Arduino wriing DHT11 PCB module  module with TM1637
Arduino wriing DHT11 PCB module module with TM1637
Arduino wriing DHT11 PCB module  module with TM1637
Arduino wriing DHT11 PCB module module with TM1637
Arduino wriing DHT11 bare module  module with TM1637
Arduino wriing DHT11 bare module module with TM1637
Arduino wriing DHT11 bare module  module with TM1637
Arduino wriing DHT11 bare module module with TM1637
56-Arduino code and video for a DHT12 Temperature and Humidity Sensor with TM1637 Display
Ede: C++
/*
 * Original code from TM1637 https://github.com/avishorp/TM1637
 * Original code and library for DHT22 https://github.com/adafruit/DHT-sensor-library
 * Modified for Robojax video on January 7, 2018
 * by Ahmad Shamshiri, in Ajax, Ontario, Canada
 * Watch the video for this code https://youtu.be/z_FvRm6Te78
 * Other Arduino library and videos https://robojax.com
 * Get this code and other Arduino codes from Robojax.com
Learn Arduino step by step in a structured course with all material, wiring diagrams, and libraries
all in one place. 

If you found this tutorial helpful, please support me so I can continue creating 
content like this. 

or make a donation using PayPal http://robojax.com/L/?id=64

 *  * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
 * This code has been downloaded from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>. 
 */
 
// ****** Start of TM1637 Display code 
#include <Arduino.h>
#include <TM1637Display.h>
// Module connection pins (Digital Pins)
#define CLK 2
#define DIO 3
// The amount of time (in milliseconds) between tests
#define TEST_DELAY   1000
TM1637Display display(CLK, DIO);
// ****** end of TM1637 Display code 

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain


// ****** Start of DHT code 
#include "DHT.h"
#define DHTPIN 9     // what digital pin we're connected to
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
// ********** end of DHT22 code

void setup()
{
  Serial.begin(9600);
  Serial.println("DHT22 Robojax Test with Display");
  pinMode(8,OUTPUT);
  digitalWrite(8,HIGH);// gives 5v for DHT22
  dht.begin();  
}

void loop()
{
  delay(TEST_DELAY);// wait
  // **** TM1637 code start
  display.setBrightness(0x0f);// set brightness
  uint8_t data[] = { 0x0, 0x0, 0x0, 0x0 };// clear display values
  display.setSegments(data);//clear display
  // **** TM1637 code end
  

  // Robojax.com test video
  Serial.println(getTemp("h"));

  int temp = round(getTemp("h"));
  
  display.showNumberDec(temp, false, 3,1);



}// loop end


/*
 * getTemp(String req)
 * returns the temperature related parameters
 * req is string request
 * This code can display temperature in:
 * getTemp("c") is used to get Celsius
 * getTemp("f") is used to get Fahrenheit
 * getTemp("k") is used for Kelvin
 * getTemp("hif") is used to get Fahrenheit
 * getTemp("hic") is used to get Celsius
 * getTemp("h") is used to get humidity 
 * written by Ahmad Shamshiri for Robojax.com on January 7, 2018
 * in Ajax, Ontario, Canada
 */
float getTemp(String req)
{

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (it's a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return 0.0; //return 0.0 instead of nothing.
  }
  // Compute heat index in Kelvin 
  float k = t + 273.15;
  if(req =="c"){
    return t;//return Celsius
  }else if(req =="f"){
    return f;// return Fahrenheit
  }else if(req =="h"){
    return h;// return humidity
  }else if(req =="hif"){
    return hif;// return heat index in Fahrenheit
  }else if(req =="hic"){
    return hic;// return heat index in Celsius
  }else if(req =="k"){
    return k;// return temperature in Kelvin
  }else{
    return 0.000;// if no request found, return 0.000
  }
 
}

Orisun & itọkasi

Ko si awọn orisun sibẹsibẹ.

Fáìlìs📁

Awọn ile-ikawe Arduino (zip)

Fayile Fritzing

Iwe Itọsọna Olumulo