Raadi Koodka

Heerkulka DHT22 iyo Qoyaanka ee Bandhigga 7-Segment ee Arduino RJT43

Heerkulka DHT22 iyo Qoyaanka ee Bandhigga 7-Segment ee Arduino RJT43

Mashruucani waxay muujinayaan sida loo dhiso nidaam fudud, laakiin wax ku ool ah, oo lagu soo bandhigo akhrinta heerkulka iyo qoyaanka ee shaashadda 7-segment iyadoo la adeegsanayo Arduino. Qalabkani waa mid faa'iido u leh codsiyo kala duwan oo lagula socdo xaaladaha deegaanka ay muhiim tahay. Mashruucu wuxuu isku darayaa dareemaha heerkulka iyo qoyaanka ee DHT22 iyo shaashadda 7-segment ee TM1637, isagoo bixinaya natiijo cad oo si fudud loo akhriyi karo.

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

Fikradaha Mashruuca:

  • La socodka deegaanka guriga si loo helo raaxo ku habboon.
  • La socodka xaaladaha guriga lagu beerto (greenhouse) ama terrarium.
  • Dhisidda xarun cimilo oo aasaasi ah.
  • Soo bandhigida heerkulka iyo qoyaanka mashruuc diiwaangelin xog ah.

Qalabka/Qaybaha

Si aad u dhisto mashruucan, waxaad u baahan doontaa qaybahan soo socda:

  • Arduino Uno (ama loox la jaanqaadi karo)
  • Dareemaha Heerkulka iyo Qoyaanka ee DHT22
  • Shaashadda 7-Segment ee TM1637
  • Fiilooyin isku xira
  • Breadboard (ikhtiyaar, laakiin lagu taliyay)

Hagaha Xidhiidhinta

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

Xidhiidhintu waa mid toos ah. Fiiri fiidiyowga (fiidiyowga 01:51) si aad u hesho hagaha muuqaalka. Xidhiidhada muhiimka ah waa:

  • Shaashadda TM1637: VCC ilaa 5V, GND ilaa GND, CLK ilaa pin-ka Arduino 2, DIO ilaa pin-ka Arduino 3 (fiidiyowga 02:00).
  • Dareemaha DHT22: VCC ilaa 5V, GND ilaa GND, DATA ilaa pin-ka Arduino 9 (fiidiyowga 02:20). Ogsoonow in fiidiyowgu uu isticmaalo pin-ka Arduino 8 si uu u siiyo 5V dareemaha (fiidiyowga 02:41).

Sharaxaadda Koodhka

Koodhka Arduino wuxuu adeegsadaa laba maktabadood: TM1637Display oo loogu talagalay shaashadda 7-segment iyo DHT oo loogu talagalay dareemaha DHT22. Xuduudaha koodhka ee la hagaajin karo waxay ugu horayn ku yaalliin bilowga:


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

Sadarradani waxay qeexayaan pin-yada Arduino ee ku xiran shaashadda iyo dareemaha DHT22. Waxaa laga yaabaa inaad u baahato inaad hagaajiso kuwan haddii aad isticmaasho pin-yo kala duwan. Shaqada getTemp() (fiidiyowga 07:03) waa mid muhiim ah. Waxay kuu ogolaaneysaa inaad soo ceshato qiimayaal kala duwan oo ka yimaada dareemaha DHT22 adigoo u gudbinaya dood xarfo ah:


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) ...
}

Shaqadani waxay fududeyneysaa akhrinta xogta kala duwan ee dareemaha (Celsius, Fahrenheit, qoyaanka, heerkulka kulaylka). Loop-ka ugu weyn wuxuu isticmaalaa shaqadan si uu u soo qaado xogta oo uu u soo bandhigo shaashadda 7-segment, isagoo ku wareejinaya qiimayaasha jajabka tobanle (floating-point) ilaa tirooyin dhammaystiran si loo soo bandhigo (fiidiyowga 07:14).

Mashruuca Tooska ah/Muujinta

Fiidiyowgu (fiidiyowga 00:32) wuxuu muujinayaa bandhig toos ah oo mashruuca ah. Shaashadda 7-segment waxay si cad u muujinaysaa heerkulka Fahrenheit. Fiidiyowgu wuxuu sidoo kale muujinayaa sida koodhka loo beddeli karo si uu u soo bandhigo Celsius, Kelvin, qoyaanka, iyo qiimayaasha heerkulka kulaylka (fiidiyowga 08:21).

Cutubyada

  • [00:06] Hordhac iyo Dulmarka Mashruuca
  • [00:53] Bilowga iyo Dulmarka Qaybaha
  • [01:51] Xidhiidhinta Shaashadda TM1637
  • [02:20] Xidhiidhinta Dareemaha DHT22
  • [03:14] Sharaxaadda Koodhka: TM1637 Setup
  • [04:00] Sharaxaadda Koodhka: DHT22 Setup
  • [05:54] Sharaxaadda Koodhka: Loop-ka ugu Weyn iyo Shaqada Soo Bandhigista
  • [07:03] Sharaxaadda Koodhka: Shaqada getTemp()
  • [08:21] Muujinta iyo Ikhtiyaarrada Natiijooyinka Kala Duwan

Sawirro

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
Luqadda: 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
  }
 
}

Kheyraadka & Tixraacyada

Wali wax kaydsan ah oo weli ma jiro.

Faylasha📁

Arduino Libraries (zip)

Faylka Fritzing

Buugga Isticmaalaha