DHT22 તાપમાન અને ભેજ 7-સેગમેન્ટ ડિસ્પ્લે પર Arduino RJT43 સાથે
આ પ્રોજેક્ટ દર્શાવે છે કે કેવી રીતે Arduino નો ઉપયોગ કરીને 7-સેગમેન્ટ ડિસ્પ્લે પર તાપમાન અને ભેજના રીડિંગ્સ દર્શાવવા માટે એક સરળ, છતાં અસરકારક, સિસ્ટમ બનાવવી. આ સેટઅપ વિવિધ એપ્લિકેશનો માટે ઉપયોગી છે જ્યાં પર્યાવરણીય પરિસ્થિતિઓનું નિરીક્ષણ કરવું મહત્વપૂર્ણ છે. આ પ્રોજેક્ટ DHT22 તાપમાન અને ભેજ સેન્સરને TM1637 7-સેગમેન્ટ ડિસ્પ્લે સાથે જોડે છે, જે સ્પષ્ટ અને સરળતાથી વાંચી શકાય તેવું આઉટપુટ પ્રદાન કરે છે.


પ્રોજેક્ટ વિચારો:
- શ્રેષ્ઠ આરામ માટે ઘરના વાતાવરણનું નિરીક્ષણ કરવું.
- ગ્રીનહાઉસ અથવા ટેરેરિયમમાં પરિસ્થિતિઓ ટ્રેક કરવી.
- મૂળભૂત હવામાન સ્ટેશન બનાવવું.
- ડેટા-લોગિંગ પ્રોજેક્ટમાં તાપમાન અને ભેજ દર્શાવવું.
હાર્ડવેર/ઘટકો
આ પ્રોજેક્ટ બનાવવા માટે, તમારે નીચેના ઘટકોની જરૂર પડશે:
- Arduino Uno (અથવા સુસંગત બોર્ડ)
- DHT22 તાપમાન અને ભેજ સેન્સર
- TM1637 7-સેગમેન્ટ ડિસ્પ્લે
- કનેક્ટિંગ વાયર
- બ્રેડબોર્ડ (વૈકલ્પિક, પરંતુ ભલામણ કરેલ)
વાયરિંગ માર્ગદર્શિકા



વાયરિંગ સરળ છે. વિઝ્યુઅલ માર્ગદર્શિકા માટે વિડિઓ (વિડિઓમાં 01:51 પર) જુઓ. મુખ્ય જોડાણો છે:
- TM1637 ડિસ્પ્લે: VCC થી 5V, GND થી GND, CLK થી Arduino પિન 2, DIO થી Arduino પિન 3 (વિડિઓમાં 02:00 પર).
- DHT22 સેન્સર: VCC થી 5V, GND થી GND, DATA થી Arduino પિન 9 (વિડિઓમાં 02:20 પર). નોંધ કરો કે વિડિઓ સેન્સરને 5V પ્રદાન કરવા માટે Arduino પિન 8 નો ઉપયોગ કરે છે (વિડિઓમાં 02:41 પર).
કોડ સમજૂતી
Arduino કોડ બે લાઇબ્રેરીઓનો ઉપયોગ કરે છે: 7-સેગમેન્ટ ડિસ્પ્લે માટે TM1637Display અને DHT22 સેન્સર માટે DHT. કોડના કન્ફિગરેબલ પરિમાણો મુખ્યત્વે શરૂઆતમાં સ્થિત છે:
// મોડ્યુલ કનેક્શન પિન (ડિજિટલ પિન)
#define CLK 2
#define DIO 3
#define DHTPIN 9 // DHT22 ડેટા પિન
#define DHTTYPE DHT22 // DHT સેન્સર પ્રકાર
આ રેખાઓ ડિસ્પ્લે અને DHT22 સેન્સર સાથે જોડાયેલા Arduino પિનને વ્યાખ્યાયિત કરે છે. જો તમે અલગ પિનનો ઉપયોગ કરો તો તમારે આને સમાયોજિત કરવાની જરૂર પડી શકે છે. getTemp() ફંક્શન (વિડિઓમાં 07:03 પર) નિર્ણાયક છે. તે તમને સ્ટ્રિંગ આર્ગ્યુમેન્ટ પસાર કરીને DHT22 સેન્સરમાંથી વિવિધ મૂલ્યો મેળવવાની મંજૂરી આપે છે:
float getTemp(String req) {
// ... (સેન્સર રીડિંગ કોડ) ...
if(req =="c"){ return t; } // સેલ્સિયસ
else if(req =="f"){ return f; } // ફેરનહીટ
// ... (કેલ્વિન, ભેજ, હીટ ઇન્ડેક્સ માટે અન્ય વિકલ્પો) ...
}
આ ફંક્શન સેન્સરમાંથી વિવિધ ડેટા (સેલ્સિયસ, ફેરનહીટ, ભેજ, હીટ ઇન્ડેક્સ) વાંચવાનું સરળ બનાવે છે. મુખ્ય લૂપ આ ફંક્શનનો ઉપયોગ ડેટા લાવવા અને તેને 7-સેગમેન્ટ ડિસ્પ્લે પર દર્શાવવા માટે કરે છે, ડિસ્પ્લે હેતુ માટે ફ્લોટિંગ-પોઇન્ટ મૂલ્યોને પૂર્ણાંકોમાં ગોળાકાર કરે છે (વિડિઓમાં 07:14 પર).
લાઇવ પ્રોજેક્ટ/પ્રદર્શન
વિડિઓ (વિડિઓમાં 00:32 પર) પ્રોજેક્ટનું લાઇવ પ્રદર્શન બતાવે છે. 7-સેગમેન્ટ ડિસ્પ્લે સ્પષ્ટપણે ફેરનહીટમાં તાપમાન દર્શાવે છે. વિડિઓ એ પણ દર્શાવે છે કે કોડને સેલ્સિયસ, કેલ્વિન, ભેજ અને હીટ ઇન્ડેક્સ મૂલ્યો દર્શાવવા માટે કેવી રીતે સંશોધિત કરી શકાય છે (વિડિઓમાં 08:21 પર).
પ્રકરણો
- [00:06] પરિચય અને પ્રોજેક્ટ ઝાંખી
- [00:53] શરૂઆત અને ઘટકોની ઝાંખી
- [01:51] TM1637 ડિસ્પ્લે વાયરિંગ
- [02:20] DHT22 સેન્સર વાયરિંગ
- [03:14] કોડ સમજૂતી: TM1637 સેટઅપ
- [04:00] કોડ સમજૂતી: DHT22 સેટઅપ
- [05:54] કોડ સમજૂતી: મુખ્ય લૂપ અને ડિસ્પ્લે ફંક્શન
- [07:03] કોડ સમજૂતી: getTemp() ફંક્શન
- [08:21] પ્રદર્શન અને વિવિધ આઉટપુટ વિકલ્પો
/*
* 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
}
}
Resources & references
No resources yet.
Files📁
Arduino Libraries (zip)
-
DHT22 PCB module red
DHT22-module-red.fzpz0.01 MB
Fritzing File
-
DHT22 Humidity and Temperature Sensor
DHT22 Humidity and Temperature Sensor.fzpz0.01 MB -
DHT22 PCB module red
DHT22-module-red.fzpz0.01 MB -
DHT22 module white
DHT22-module-white.fzpz0.01 MB -
TM1637 Seven Segment module
TM1637.fzpz0.01 MB -
DHT11 Humitidy and Temperature Sensor (3 pins)
DHT11 Humitidy and Temperature Sensor (3 pins).fzpz0.20 MB
User’s Manual
-
DHT22 Temperature and Humidity sensor user's manual
robojax-DHT22_manual.pdf0.36 MB