loading

A few months ago i presented a workshop on Arduino and decided to build a simple weather station. The station measured the environment temperature and humidity, showing the data on an LCD and activating a visual indicator. This indicator consisted of three LEDs : one blue, one green and one red.

If the temperature drops below 20°C the blue LED turn on; if it was between 20ºC and 30ºC turn on the green and above 30ºC turn on the red LED.

Step 1: Components

Step 2: Wiring Diagram

Step 3: Code Header Section

To use the DHT22 and the LCD we need the libraries "DHT.h" and "LiquidCrystal.h". In "LiquidCrystal.h" it is necessary to define the Arduino pins to the LCD will use .

In "DHT.h" when initialized , you must choose what type of sensor we use . The library supports multiple sensors.

You can download the "DHT.h" and the "LiquidCrystal.h" from here:

DHT.h - https://github.com/adafruit/DHT-sensor-library

"LiquidCrystal.h" - https://github.com/adafruit/Adafruit_LiquidCrystal

/** Tiago Santos
* dark_storm@groundzero.com.pt
*  http://space.groundzero.com.pt

* free to share
*/
#include "DHT.h"
#include "LiquidCrystal.h"
#define DHTPIN 6
#define DHTTYPE DHT22
#define blue 8
#define green 9
#define red 10
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

Step 4: Code Setup Section

Then we started the setup, where we define the pins whre the LEDs are connected and that are OUTPUT, started the dht22 and set that the LCD has 16 columns by 2 lines.

void setup()
{
 Serial.begin(9600);
 pinMode(blue,OUTPUT);
 pinMode(green, OUTPUT);
 pinMode(red,OUTPUT);
 
 dht.begin();
 lcd.begin(16, 2);
}

Step 5: Code Loop Section

In the loop section, we read the humidity and the temperature and present them on the LCD. Humidity in line 0 and the temperature in line 1. Next, define what LED turn on. If the temperature is below 20°C we turn on blue. Between 20ºC and 30ºC turn on the green. Above 30 ° C we turn on red.

void loop(){
 delay(2000);
 float h = dht.readHumidity();
 float t = dht.readTemperature();
 if (isnan(h) || isnan(t) ){
  Serial.println("Failed to read from DHT sensor!");
  return;
 }
 lcd.setCursor(0, 0);
 lcd.print("Humid.: ");
 lcd.print(h);
 lcd.print(" %");
 lcd.setCursor(0, 1);
 lcd.print("Temp. : ");
 lcd.print(t);
 lcd.print(" C");
 Serial.print("Humidity: ");
 Serial.print(h);
 Serial.print(" %\t");
 Serial.print("Temperature: ");
 Serial.print(t);
 Serial.println(" *C ");
 if( t < 20 )
 {
  digitalWrite(green, LOW);
  digitalWrite(red, LOW);
  digitalWrite(blue, HIGH);
 }
 else
 {
  if(t > 30)
  {
   digitalWrite(green, LOW);
   digitalWrite(blue, LOW);
   digitalWrite(red, HIGH); 
  }
  else
  {
   digitalWrite(blue, LOW);
   digitalWrite(red, LOW);
   digitalWrite(green, HIGH); 
  }
 }
}

All the code is avaiable in my GitHub Account:

https://github.com/d4rks70rm/Arduino-DHT22-Sensor-with-LCD

<p>Hi! What version od arduino IDE did you use? your code doesnt seem to work,there a lot of </p><p>exit status 1<br>expected unqualified-id before '&lt;' token</p><p>since I have never programmed before in c++ (thats what arduino uses right?) the only experience I have is in computercraft in minecraft,and its very diffrent,anyways,in your code there are a lot of faults,and I dont know what wrong,the libraries? or the version,I want to use an arduino leonardo pro mini clone,but the problem is in the code anyways....do you have any fix for this? I searched the internet but they say its something that you didnt close or something like that but there dont seem to be any faults in my view......</p><p>Hope you understand me,I comment in a nice and informative way,I dont want to put hate on you.</p>
<p>ohh nevermind,I download your whole sketch from github and it doesnt have any faults,waht went wrong there? At first I just copy pasted the code,no problem then,I have one question though,you say you used an arduino nano,but in the pictures and in the schematic you seem to use an arduino leonardo pro micro? </p>
The arduino is an Arduino Nano. I've added the links to the material used.
Hello.<br>The code on instructables has some wrong tags. When i edited, some html was added and i don't notice. It's repaired.

About This Instructable

1,133views

19favorites

License:

Bio: https://about.me/tiago.santos
More by TiagoSantos:Prusa I3 Enclosure Marvin Night Light BQ Ciclop Home Made 
Add instructable to: