Basic setup for Arduino with Temp. & Humidity sensor
Most essential, yet very simple project using Temperature & Humidity sensor. This could be part of your Home Automation!
Components and supplies
1
USB-A to B Cable
1
Arduino UNO
1
Jumper wires (generic)
1
Breadboard (generic)
1
DHT11 Temperature & Humidity Sensor (3 pins)
Apps and platforms
1
Arduino IDE
Project description
Code
Optimised Code for Arduino with DHT11 sensor
c_cpp
1/* 2 * Credits to all sources on Google, acting as reference to this 3 code below. This code is not 4 * TechValer's own creation. TechValer has referred 5 to different projects and websites to 6 * find an easy code for beginners to 7 get started with Temperature & Humidity sensor(DHT11/DHT22) 8 * and Arduino. 9 TechValer does not claim this code to be its own. TechValer is greatly thankful 10 11 * for original creaters of this code and also all others who acted as reference. 12 13 */ 14 15/* 16 * About TechValer 17 * 18 * What comes to mind when 19 you think of tech...hmm, we're sure youre thinking of iPhone, 20 * Alexa, Boston 21 Dynamics robotic dog etc., at least thats what we would have thought of. 22 * 23 Our point here is, when you look inside this tech...you'll find weird boards with 24 25 * components attached to it. This stuff is electronics and we at Techvaler 26 deeply appreciate 27 * this piece of tech. As the name suggests, we are Tech 28 Enthusiasts who know the Worth and 29 * Potential of these amazing tech stuff! 30 So, check out our website techvaler.com and Youtube channel: "Techcafe" to find 31 out 32 * more. 33 */ 34 35/* 36 * Note: Any model of Arduino can be used 37 for this project. Just keep in mind the digital pins. 38 * The readings available 39 in the serial monitor are almost accurate. 40 * Refer to the documentation for 41 better understanding of this particular code and project. 42 */ 43 44/* 45 * 46 Thanks to Drona Automations Pvt.Ltd for Sponsoring this project! 47 */ 48 49#include 50 "DHT.h" //It is necessary for us to include this library when we use DHT11/DHT22 51 sensor 52#define DHTPIN 3 // Defining the data output pin to Arduino 53#define 54 DHTTYPE DHT11 // Specify the sensor type(DHT11 or DHT22) 55 56DHT dht(DHTPIN, 57 DHTTYPE); //Declaration for varibles below... 58 59void setup() { 60 Serial.begin(9600); 61 //To engage serial monitor 62 dht.begin(); //To initialise DHT sensor 63} 64 65void 66 loop() { 67 delay(1000); 68 //Here h= Humidity; tC= Temperature in degree C; 69 tF= Temperature in degree F 70 float h= dht.readHumidity(); 71 float tC= dht.readTemperature(); 72 73 float tF= dht.readTemperature(true); 74 75 if (isnan(h) || isnan(tC) || isnan(tF)){ 76 77 Serial.println("Failed to read the DHT sensor. Check connections"); 78 } 79 80 else{ 81 Serial.print("Humidity: "); 82 Serial.print(h); 83 Serial.print("%"); 84 85 Serial.print(" || "); 86 Serial.print("Temperature: "); 87 Serial.print(tC); 88 89 Serial.print("C "); 90 Serial.print(tF); 91 Serial.println("F"); 92 93 } 94} 95
Optimised Code for Arduino with DHT11 sensor
c_cpp
1/* 2 * Credits to all sources on Google, acting as reference to this code below. This code is not 3 * TechValer's own creation. TechValer has referred to different projects and websites to 4 * find an easy code for beginners to get started with Temperature & Humidity sensor(DHT11/DHT22) 5 * and Arduino. TechValer does not claim this code to be its own. TechValer is greatly thankful 6 * for original creaters of this code and also all others who acted as reference. 7 */ 8 9/* 10 * About TechValer 11 * 12 * What comes to mind when you think of tech...hmm, we're sure youre thinking of iPhone, 13 * Alexa, Boston Dynamics robotic dog etc., at least thats what we would have thought of. 14 * Our point here is, when you look inside this tech...you'll find weird boards with 15 * components attached to it. This stuff is electronics and we at Techvaler deeply appreciate 16 * this piece of tech. As the name suggests, we are Tech Enthusiasts who know the Worth and 17 * Potential of these amazing tech stuff! So, check out our website techvaler.com and Youtube channel: "Techcafe" to find out 18 * more. 19 */ 20 21/* 22 * Note: Any model of Arduino can be used for this project. Just keep in mind the digital pins. 23 * The readings available in the serial monitor are almost accurate. 24 * Refer to the documentation for better understanding of this particular code and project. 25 */ 26 27/* 28 * Thanks to Drona Automations Pvt.Ltd for Sponsoring this project! 29 */ 30 31#include "DHT.h" //It is necessary for us to include this library when we use DHT11/DHT22 sensor 32#define DHTPIN 3 // Defining the data output pin to Arduino 33#define DHTTYPE DHT11 // Specify the sensor type(DHT11 or DHT22) 34 35DHT dht(DHTPIN, DHTTYPE); //Declaration for varibles below... 36 37void setup() { 38 Serial.begin(9600); //To engage serial monitor 39 dht.begin(); //To initialise DHT sensor 40} 41 42void loop() { 43 delay(1000); 44 //Here h= Humidity; tC= Temperature in degree C; tF= Temperature in degree F 45 float h= dht.readHumidity(); 46 float tC= dht.readTemperature(); 47 float tF= dht.readTemperature(true); 48 49 if (isnan(h) || isnan(tC) || isnan(tF)){ 50 Serial.println("Failed to read the DHT sensor. Check connections"); 51 } 52 else{ 53 Serial.print("Humidity: "); 54 Serial.print(h); 55 Serial.print("%"); 56 Serial.print(" || "); 57 Serial.print("Temperature: "); 58 Serial.print(tC); 59 Serial.print("C "); 60 Serial.print(tF); 61 Serial.println("F"); 62 } 63} 64
Downloadable files
DHT11 Sensor with Arduino Uno
DHT11 Sensor with Arduino Uno

Comments
Only logged in users can leave comments