Offline
Jr. Member
Karma: 0
Posts: 75
|
 |
« on: February 13, 2013, 06:21:05 am » |
I'm building a simple fan controller...I want the fan to switch on at 27c and go off at 25c, hence creating a 2c hysteresis.. at the moment with the code below the fan goes on off around 27.... is this due to the else command .. do I create a >27 and <25 scenarios and put the else between? { if(t>=27) {//lcd.setCursor(0, 0); //lcd.print("* hot * "); digitalWrite(fan, HIGH); lcd.setCursor(15, 0); lcd.print("F");} else {//lcd.setCursor(0, 0); // lcd.print(" Just Right "); digitalWrite(fan, LOW); lcd.setCursor(15, 0); lcd.print("_"); } { if(t<=25) {//lcd.setCursor(0, 0); //lcd.print("It's Freezing");} digitalWrite(fan, LOW);} } Second question. I'm using the DHT 11 sensor, the temp is only shown in single 1c units, no decimal.. Im using the library from http://learn.adafruit.com/dht/using-a-dhtxx-sensorthanks for any help
|
|
|
|
|
Logged
|
|
|
|
|
Norfolk UK
Offline
Edison Member
Karma: 23
Posts: 1317
|
 |
« Reply #1 on: February 13, 2013, 06:28:43 am » |
I'm building a simple fan controller...I want the fan to switch on at 27c and go off at 25c, hence creating a 2c hysteresis.. at the moment with the code below the fan goes on off around 27.... is this due to the else command .. Yes do I create a >27 and <25 scenarios and put the else between? Just have a >=27 and <=25 with no else condition.Second question. I'm using the DHT 11 sensor, the temp is only shown in single 1c units, no decimal.. Im using the library from http://learn.adafruit.com/dht/using-a-dhtxx-sensorYou don't show code for this but your probably using int instead of float and loosing the .x part.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 75
|
 |
« Reply #2 on: February 13, 2013, 06:32:01 am » |
Ok so code { if(t>=27) { digitalWrite(fan, HIGH); lcd.setCursor(15, 0); lcd.print("F");} if(t<=25) {digitalWrite(fan, LOW);} }
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 75
|
 |
« Reply #3 on: February 13, 2013, 06:33:11 am » |
Code for reading sensor = I'm using float, but it only shows in 1c increments. float h = dht.readHumidity(); float t = dht.readTemperature(); // check if returns are valid, if they are NaN (not a number) then something went wrong! if (isnan(t) || isnan(h)) { Serial.println("Failed to read from DHT"); } else { Serial.print("Humidity: "); Serial.print(h); Serial.print(" % "); Serial.print("Temp: "); Serial.print(t); Serial.println("C"); }
// set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(8, 1); lcd.print("H:"); lcd.print(h); lcd.print("%"); //delay(2000); lcd.setCursor(0, 1); lcd.print("T:"); lcd.print(t); //lcd.print("C"); //delay(2000);
{ if(t>=25) {//lcd.setCursor(0, 0); //lcd.print("* hot * "); digitalWrite(fan, HIGH); lcd.setCursor(15, 0); lcd.print("F");} else {//lcd.setCursor(0, 0); // lcd.print(" Just Right "); digitalWrite(fan, LOW); lcd.setCursor(15, 0); lcd.print("_"); } { if(t<=23) {//lcd.setCursor(0, 0); //lcd.print("It's Freezing");} digitalWrite(fan, LOW);} }
|
|
|
|
« Last Edit: February 13, 2013, 06:50:29 am by Hackdub »
|
Logged
|
|
|
|
|
Poole, Dorset, UK
Offline
God Member
Karma: 8
Posts: 669
|
 |
« Reply #4 on: February 13, 2013, 06:53:59 am » |
You must make use of the auto format option on the IDE. It makes code so much more readable. (And helps keep PaulS at bay).
Mark
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 75
|
 |
« Reply #5 on: February 13, 2013, 07:01:39 am » |
OK try again... still only reads in 1 deg c increments void loop() {
float h = dht.readHumidity(); float t = dht.readTemperature(); // check if returns are valid, if they are NaN (not a number) then something went wrong! if (isnan(t) || isnan(h)) { Serial.println("Failed to read from DHT"); } else { Serial.print("Humidity: "); Serial.print(h); Serial.print(" % "); Serial.print("Temp: "); Serial.print(t); Serial.println("C"); }
// set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(8, 1); lcd.print("H:"); lcd.print(h); lcd.print("%"); //delay(2000); lcd.setCursor(0, 1); lcd.print("T:"); lcd.print(t); //lcd.print("C"); //delay(2000);
if(t>=27)
{ digitalWrite(fan, HIGH); lcd.setCursor(15, 0); lcd.print("F"); }
if(t<=25)
{ digitalWrite(fan, LOW); lcd.setCursor(15, 0); lcd.print("_"); }
|
|
|
|
|
Logged
|
|
|
|
|
Norfolk UK
Offline
Edison Member
Karma: 23
Posts: 1317
|
 |
« Reply #6 on: February 13, 2013, 07:10:11 am » |
Did you set the DHT type in the library as stated in the Adafruit tutorial you linked to and what readout do you get if you use the example sketch included in the Adafruit library download?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 75
|
 |
« Reply #7 on: February 13, 2013, 07:13:29 am » |
yes.. set as dht 11
and when using example just get it as 1 degress c increments.
i think there example shown on website , is using the dht22... not sure if that matters.
ive looked at the library files and cant see if thats the issue.
|
|
|
|
|
Logged
|
|
|
|
|
New Jersey
Offline
Edison Member
Karma: 24
Posts: 2345
|
 |
« Reply #8 on: February 13, 2013, 07:23:06 am » |
ive looked at the library files and cant see if thats the issue. It is. case DHT11: f = data[2];
f is the float temp read, but the data array is declared as uint8_t, so it will always be a whole number.
|
|
|
|
|
Logged
|
|
|
|
|
Norfolk UK
Offline
Edison Member
Karma: 23
Posts: 1317
|
 |
« Reply #9 on: February 13, 2013, 07:26:57 am » |
Using Google translate on the datasheet and it looks like the DHT-11 is scaled to 1 degree values. Parameter Condition Min Typ Max Units Temperature 1 1 1 C Resolution 8 8 8 Bit Repeatability of ± 1 C Accuracy of ± 1 ± 2 C
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 75
|
 |
« Reply #10 on: February 13, 2013, 07:37:55 am » |
So looks like I'm stuck with 1 deg c unless I change to dht22?
thanks for the help so far BTW
|
|
|
|
|
Logged
|
|
|
|
|
Poole, Dorset, UK
Offline
God Member
Karma: 8
Posts: 669
|
 |
« Reply #11 on: February 13, 2013, 08:18:28 am » |
|
|
|
|
|
Logged
|
|
|
|
|
|