Instructables

Arduino "Talking" Temp / Humidity on a TFT LCD w/ relays

Picture of Arduino

From the minds of http://arduinotronics.blogspot.com

UPDATE: Added our SpeakEasy Text-To-Speech (TTS) Shield to make this a "Talking" Weather Station!

UPDATE: Added a 4 port relay board for device control

UPDATE: Added Dew Point and Heat Index calculations

SainSmart sent me a 1.8" TFT LCD (ST7735R), and I decided to upgrade my Weather Station / Thermostat. This time around, I used the slightly less accurate but much less expensive DHT-22 (AM2302) temperature / humidity sensor. I also received a BMP-085 barometric pressure sensor, but it appears dead. More on that in the near future. Tighten your seat belt, and here we go:

Parts:

Arduino Uno
1.8 TFT LCD
DHT-22
10k Ohm Resistor
Relay Board (optional)
Male / Female Jumpers (very helpful)


 
Remove these adsRemove these ads by Signing Up

Step 1: Connections

Picture of Connections
TFT_DHT.PNG

Connect the DHT-22 sensor and the LCD display as per the schematic. There are also connections on the left side of the display for the SD card, and we will address that at a future edit for logging purposes. Just use the connections on the right side of the display for now.

DHT-22:

(S)ignal to Arduino Pin 2
+5 to Arduino +5vdc
G to Arduino Ground
10k Resistor between S and +5vdc

ST7735R LCD:

VCC to Arduino +5vdc
Gnd to Arduino Ground
SCL to Ardiuino Pin 13
SDA to Arduino Pin 11
CS to Arduino Pin 10
DC to Arduino Pin 9
Reset to Arduino Pin 8

1-40 of 53Next »
c_droner7 months ago

Hi,

I was having the same problem as madmoonfish was having, and I don't understand where to get the DHT library. If you could help me out, that would be great!

sspence (author)  c_droner7 months ago
Just updated the code page with the link to the DHT library, and fixed the 3 includes that did not paste properly.
can you please tell me what to include, sketch is saying error class tft has no member named background, stroke, text in various sections of t he code.
Ive installed the gfx amd st7735 libraries but im just not too sure how to make them work, the errors look like to not me, im missing a library or something! ? im not sure.
Please help!
Im going to use this for an automated greenhouse. :-)
my screen came in the mail today but all I get is a white backlight :-(
sspence (author)  peter696113 days ago

< and > symbols get dropped when pasting in the code. Went back and fixed.

#include <SPI.h>

#include <ST7735.h>

I forgot to ask, in the code for your screen I noticed your using BLACKTAB witch is the S version, but you talk about using the R version witch is the screen I ordered wich is GREENTAB I think there is also a BLUETAB version that they sell.
do I just replace BLACKTAB with GREENTAB in the code?
thank you for your help, its very much appreciated. :-)
sspence (author)  peter696112 days ago

I went back and looked at my code, and don't see "blacktab", "greentab" etc. what line of code are you referring to? The code should work on any ST7735

im sorry that is from another code, ignore that. very sorry for the confusion.
ill try the updated code soon. if it still doesn't work ill reinstall the IDE
thank you very much for replying, ill try it in a few hours.
my back went out thismorning so cant sit, wish there was a sketch download link.
if its not too much to ask can you please email me the code?
thank you. once again
kurtee1 year ago
Yep,
That did the trick!
Glad to see that my display is working properly.
Many thanks for the write up!
sspence (author)  kurtee1 year ago
Sorry for the confusion. I need a version control system :-)
dleec45 sspence5 months ago

I'm trying to put this together and have a bit of a problem in the wiring.

In the code talking about the TFT the following pin assignments are mentioned:

CS to Arduino Pin 10

DC to Arduino Pin 9

Reset to Arduino Pin 8


and from this link talking about the relay http://arduinotronics.blogspot.com/2013/01/working-with-sainsmart-5v-relay-board.html


the following code is given:

int relayPin2 = 8; // IN2 connected to digital pin 8

int relayPin3 = 9; // IN3 connected to digital pin 9

int relayPin4 = 10; // IN3 connected to digital pin 10

are these two sharing the same pins?

sspence (author)  dleec455 months ago

Change the relay pins to whatever pins you have available.

dleec45 sspence5 months ago
(removed by author or community request)
sspence (author)  dleec455 months ago

When I pasted the code, it dropped the <> from the include:

#include <SoftwareSerial.h>

dleec45 sspence5 months ago

Couldn't find any pics to show how you would hook up the relays in this project and hope the image I included is what you had in mind but it's from one I found in reading another project on HomeBrewTalk.

sspence (author)  dleec455 months ago
dleec45 sspence5 months ago

Yeah I've been there several times so what am I missing that I don't understand. Sorry to be so dense but I'm at a loss for words?

sspence (author)  dleec455 months ago

you engage the relay by sending it a low (0). if you have the sainsmart board connected per the article at http://arduinotronics.blogspot.com/2013/01/working-with-sainsmart-5v-relay-board.html and use that sample sketch, it will work. If it doesn't, then your board may be defective.

dleec45 sspence5 months ago

Thanks again Steve for the reply...my problem is that I don't know how to take this info:


K4


1 - Normally Open


2 - Common


3 - Normally Closed

and wire up the relays correctly...the uno I'm using is this one:

http://www.sainsmart.com/arduino/control-boards/sa...

so I'm assuming the relays go to the DO-D13 (7-10) of the S connection and have hooked it up that way and when I try it, one of my relays is on and two click on and back off over and over....am I out in left field here?

dleec45 dleec455 months ago

PS that schematic tell me nothing in how to wire up the relays if that is it's intent, just don't know electronics that well

sspence (author)  dleec455 months ago

A relay is just a switch. if you have a light bulb connected to power, insert (series) the relay into one leg of the light bulb, power to common, light to Normally Closed. when you send a low to that relay, the light comes on.

dleec45 sspence5 months ago

Yes I do understand that and the test code validates it perfectly, I don't understand why the test code doesn't work when I paste it into the sketch which test for hum and temp....acts completely different and the lights on the relays will flash then come on and more strange when I comment out the test code and use the regular code to test the relays, the relays that should come on don't or not all of them that should and I get lighting conditions that doesn't match any code because maybe one is on but not another that should be on to match condition that exist isn't.....very strange...as an example, the display shows temp to be 75 and hum 39 which means that according to my code I should have 2 lights on, Fan and Humidifier. but I only have Pin2 on...I don't have a condition where just Pin2 alone should be on but that's what I got??

// if temp is right but humidity is low
if(t>70 && t<80 && h<90){
digitalWrite(relayPin1, HIGH); // turn off AC);
digitalWrite(relayPin2, LOW); // turn on Fan);
digitalWrite(relayPin3, HIGH); // turn off Heat);
digitalWrite(relayPin4, LOW); // turn on Humidifier);

dleec45 dleec455 months ago

Just switched to usin3 pins A0-A3 and everything seems to work just fine.....thanks for all my ignorance but it's been fun for me and frustrating for you...appreciate your patience.....really

sspence (author)  dleec455 months ago

No worries, just glad it's working for you now!

dleec45 dleec455 months ago

OK tried the code and it worked perfectly.....so went back to my code and loaded it again and here's the strange part. I loaded in your test code and commented out the temp testing and it works, but the display doesn't work for more than one cycle and I changed the code to do the following:

digitalWrite(relayPin1, LOW); // energizes AC
delay(1000); // waits for a second
digitalWrite(relayPin1, HIGH); // de-energizes AC
delay(1000); // waits for a second
digitalWrite(relayPin2, LOW); // de-energizes Fan
delay(1000); // waits for a second

etc...

.it cycles thru one relay at a time with one crazy twist....It goes from 1 to 2 to 3 to 4 then it flashes 3 and 4 at the same time twice with a 1 second delay between flashes, then goes back to 1 then 2 etc for the 1 sec delay then flashes 3 and 4 twice again and repeats forever in this pattern. I know the wiring is right (don't I?) but have no idea about the strange flashing of 3 and 4..there is no code for this.....and why doesn't the display work anymore...any ideas?

sspence (author)  dleec455 months ago

Sounds like you have the relay board connected to the display pins.

sspence (author)  dleec455 months ago

The LCD is using 8-13, so you can't use those for the relays. You need to pick other (available) pins and change your code accordingly. K1-4 are your 4 relays, pins 1,2, & 3 of those relays go to your loads. if you apply power to common, pin3 will have power if the arduino sends a high, and pin 1 if the arduino sends a low.

dleec45 dleec455 months ago

You talking about my wiring, code, don't understand? Thanks,

sspence (author)  sspence5 months ago

Looks like most of the includes got scrambled. I'll have to dig up the original sketch, and fix the includes. Instructables won't let you paste them in.

dleec45 dleec455 months ago

Got the compile working and loaded....getting Temp reading of 32F and Humidity of 0.....any suggestions appreciated

sspence (author)  dleec455 months ago

test with the sample code at https://learn.adafruit.com/dht to make sure your sensor is working.

dleec45 sspence5 months ago

YEAH, says failing to read from DHT sensor.....does that really mean the sensors is bad or could it be another problem....appears to be hooked up right and I have the correct pin setting of 6 on the board and software....whatcha think?

sspence (author)  dleec455 months ago

if the sample code fails, and you have it wired correctly, you may have a bad sensor.

dleec45 sspence5 months ago

Thanks so much....will check wiring again but I'm afraid you're correct....awesome response, thanks again

dleec45 dleec455 months ago

Tested with another UNO and it was my wiring.....thanks for all your help...really excited that it works ....if I can get the relays hooked up correctly, I'm in business

dleec45 dleec455 months ago

Just started to try and hook up the relays and although they are wired, don't seem to work as they don't match the conditions stated in the software below...any ideas?....I have attached am image showing how I wired them up and when I am using the low side all 4 are on and on the HIGH slide all 4 are off and the temp and humidity in the room I'm in is like 85 F with the humidity at 75 so the relay conditions don't match what the code says it should be...

// if temp is right and humidity is correct (above 95)
if(t>70 && t<80 && h>95){
digitalWrite(relayPin1, HIGH); // turn off AC);
digitalWrite(relayPin2, HIGH); // turn off Heat);
digitalWrite(relayPin3, HIGH); // turn off FAN);
digitalWrite(relayPin4, HIGH); // turn off Dehumidifier);
}

// if temp is right but humidity is low
if(t>70 && t<80 && h<90){
digitalWrite(relayPin1, HIGH); // turn off AC);
digitalWrite(relayPin2, HIGH); // turn off Heat);
digitalWrite(relayPin3, LOW); // turn on FAN);
digitalWrite(relayPin4, LOW); // turn on Dehumidifier);
}

// if temp is low (below 70) and humidity is low (below 95)
if(t<70 && h<95){
digitalWrite(relayPin1, HIGH); // turn off AC);
digitalWrite(relayPin2, LOW); // turn on Heat);
digitalWrite(relayPin3, LOW); // turn on FAN);
digitalWrite(relayPin4, LOW); // turn on Dehumidifier);
}

// if temp is high (above 80) and humidity is low (below 95)
if(t<80 && h<95){
digitalWrite(relayPin1, LOW); // turn on AC);
digitalWrite(relayPin2, HIGH); // turn on Heat);
digitalWrite(relayPin3, LOW); // turn on FAN);
digitalWrite(relayPin4, LOW); // turn on Dehumidifier);
}

// if temp is high (above 80) and humidity is high (above 95)
if(t>80 && h>95){
digitalWrite(relayPin1, LOW); // turn on AC);
digitalWrite(relayPin2, HIGH); // turn off Heat);
digitalWrite(relayPin3, HIGH); // turn off FAN);
digitalWrite(relayPin4, HIGH); // turn off Dehumidifier);
}

// if temp is low (below 70) and humidity is high (above 95)
if(t<70 && h<95){
digitalWrite(relayPin1, HIGH); // turn off AC);
digitalWrite(relayPin2, LOW); // turn on Heat);
digitalWrite(relayPin3, HIGH); // turn off FAN);
digitalWrite(relayPin4, HIGH); // turn off Dehumidifier);
}
Any thoughts? Thanks

Wiring relays.png
c_droner7 months ago

Okay, how would I hook the pressure sensor up to this project. Where would it go into the sketch?

c_droner7 months ago

Hello again,

Although my sensor is working and I am receiving accurate info, the screen is real dim, nothing like in your video. Is this something you would know how to fix?

Many thanks

sspence (author)  c_droner7 months ago
check your brightness and contrast resistors.
madmoonfish8 months ago

Hi. I was wondering if you can help me. I am planning on using this (minus talking part) for a homemade incubator. Am trying to set-up the code, but I get an error. The part hi-lighted is "DHT dht(DHTPIN, DHTTYPE);" with the error "'DHT' does not name the type." I would be grateful for your thought, as search this problem has come up with no easy fix.

Great and inspiring instructable!

1-40 of 53Next »