Devices & Components
Arduino Uno Rev3
DHT11 Temperature & Humidity Sensor (3 pins)
Rotary potentiometer (generic)
RGB Backlight LCD - 16x2
Resistor 10k ohm
Multicolored Dupont Wire
Thermistor
Project description
Code
DHT
arduino
Library for the DH11 sensor
1inary file (no preview
Liquid Crystal library
arduino
Library for the LCD panel
1inary file (no preview
DHT
arduino
Library for the DH11 sensor
1inary file (no preview
Liquid Crystal library
arduino
Library for the LCD panel
1inary file (no preview
ThDH11
arduino
Simple cade to measure temperature with a Thermistor and also temperature and humidity with the DH11 sensor, the output is displayed to the terminal and to an LCD display.
1// Measurement with the DH11 and thermistor 2//Printout to terminal and to the LCD display 3 4#include <dht_nonblocking.h> // DH11 5#define DHT_SENSOR_TYPE DHT_TYPE_11 // DH11 6#include <LiquidCrystal.h> // LCD display 7 8static const int DHT_SENSOR_PIN = 2; //DH11 9DHT_nonblocking dht_sensor( DHT_SENSOR_PIN, DHT_SENSOR_TYPE ); //DH11 10 11int tempPin = 0; // Thermistor 12 13// BS E D4 D5 D6 D7 14LiquidCrystal lcd(7, 8, 9, 10, 11, 12); 15 16// setup 17void setup() 18{ 19 Serial.begin(9600); 20 21 lcd.begin(16, 2); 22} 23 24static bool measure_environment( float *temperature, float *humidity ) // DH11 25{ 26 static unsigned long measurement_timestamp = millis( ); 27 28 /* Measure once every x seconds. */ 29 if( millis( ) - measurement_timestamp > 10000ul ) 30 { 31 if( dht_sensor.measure( temperature, humidity ) == true ) 32 { 33 measurement_timestamp = millis( ); 34 return( true ); 35 } 36 } 37 38 return( false ); 39} 40 41void loop() 42{ 43 // Thermistor 44 int tempReading = analogRead(tempPin); 45 double tempK = log(10000.0 * ((1024.0 / tempReading - 1))); 46 tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) * tempK ); // Temp Kelvin 47 float tempC = tempK - 273.15; // Convert Kelvin to Celcius 48 float tempF = (tempC * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit 49 50 // DH11 51 float temperature; 52 float humidity; 53 if( measure_environment( &temperature, &humidity ) == true ) 54 55 { 56 // Print a terminal 57 Serial.print( "DH11 " ); 58 Serial.print( temperature, 1 ); 59 Serial.print(" C, " ); 60 Serial.print( humidity, 1 ); 61 Serial.print(" %; Therm "); 62 Serial.print(tempC); 63 Serial.print(" C, "); 64 Serial.print(tempF); 65 Serial.print(" F\ 66"); 67 68 69 // Display in the LCD 70 // Display Temperature from the Thermistor 71 lcd.setCursor(0, 0); 72 lcd.print("Therm C "); 73 lcd.setCursor(7, 0); 74 lcd.print(tempC); 75 76 // Display Temperature from the DH11 77 lcd.setCursor(0, 2); 78 lcd.print("DH11 C %"); 79 lcd.setCursor(5, 2); 80 lcd.print(temperature,1); 81 82 // Display Humidity from the DH11 83 lcd.setCursor(11, 2); 84 lcd.print(humidity,1); 85 86 delay(500); 87 } 88} 89// This is the end.
Downloadable files
Circuit
Circuit

Circuit
Circuit

Comments
Only logged in users can leave comments