Adds

25 June 2015

Arduino with DHT11 - Prints temperature and humidity to LCD and serial monitor

Code gets:

- Temperature and Humidity from a DHT11 sensor

Prints the data to the Serial Monitor

Data is printed onto a LCD display

Please let me know if you experience any problems with this code. Be sure to check back for more Arduino code.

Schematic:




Code:


 /*  
   
 Oliver Holden  
 Created 28/10/2014  
   
 Components:  
 * Arduino UNO  
 * DHT11  
 * 4.7K resistor  
 * LCD  
   
 - Gets Temperature and Humidity from a DHT11 sensor  
   
 Prints the data to the Serial Monitor  
   
 Data is printed onto a LCD display  
   
 Schematic for this project is on  
 http://breadboarder.blogspot.co.uk/  
   
 */  
   
 #include <LiquidCrystal.h>   // Including Libaries needed  
 #include <dht.h>  
   
 dht DHT;   // Need this  
   
 LiquidCrystal lcd(8, 9, 4, 5, 6, 7);   // select the pins used on the LCD panel  
   
 int dht_dpin = A0;   // DHT11 Data pin attached to A0   
   
 void setup(){  
   
  Serial.begin(9600);   // Opening serial connection at 9600bps  
  lcd.begin(16, 2);   // Starting LCD libary and setting character size of LCD (X, Y)  
  lcd.setCursor(0,0);   // Setting starting position of text  
    
 }  
    
 void loop(){  
   
 DHT.read11(dht_dpin);   // Reading Data from DHT11  
 delay(2000);   // 2s delay beween reading DHT11  
   
   
 {  
    
  // Printing data to LCD   
    
  lcd.setCursor(0,0);      // move cursor to first line 0 and 9 spaces over  
  lcd.print("Temp = ");   
  lcd.print(DHT.temperature);  
  lcd.print(" C");  
    
  lcd.setCursor(0,1);      // move cursor to second line 1 and 9 spaces over  
  lcd.print("Hum = ");        
  lcd.print(DHT.humidity);  
  lcd.print(" % ");  
   
  }  
    
  // Printing data to Serial Monitor  
  lcd.print("Temp = ");   
  lcd.print(DHT.temperature);  
  lcd.print(" C");  
  lcd.print(",");  
    
  lcd.print("Hum = ");        
  lcd.print(DHT.humidity);  
  lcd.print(" % ");  
    
 }  

Arduino with a DHT11 and RGB LED which changes colour based on temperature - prints temperature and humidity to PLX-DAQ Excel spreedsheet and serial monitor

Code gets:

- Temperature and Humidity from a DHT11 sensor

and

 RGB LED changes colour depending on the Temperature

Prints the data to the Serial Monitor

Data is sent to an Excel spreadsheet through data acquisition software, PLX-DAQ, Download here

Please let me know if you experience any problems with this code. Be sure to check back for more Arduino code.

Schematic:




Code:


 /*  
   
 Oliver Holden  
 Created 28/10/2014  
   
 Components:  
 * Arduino UNO  
 * DHT11  
 * 4.7K resistor  
 * RGB LED  
 * 3x 220 ohm resistors  
   
 - Gets Temperature and Humidity from a DHT11 sensor  
   
 - RGB LED changes colour depending on the Temperature   
   
 Prints the data to the Serial Monitor  
   
 Data is sent to an Excel spreadsheet through data   
 acquisition software, PLX-DAQ, Download http://www.parallax.com/downloads/plx-daq  
   
 Schematic for this project is on  
 http://breadboarder.blogspot.co.uk/  
   
 */  
   
 #include <dht.h>   // Including libary to read DHT11   
    
 dht DHT;   // Need this   
   
 int x = 0;   // For PLX-DAQ  
 int row = 0;   // For PLX-DAQ  
   
 int redPin = 11;   // Red LED,  connected to digital pin 11  
 int grnPin = 10;  // Green LED, connected to digital pin 10  
 int bluPin = 9;  // Blue LED, connected to digital pin 9  
   
 int dht_dpin = A0;   // DHT11 data pin attached to A2   
    
 void setup(){     
    
  Serial.begin(9600);   // Opening serial connection at 9600bps   
  Serial.println("Humidity and temperature");   // Printing Serial Monitor header  
  Serial.println("LABEL, Time, T (C)");   // Setting headers of colums in PLX-DAQ spreadsheet  
  delay(1000);   // Wait 1 second before printing data to Serial Monitor  
    
  pinMode(redPin, OUTPUT);   // Sets the pins as output for RGB LED  
  pinMode(grnPin, OUTPUT);  
  pinMode(bluPin, OUTPUT);  
    
  }  
    
 void loop(){     
    
  DHT.read11(dht_dpin);   // Reading data from DHT11  
    
   Serial.print("Current humidity = ");   // Printing text  
    
   Serial.print(DHT.humidity);     
   Serial.print("% ");     
   Serial.print("temperature = ");     
   Serial.print(DHT.temperature);     
   Serial.println("C ");     
    
  // Setting the colours of the RGB LED based on temperature,  
 // Colour is shown for 0.1s before checking temperature again.  
   
 if((DHT.temperature < 26) && (DHT.temperature >= 23.2))   // Writing the LED colour pins HIGH or LOW to set colours  
  {  
   digitalWrite(redPin, HIGH);  // yellow  
   digitalWrite(grnPin, HIGH);  
   delay(100);  
     
   digitalWrite(bluPin, LOW);  
   
  }  
    
  if((DHT.temperature < 23) && (DHT.temperature > 20.2))  
  {  
   digitalWrite(grnPin, HIGH);  // green  
   delay(100);  
     
   digitalWrite(redPin, LOW);  
   digitalWrite(bluPin, LOW);  
    
  }  
   
 if((DHT.temperature < 20) && (DHT.temperature > 17.2))  
  {  
   digitalWrite(grnPin, HIGH);  // aqua  
   digitalWrite(bluPin, HIGH);  
   delay(100);  
     
   digitalWrite(redPin, LOW);  
     
   
  }  
   
  if(DHT.temperature <= 17)  
  {  
   digitalWrite(bluPin, HIGH);  // blue  
   delay(100);  
     
   digitalWrite(grnPin, LOW);  
   digitalWrite(redPin, LOW);  
    
  }  
    
 row++;   // For PLX-DAQ  
 x++;   // For PLX-DAQ  
    
  delay(1000);   // Sensor shouldn't be read too frequently so delay of 1s  
    
  }  

Arduino with a DHT11 and RGB LED which changes colour based on temperature - Prints temperature and humidity to serial monitor

Code gets:

- Temperature and Humidity from a DHT11 sensor

and

 RGB LED changes colour depending on the Temperature

Prints the data to the Serial Monitor

Please let me know if you experience any problems with this code. Be sure to check back for more Arduino code.

Schematic:




Code:


 /*  
   
 Oliver Holden  
 Created 28/10/2014  
   
 Components:  
 * Arduino UNO  
 * DHT11  
 * 4.7K resistor  
 * RGB LED  
 * 3x 220 ohm resistors  
   
 - Gets Temperature and Humidity from a DHT11 sensor  
   
 - RGB LED changes colour depending on the Temperature   
   
 Prints the data to the Serial Monitor  
   
 Schematic for this project is on  
 http://breadboarder.blogspot.co.uk/  
   
 */  
   
 #include <dht.h>   // Including libary to read DHT11   
    
 dht DHT;   // Need this   
   
 int redPin = 11;   // Red LED,  connected to digital pin 11  
 int grnPin = 10;  // Green LED, connected to digital pin 10  
 int bluPin = 9;  // Blue LED, connected to digital pin 9  
   
 int dht_dpin = A0;   // DHT11 data pin attached to A2   
    
 void setup(){     
    
  Serial.begin(9600);   // Opening serial connection at 9600bps   
  Serial.println("Humidity and temperature");   // Printing Serial Monitor header  
  delay(1000);   // Wait 1 second before printing data to Serial Monitor  
    
  pinMode(redPin, OUTPUT);   // Sets the pins as output for RGB LED  
  pinMode(grnPin, OUTPUT);  
  pinMode(bluPin, OUTPUT);  
    
  }  
    
 void loop(){     
    
  DHT.read11(dht_dpin);   // Reading data from DHT11  
    
   Serial.print("Current humidity = ");   // Printing text  
    
   Serial.print(DHT.humidity);     
   Serial.print("% ");     
   Serial.print("temperature = ");     
   Serial.print(DHT.temperature);     
   Serial.println("C ");     
    
  // Setting the colours of the RGB LED based on temperature,  
 // Colour is shown for 0.1s before checking temperature again.  
   
 if((DHT.temperature < 26) && (DHT.temperature >= 23.2))   // Writing the LED colour pins HIGH or LOW to set colours  
  {  
   digitalWrite(redPin, HIGH);  // yellow  
   digitalWrite(grnPin, HIGH);  
   delay(100);  
     
   digitalWrite(bluPin, LOW);  
   
  }  
    
  if((DHT.temperature < 23) && (DHT.temperature > 20.2))  
  {  
   digitalWrite(grnPin, HIGH);  // green  
   delay(100);  
     
   digitalWrite(redPin, LOW);  
   digitalWrite(bluPin, LOW);  
    
  }  
   
 if((DHT.temperature < 20) && (DHT.temperature > 17.2))  
  {  
   digitalWrite(grnPin, HIGH);  // aqua  
   digitalWrite(bluPin, HIGH);  
   delay(100);  
     
   digitalWrite(redPin, LOW);  
     
   
  }  
   
  if(DHT.temperature <= 17)  
  {  
   digitalWrite(bluPin, HIGH);  // blue  
   delay(100);  
     
   digitalWrite(grnPin, LOW);  
   digitalWrite(redPin, LOW);  
    
  }  
    
  delay(1000);   // Sensor shouldn't be read too frequently so delay of 1s  
    
  }  

Arduino with DHT11 - Prints temperature and humidity to PLXDAQ Excel spreadsheet and serial monitor

Code gets:

- Temperature and Humidity from a DHT11 sensor

Prints the data to the Serial Monitor

Data is sent to an Excel spreadsheet through data acquisition software, PLX-DAQ, Download here

Please let me know if you experience any problems with this code. Be sure to check back for more Arduino code.

Schematic:




Code:


 /*  
   
 Oliver Holden  
 Created 28/10/2014  
   
 Components:  
 * Arduino UNO  
 * DHT11  
 * 4.7K resistor  
   
 - Gets Temperature and Humidity from a DHT11 sensor  
   
 - RGB LED changes colour depending on the Temperature   
   
 Prints the data to the Serial Monitor  
   
 Data is sent to an Excel spreadsheet through data   
 acquisition software, PLX-DAQ, Download http://www.parallax.com/downloads/plx-daq  
   
 Schematic for this project is on  
 http://breadboarder.blogspot.co.uk/  
   
 */  
   
   
 #include <dht.h>   // Including libary to read DHT11   
    
 dht DHT;   // Need this   
   
 int x = 0;   // For PLX-DAQ  
 int row = 0;   // For PLX-DAQ  
   
 int dht_dpin = A0;   // DHT11 data pin attached to A2   
    
 void setup(){     
    
  Serial.begin(9600);   // Opening serial connection at 9600bps   
  Serial.println("Humidity and temperature");   // Printing Serial Monitor header  
  Serial.println("LABEL, Time, T (C)");   // Setting headers of colums in PLX-DAQ spreadsheet  
  delay(1000);   // Wait 1 second before printing data to Serial Monitor  
  }  
    
 void loop(){     
    
  DHT.read11(dht_dpin);   // Reading data from DHT11  
    
   Serial.print("Current humidity = ");   // Printing text  
    
   Serial.print(DHT.humidity);     
   Serial.print("% ");     
   Serial.print("temperature = ");     
   Serial.print(DHT.temperature);     
   Serial.println("C ");     
     
 row++;   // For PLX-DAQ  
 x++;   // For PLX-DAQ  
    
  delay(1000);   // Sensor shouldn't be read too frequently so delay of 1s  
    
  }  

Arduino with DHT11 - Prints temperature and humidity to serial monitor

Code gets:

- Temperature and Humidity from a DHT11 sensor

Prints the data to the Serial Monitor

Please let me know if you experience any problems with this code. Be sure to check back for more Arduino code.

Schematic:


Code:


 /*  
   
 Oliver Holden  
 Created 28/10/2014  
   
 Components:  
 * Arduino UNO  
 * DHT11  
 * 4.7K resistor  
   
 - Gets Temperature and Humidity from a DHT11 sensor  
   
 Prints the data to the Serial Monitor  
   
 Schematic for this project is on  
 http://breadboarder.blogspot.co.uk/  
   
 */  
   
 #include <dht.h>   // Including libary to read DHT11   
    
 dht DHT;   // Need this   
   
 int dht_dpin = 2;   // DHT11 data pin attached to A2   
    
 void setup(){     
    
  Serial.begin(9600);   // Opening serial connection at 9600bps   
  Serial.println("Humidity and temperature");   // Printing Serial Monitor header  
  delay(1000);   // Wait 1 second before printing data to Serial Monitor  
  }  
    
 void loop(){     
    
  DHT.read11(dht_dpin);   // Reading data from DHT11  
    
   Serial.print("Current humidity = ");   // Printing text  
    
   Serial.print(DHT.humidity);     
   Serial.print("% ");     
   Serial.print("temperature = ");     
   Serial.print(DHT.temperature);     
   Serial.println("C ");     
    
  delay(1000);   // Sensor shouldn't be read too frequently so delay of 1s  
    
  }