Introduction: Arduino "Talking" Temp / Humidity on a TFT LCD W/ Relays

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)


Step 1: Connections

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

Step 2: Code

The following code is still a work in progress, but is functional. Let us know if you find problems or have suggestions for improvements.

/*
Arduino TFT text example

This example demonstrates how to draw text on the
TFT with an Arduino.

This example code is in the public domain

Created 15 April 2013 by Scott Fitzgerald

http://arduino.cc/en/Tutorial/TFTDisplayText

Modded by Steve Spence of http://arduinotronics.blogspot.com


*/

#include "SPI.h"

#include "ST7735.h"


// Pins SCLK and MOSI are fixed in hardware, and pin 10 (or 53)
// must be an output
//#define sclk 13 // for MEGAs use pin 52
//#define mosi 11 // for MEGAs use pin 51
#define cs 10 // for MEGAs you probably want this to be pin 53
#define dc 9
#define rst 8 // you can also connect this to the Arduino reset

// pin definition for the Leonardo
// #define cs 7
// #define dc 0
// #define rst 1

// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);

// char array to print to the screen
char tempPrintout[6];
char humPrintout[6];




// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
// Fahrenheit conversion added by Steve Spence, http://arduinotronics.blogspot.com

#include "DHT.h" //https://learn.adafruit.com/dht/downloads



#define DHTPIN 2 // what pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

// Connect pin + (middle) of the sensor to +5V
// Connect pin S (on the right) of the sensor to whatever your DHTPIN is
// Connect pin - (on the left) of the sensor to GROUND
// Connect 10k resistor between S and +

int cycleTime = 2000;

DHT dht(DHTPIN, DHTTYPE);

float h;
float t;

void setup() {

// Put this line at the beginning of every sketch that uses the GLCD:
TFTscreen.begin();

// clear the screen with a black background
TFTscreen.background(0, 0, 0);

// write the static text to the screen
// set the font color to white
TFTscreen.stroke(255,255,255);
// set the font size
TFTscreen.setTextSize(2);
// write the text to the top left corner of the screen
TFTscreen.text("Temp (F)",0,0);
// write the text to the top left corner of the screen
TFTscreen.text("Humidity (%)",0,60);
// ste the font size very large for the loop
TFTscreen.setTextSize(4);

dht.begin();

}

void loop() {

// Read the value of the temp/humidity sensor on D2

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
h = dht.readHumidity();
t = dht.readTemperature();
t = (t*1.8)+32; //C to F conversion

String tempVal = doubleToString(t, 2);
String humVal = doubleToString(h, 0);
// String sensorVal = String(1.234);

// convert the reading to a char array
tempVal.toCharArray(tempPrintout, 6);
humVal.toCharArray(humPrintout, 6);

// set the font color
TFTscreen.stroke(255,255,255);
// print the sensor value
TFTscreen.text(tempPrintout, 0, 25);
TFTscreen.text(humPrintout, 0, 85);
// wait for a moment
delay(cycleTime);
// erase the text you just wrote
TFTscreen.stroke(0,0,0);
TFTscreen.text(tempPrintout, 0, 25);
TFTscreen.text(humPrintout, 0, 85);
}

//Rounds down (via intermediary integer conversion truncation)
String doubleToString(double input,int decimalPlaces){
if(decimalPlaces!=0){
String string = String((int)(input*pow(10,decimalPlaces)));
if(abs(input)<1){
if(input>0)
string = "0"+string;
else if(input<0)
string = string.substring(0,1)+"0"+string.substring(1);
}
return string.substring(0,string.length()-decimalPlaces)+"."+string.substring(string.length()-decimalPlaces);
}
else {
return String((int)input);
}
}

Step 3: Now With Text-To-Speech

We added our prototype TTS Shield, and made some slight modifications to the code. Now the temperature and humidity is spoken out loud. This can get annoying, so you may want to add a button for speech on demand! We changed the DHT-22 pin to 6 as the original pin 2 interferes with the SpeakEasy Shield. The SpeakEasy Shield (produced for us by http://www.hacktronics.com) is based on the SpeakJet and TTS256 chips, with an onboard amplifier.



//Speak Easy Setup


#include <SoftwareSerial.h>

#define txPin 2
#define rxPin 5
SoftwareSerial sjSerial = SoftwareSerial(rxPin, txPin);

int bufferPin = 4; // monitor buffer half full, or busy (jmp2)


/*
Arduino TFT text example

This example demonstrates how to draw text on the
TFT with an Arduino. The Arduino reads the value
of an analog sensor attached to pin A0, and writes
the value to the LCD screen, updating every
quarter second.

This example code is in the public domain

Created 15 April 2013 by Scott Fitzgerald

http://arduino.cc/en/Tutorial/TFTDisplayText

*/

#include // Arduino LCD library
#include

// pin definition for the Uno
#define cs 10
#define dc 9
#define rst 8

// pin definition for the Leonardo
// #define cs 7
// #define dc 0
// #define rst 1

// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);

// char array to print to the screen
char tempPrintout[6];
char humPrintout[6];




// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
// Fahrenheit conversion added by Steve Spence, http://arduinotronics.blogspot.com

#include


#define DHTPIN 6 // what pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

// Connect pin + (middle) of the sensor to +5V
// Connect pin S (on the right) of the sensor to whatever your DHTPIN is
// Connect pin - (on the left) of the sensor to GROUND
// Connect 10k resistor between S and +

int cycleTime = 2000;

DHT dht(DHTPIN, DHTTYPE);

float h;
float t;

void setup() {

// initialize the serial communications with the SpeakJet-TTS256
Serial.begin (9600);
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
pinMode(bufferPin, INPUT);
sjSerial.begin(9600);// set the data rate for the SoftwareSerial port

// Put this line at the beginning of every sketch that uses the GLCD:
TFTscreen.begin();

// clear the screen with a black background
TFTscreen.background(0, 0, 0);

// write the static text to the screen
// set the font color to white
TFTscreen.stroke(255,255,255);
// set the font size
TFTscreen.setTextSize(2);
// write the text to the top left corner of the screen
TFTscreen.text("Temp (F)",0,0);
// write the text to the top left corner of the screen
TFTscreen.text("Humidity (%)",0,60);
// ste the font size very large for the loop
TFTscreen.setTextSize(4);

dht.begin();

}

void loop() {

// Read the value of the temp/humidity sensor on D2

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
h = dht.readHumidity();
t = dht.readTemperature();
t = (t*1.8)+32; //C to F conversion

String tempVal = doubleToString(t, 0);
String humVal = doubleToString(h, 0);
// String sensorVal = String(1.234);

// convert the reading to a char array
tempVal.toCharArray(tempPrintout, 6);
humVal.toCharArray(humPrintout, 6);

// set the font color
TFTscreen.stroke(255,255,255);
// print the sensor value
TFTscreen.text(tempPrintout, 0, 25);
TFTscreen.text(humPrintout, 0, 85);
// wait for a moment
delay(cycleTime);
// erase the text you just wrote
TFTscreen.stroke(0,0,0);
TFTscreen.text(tempPrintout, 0, 25);
TFTscreen.text(humPrintout, 0, 85);

sjSerial.print("temprature ");
delay(250);
sjSerial.print(tempPrintout);
delay(500);
sjSerial.print(" humidity ");
delay(250);
sjSerial.println(humPrintout);
}

//Rounds down (via intermediary integer conversion truncation)
String doubleToString(double input,int decimalPlaces){
if(decimalPlaces!=0){
String string = String((int)(input*pow(10,decimalPlaces)));
if(abs(input)<1){
if(input>0)
string = "0"+string;
else if(input<0)
string = string.substring(0,1)+"0"+string.substring(1);
}
return string.substring(0,string.length()-decimalPlaces)+"."+string.substring(string.length()-decimalPlaces);
}
else {
return String((int)input);
}
}

Step 4: Adding a Relay Board

In this step, we add a 4 port relay board, that controls an air conditioner, heater, fan, and dehumidifier. If the temperature goes above 70 degrees F, then the fan and AC come on. If the temp drops below 65 and the humidity is above 50%, then the heat, fan, and dehumidifier come on. You can customize your switch points and logic in the code.

We are using a SainSmart 4 port relay board, and connecting the 4 input lines to analog ports repurposed as digital outputs. For more information, see http://arduinotronics.blogspot.com/2013/01/working-with-sainsmart-5v-relay-board.html

//SainSmart 4 port relay board setup
//We are out of digital ports, so repurposing
//analog inputs as digital outputs

// GND connected to Arduino GND
int relayPin1 = A0; // IN1 connected to digital pin A0
int relayPin2 = A1; // IN2 connected to digital pin A1
int relayPin3 = A2; // IN3 connected to digital pin A2
int relayPin4 = A3; // IN4 connected to digital pin A3
// VCC connected to Arduino +5v


//Speak Easy Setup



#include
#define txPin 2
#define rxPin 5
SoftwareSerial sjSerial = SoftwareSerial(rxPin, txPin);

int bufferPin = 4; // monitor buffer half full, or busy (jmp2)


/*
Arduino TFT text example

This example demonstrates how to draw text on the
TFT with an Arduino. The Arduino reads the value
of an analog sensor attached to pin A0, and writes
the value to the LCD screen, updating every
quarter second.

This example code is in the public domain

Created 15 April 2013 by Scott Fitzgerald

http://arduino.cc/en/Tutorial/TFTDisplayText

*/

#include // Arduino LCD library
#include

// pin definition for the Uno
// SCL Hardware 13
// SDA Hardware 11
#define cs 10
#define dc 9
#define rst 8


// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);

// char array to print to the screen
char tempPrintout[6];
char humPrintout[6];




// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
// Fahrenheit conversion added by Steve Spence, http://arduinotronics.blogspot.com

#include


#define DHTPIN 6 // what pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

// Connect pin + (middle) of the sensor to +5V
// Connect pin S (on the right) of the sensor to whatever your DHTPIN is
// Connect pin - (on the left) of the sensor to GROUND
// Connect 10k resistor between S and +

int cycleTime = 2000;

DHT dht(DHTPIN, DHTTYPE);

float h;
float t;

void setup() {

//Initialize SainSmart Relay Board
pinMode(relayPin1, OUTPUT); // sets the analog pin as digital output
pinMode(relayPin2, OUTPUT); // sets the analog pin as digital output
pinMode(relayPin3, OUTPUT); // sets the analog pin as digital output
pinMode(relayPin4, OUTPUT); // sets the sets the analog pin as digital output

digitalWrite(relayPin1, HIGH); // Prevents relays from starting up engaged
digitalWrite(relayPin2, HIGH); // Prevents relays from starting up engaged
digitalWrite(relayPin3, HIGH); // Prevents relays from starting up engaged
digitalWrite(relayPin4, HIGH); // Prevents relays from starting up engaged

// initialize the serial communications with the SpeakJet-TTS256
Serial.begin (9600);
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
pinMode(bufferPin, INPUT);
sjSerial.begin(9600);// set the data rate for the SoftwareSerial port

// Put this line at the beginning of every sketch that uses the GLCD:
TFTscreen.begin();

// clear the screen with a black background
TFTscreen.background(0, 0, 0);

// write the static text to the screen
// set the font color to white
TFTscreen.stroke(255,255,255);
// set the font size
TFTscreen.setTextSize(2);
// write the text to the top left corner of the screen
TFTscreen.text("Temp (F)",0,0);
// write the text to the top left corner of the screen
TFTscreen.text("Humidity (%)",0,60);
// ste the font size very large for the loop
TFTscreen.setTextSize(4);

dht.begin();

}

void loop() {

// Read the value of the temp/humidity sensor on D2

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
h = dht.readHumidity();
t = dht.readTemperature();
t = (t*1.8)+32; //C to F conversion

String tempVal = doubleToString(t, 0);
String humVal = doubleToString(h, 0);
// String sensorVal = String(1.234);

// convert the reading to a char array
tempVal.toCharArray(tempPrintout, 6);
humVal.toCharArray(humPrintout, 6);

// set the font color
TFTscreen.stroke(255,255,255);
// print the sensor value
TFTscreen.text(tempPrintout, 0, 25);
TFTscreen.text(humPrintout, 0, 85);
// wait for a moment
delay(cycleTime);
// erase the text you just wrote
TFTscreen.stroke(0,0,0);
TFTscreen.text(tempPrintout, 0, 25);
TFTscreen.text(humPrintout, 0, 85);

sjSerial.print("temprature ");
delay(250);
sjSerial.print(tempPrintout);
delay(500);
sjSerial.print(" humidity ");
delay(250);
sjSerial.println(humPrintout);

if(t>70){
digitalWrite(relayPin1, LOW); // turn on AC);
digitalWrite(relayPin2, HIGH); // turn off Heat);
digitalWrite(relayPin3, LOW); // turn on FAN);
digitalWrite(relayPin4, HIGH); // turn off Dehumidifier);
}

if(t<65 && h<50){
digitalWrite(relayPin1, HIGH); // turn off AC);
digitalWrite(relayPin2, LOW); // turn on Heat);
digitalWrite(relayPin3, LOW); // turn on FAN);
digitalWrite(relayPin4, HIGH); // turn off Dehumidifier);
}

if(t<65 && h>50){
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(t>65 && t< 70 && h>50){
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(t>65 && t< 70 && h<50){
digitalWrite(relayPin1, HIGH); // turn off AC);
digitalWrite(relayPin2, HIGH); // turn off Heat);
digitalWrite(relayPin3, HIGH); // turn off FAN);
digitalWrite(relayPin4, HIGH); // turn off Dehumidifier);
}
}

//Rounds down (via intermediary integer conversion truncation)
String doubleToString(double input,int decimalPlaces){
if(decimalPlaces!=0){
String string = String((int)(input*pow(10,decimalPlaces)));
if(abs(input)<1){
if(input>0)
string = "0"+string;
else if(input<0)
string = string.substring(0,1)+"0"+string.substring(1);
}
return string.substring(0,string.length()-decimalPlaces)+"."+string.substring(string.length()-decimalPlaces);
}
else {
return String((int)input);
}
}

Step 5: Future Upgrades

Future upgrades for this are using the included SD card socket on the display for logging, and web interface with a Ethernet shield. We will also add the ability to request the target temperature, using a potentiometer or up/down buttons.

See:

http://arduinotronics.blogspot.com/2012/03/arduino-thermostat.html

http://arduinotronics.blogspot.com/2013/01/working-with-sainsmart-5v-relay-board.html

http://arduinotronics.blogspot.com/2012/11/more-ethernet-read-analog-set-digital.html

http://arduinotronics.blogspot.com/2012/06/building-heating-air-conditioning.html

Add Dew Point and Heat Index calculations to your temperature and humidity project (works with any sensor) - http://arduinotronics.blogspot.com/2013/12/temp-humidity-w-dew-point-calcualtions.html


Comments

author
Graham Mantel (author)2015-09-25

This looks like a great item that will be used a lot Thanks

author
c_droner (author)2014-05-06

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!

author
sspence (author)c_droner2014-05-06

Just updated the code page with the link to the DHT library, and fixed the 3 includes that did not paste properly.

author
peter6961 (author)sspence2014-12-05

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 :-(

author
sspence (author)peter69612014-12-05

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

#include <SPI.h>

#include <ST7735.h>

author
peter6961 (author)sspence2014-12-05

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. :-)

author
sspence (author)peter69612014-12-06

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

author
peter6961 (author)sspence2014-12-06

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

author
peter6961 (author)sspence2014-12-05

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

author
sspence (author)2014-06-25

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

#include <SoftwareSerial.h>

author
dleec45 (author)sspence2014-07-13

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.

author
dleec45 (author)sspence2014-07-13

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?

author
sspence (author)dleec452014-07-14

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.

author
dleec45 (author)sspence2014-07-14

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?

author
dleec45 (author)dleec452014-07-14

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

author
sspence (author)dleec452014-07-15

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.

author
dleec45 (author)sspence2014-07-15

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);

author
dleec45 (author)dleec452014-07-15

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

author
sspence (author)dleec452014-07-15

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

author
dleec45 (author)dleec452014-07-14

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?

author
sspence (author)dleec452014-07-15

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

author
sspence (author)dleec452014-07-15

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.

author
dleec45 (author)dleec452014-07-13

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

author
sspence (author)sspence2014-06-25

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.

author
dleec45 (author)2014-06-25

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

author
sspence (author)dleec452014-06-25

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

author
dleec45 (author)sspence2014-06-25

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?

author
sspence (author)dleec452014-06-25

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

author
dleec45 (author)sspence2014-06-25

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

author
dleec45 (author)dleec452014-06-26

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

author
dleec45 (author)dleec452014-07-11

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
author
kurtee (author)2013-08-09

Yep,
That did the trick!
Glad to see that my display is working properly.
Many thanks for the write up!

author
sspence (author)kurtee2013-08-09

Sorry for the confusion. I need a version control system :-)

author
dleec45 (author)sspence2014-06-25

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?

author
sspence (author)dleec452014-06-25

Change the relay pins to whatever pins you have available.

author
c_droner (author)2014-05-12

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

author
c_droner (author)2014-05-10

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

author
sspence (author)c_droner2014-05-11

check your brightness and contrast resistors.

author
madmoonfish (author)2014-04-13

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!

author
sspence (author)madmoonfish2014-04-13

Sounds like you are missing the dht library.

author
sspence (author)sspence2014-05-06

Updated the code with a link to the libray, and fixed the 3 includes that did not paste properly.

author
madmoonfish (author)sspence2014-04-14

Aargh! I thought they were ok as they were showing up in my library. I even tried 3 different DHT libraries previously (which all showed up!) So what did was updated my arduino software to current version. Re-done the dht sensor files and now all works fab! Thanks very much! Just need to setup my relays and all will be up and running. Thanks again :D

author
kurtee (author)2013-08-09

Ok, something seems to be wrong!
You are showing CS, DC an RST to be pins 10,9 and 8.
In your code CS=10, DC=11 and RST =13
Also ,are the SCL clock and SDA data line coded from the libraries.
When I scope 13 it does not seem to be reset because it popping like a clock signal!
Very confused!!

author
sspence (author)kurtee2013-08-09

Good catch. Originally, we did software SPI (any pins can be used), then switched to hardware SPI (for faster performance), and forgot to update parts of the instructable. All should be fixed now.

author
dleec45 (author)sspence2013-11-21

Do I need to call the different code examples any particular name....kinda new at this...thanks

author
sspence (author)dleec452013-11-21

any name you would like, within arduino naming conventions.

author
dleec45 (author)sspence2014-01-02

Ask previous question about naming requirements of programs as haven't done this much and now I'm confused with how do you load all 4 programs to get everything to work? Any help appreciated...thanks

author
sspence (author)dleec452014-01-02

to load a sketch on an arduino, you use the arduino IDE, open the sketch to upload or type the code, and click the upload button. you can only have one sketch loaded at a time. Learning to use the Arduino IDE is beyond the scope of this tutorial. See http://arduino.cc/en/Guide/HomePage

author
dleec45 (author)sspence2014-01-02

Thanks sspence for the reply....I do understand that only one sketch can be loaded at a time but I'm trying to use all the features of this project with the relay and don't know how one accomplishes this.....any suggestions?

About This Instructable

49,030views

145favorites

License:

Bio: Professionally, I'm an IT Engineer (Executive Level) and Electronics Tech. I'm a Amateur Radio Operator (KK4HFJ). I lived off grid, with Solar (PV ... More »
More by sspence:DIY I2C LCD Display with InputsRaspberry Pi & the Neo 6M GPSEarthquake / Vibration Sensor
Add instructable to: