Arduino UNO -temp./humid. program code modification

Discussion in 'Programmer's Corner' started by neo1111, May 2, 2015.

  1. neo1111

    Thread Starter New Member

    Jan 11, 2014
    28
    1
    Hy there.
    Let me explain what i intend to do: using 2 pins , if the temperature is over 40 degrees then set digitalpin3(LOW) --> 0V.(is an example)
    If humidity is over 95 % , then set digitalpin3(low).
    But, if the temperature is over 40 , only one pin is LOW(OV) , the other one is (HIGH) amd the other way for exceeding 95% for humidity .
    At first the pins must be on HIGH.(both) initially .
    I have the program but my modifications havent led me anywhere.
    I want to modify this program because it is tested and works just fine .
    Any ideas?Thx!
    Code (Text):
    1. Code:
    2. #include "DHT.h"                      
    3. #define DHTPIN 9                        
    4. #define DHTTYPE DHT22                    
    5. DHT dht22(DHTPIN, DHTTYPE);              
    6. #include "Wire.h"                        
    7. #include "LiquidCrystal_I2C.h"
    8. LiquidCrystal_I2C lcd(0x27,16,2);          
    9. void setup()
    10. {
    11.   Serial.begin(9600);                    
    12.   Serial.println("DHT22 serial");
    13. dht22.begin();                            
    14. lcd.init();                                                                    
    15. lcd.backlight();                          
    16. lcd.print("  OK ");
    17. lcd.setCursor (0, 1);
    18. lcd.print(F("Reading data"));
    19.     delay(5550);
    20.  
    21. }
    22.  
    23. void loop()
    24. {
    25.   lcd.setCursor(0,0);
    26.   float t = dht22.readTemperature() ;      
    27.   float h = dht22.readHumidity() ;        
    28.   Serial.print("Temperature is: ");      
    29.   Serial.print(t);                      
    30.   Serial.print(" C\t");                  
    31.   Serial.print("Humidity is: ");          
    32.   Serial.print(h);                      
    33.   Serial.print(" %");                  
    34. lcd.setCursor(0, 0);                    
    35. lcd.print("Temp.  : ");                  
    36. lcd.setCursor(9, 0);                    
    37. lcd.print(t);                        
    38. lcd.setCursor(15, 0);              
    39. lcd.print("C");                      
    40. lcd.setCursor(0, 1);                    
    41. lcd.print("Umidit.:       ");                  
    42. lcd.setCursor(9, 1);                    
    43. lcd.print(h);                            
    44. lcd.setCursor(15, 1);                  
    45. lcd.print("%");                          
    46. }
     
  2. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,383
    495
    digitalpin3==digitalpin3

    You said you are using 2 pins. Then you say you are using one pin, digitalpin3. Make up your mind.
     
  3. neo1111

    Thread Starter New Member

    Jan 11, 2014
    28
    1
    I gave an axample: of course i'm supposed to use 2 digitalpins (digitalpin3 &digitalpin4).3-for temp/ and 4-humidity
     
  4. neo1111

    Thread Starter New Member

    Jan 11, 2014
    28
    1
    This condition is ok?
    Code (Text):
    1. if (isnan(t) > 40) {
    2.   digitalWrite(2,LOW);}
    3.   else {
    4.     digitalWrite(2,HIGH);
    5.   }
    6.  
    7. if (isnan(h) > 90) {
    8. digitalWrite(3,LOW);}
    9.    else {
    10.      digitalWrite(3,HIGH);
    11.    }}
    I must have "0" logic on pin 2 when the temperature is over 40 and also "0" on pin3 when the humidity is over 90% ; else , they must be "1".
    I need " 0" because when i give 0V to a different pin - it will turn on a 7 digit segment .
     
Loading...