Components and supplies
LCD1602 I2C
dupont cable some
Arduino UNO
DHT11
UNO R3
Project description
Code
CODE
arduino
1// Example testing sketch for various DHT humidity/temperature sensors 2// Written by ladyada, public domain 3 4// REQUIRES the following Arduino libraries: 5// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library 6// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor 7 8#include "DHT.h" 9 10#define DHTPIN 2 // Digital pin connected to the DHT sensor 11// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 -- 12// Pin 15 can work but DHT must be disconnected during program upload. 13 14// Uncomment whatever type you're using! 15//#define DHTTYPE DHT11 // DHT 11 16#define DHTTYPE DHT11 // DHT 22 (AM2302), AM2321 17//#define DHTTYPE DHT21 // DHT 21 (AM2301) 18#include <LiquidCrystal_I2C.h> 19 20LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display 21 22// Connect pin 1 (on the left) of the sensor to +5V 23// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1 24// to 3.3V instead of 5V! 25// Connect pin 2 of the sensor to whatever your DHTPIN is 26// Connect pin 4 (on the right) of the sensor to GROUND 27// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor 28 29// Initialize DHT sensor. 30// Note that older versions of this library took an optional third parameter to 31// tweak the timings for faster processors. This parameter is no longer needed 32// as the current DHT reading algorithm adjusts itself to work on faster procs. 33DHT dht(DHTPIN, DHTTYPE); 34 35void setup() { 36 lcd.init(); // initialize the lcd 37 lcd.backlight(); 38 lcd.print("Small Hammer"); 39 Serial.begin(9600); 40 Serial.println(F("DHTxx test!")); 41 42 dht.begin(); 43} 44 45void loop() { 46 // Wait a few seconds between measurements. 47 delay(2000); 48 49 // Reading temperature or humidity takes about 250 milliseconds! 50 // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) 51 float h = dht.readHumidity(); 52 // Read temperature as Celsius (the default) 53 float t = dht.readTemperature(); 54 // Read temperature as Fahrenheit (isFahrenheit = true) 55 float f = dht.readTemperature(true); 56 57 // Check if any reads failed and exit early (to try again). 58 if (isnan(h) || isnan(t) || isnan(f)) { 59 Serial.println(F("Failed to read from DHT sensor!")); 60 return; 61 } 62 63 // Compute heat index in Fahrenheit (the default) 64 float hif = dht.computeHeatIndex(f, h); 65 // Compute heat index in Celsius (isFahreheit = false) 66 float hic = dht.computeHeatIndex(t, h, false); 67 68 Serial.print(F("Humidity: ")); 69 Serial.print(h); 70 Serial.print(F("% Temperature: ")); 71 Serial.print(t); 72 Serial.print(F("C ")); 73 Serial.print(f); 74 Serial.print(F("F Heat index: ")); 75 Serial.print(hic); 76 Serial.print(F("C ")); 77 Serial.print(hif); 78 Serial.println(F("F")); 79 lcd.setCursor(0, 0); 80 lcd.print("Temp:"); 81 lcd.print(t); 82 83 lcd.write(0xDF); 84 lcd.print("C"); 85 86 lcd.setCursor(0, 1); 87 lcd.print("Humidity:"); 88 lcd.print(f); 89 lcd.print("%"); 90} 91
CODE
arduino
1// Example testing sketch for various DHT humidity/temperature sensors 2// 3 Written by ladyada, public domain 4 5// REQUIRES the following Arduino libraries: 6// 7 - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library 8// - Adafruit 9 Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor 10 11#include 12 "DHT.h" 13 14#define DHTPIN 2 // Digital pin connected to the DHT sensor 15// 16 Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 -- 17// Pin 15 can 18 work but DHT must be disconnected during program upload. 19 20// Uncomment whatever 21 type you're using! 22//#define DHTTYPE DHT11 // DHT 11 23#define DHTTYPE DHT11 24 // DHT 22 (AM2302), AM2321 25//#define DHTTYPE DHT21 // DHT 21 (AM2301) 26#include 27 <LiquidCrystal_I2C.h> 28 29LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address 30 to 0x27 for a 16 chars and 2 line display 31 32// Connect pin 1 (on the left) 33 of the sensor to +5V 34// NOTE: If using a board with 3.3V logic like an Arduino 35 Due connect pin 1 36// to 3.3V instead of 5V! 37// Connect pin 2 of the sensor 38 to whatever your DHTPIN is 39// Connect pin 4 (on the right) of the sensor to GROUND 40// 41 Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor 42 43// 44 Initialize DHT sensor. 45// Note that older versions of this library took an optional 46 third parameter to 47// tweak the timings for faster processors. This parameter 48 is no longer needed 49// as the current DHT reading algorithm adjusts itself to 50 work on faster procs. 51DHT dht(DHTPIN, DHTTYPE); 52 53void setup() { 54 lcd.init(); 55 // initialize the lcd 56 lcd.backlight(); 57 lcd.print("Small 58 Hammer"); 59 Serial.begin(9600); 60 Serial.println(F("DHTxx test!")); 61 62 63 dht.begin(); 64} 65 66void loop() { 67 // Wait a few seconds between measurements. 68 69 delay(2000); 70 71 // Reading temperature or humidity takes about 250 milliseconds! 72 73 // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) 74 75 float h = dht.readHumidity(); 76 // Read temperature as Celsius (the default) 77 78 float t = dht.readTemperature(); 79 // Read temperature as Fahrenheit (isFahrenheit 80 = true) 81 float f = dht.readTemperature(true); 82 83 // Check if any reads 84 failed and exit early (to try again). 85 if (isnan(h) || isnan(t) || isnan(f)) 86 { 87 Serial.println(F("Failed to read from DHT sensor!")); 88 return; 89 90 } 91 92 // Compute heat index in Fahrenheit (the default) 93 float hif = 94 dht.computeHeatIndex(f, h); 95 // Compute heat index in Celsius (isFahreheit = 96 false) 97 float hic = dht.computeHeatIndex(t, h, false); 98 99 Serial.print(F("Humidity: 100 ")); 101 Serial.print(h); 102 Serial.print(F("% Temperature: ")); 103 Serial.print(t); 104 105 Serial.print(F("C ")); 106 Serial.print(f); 107 Serial.print(F("F Heat index: 108 ")); 109 Serial.print(hic); 110 Serial.print(F("C ")); 111 Serial.print(hif); 112 113 Serial.println(F("F")); 114 lcd.setCursor(0, 0); 115 lcd.print("Temp:"); 116 117 lcd.print(t); 118 119 lcd.write(0xDF); 120 121 lcd.print("C"); 122 123 lcd.setCursor(0, 1); 124 125 lcd.print("Humidity:"); 126 lcd.print(f); 127 lcd.print("%"); 128} 129
Downloadable files
arduino to DHT11
DHT11 connect to arduino Left 1 connect to arduino + 5V, Left 2 is signal lines connecte to arduino 2, Right 1 connect arduino GND IIC LCD1602 wiring methods: GND ———— GND VCC ———— 5V SDA ———— A4 SCL ———— A5
arduino to DHT11
Comments
Only logged in users can leave comments
ning
0 Followers
•1 Projects
1
0