Pages: [1]   Go Down
Author Topic: problem with comparators  (Read 413 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, im making a code with the dht11 sensor, lcd to see the data and comparators with the humidity and temperature. My goal is to reach some basic comparation like if the humidity is lower than 50% then turn on a led and if is higher than 70% turn on another lead. I want to mix the codes

this is the lcd + dht11
Code:
#include <LiquidCrystal.h>
#include <<span class="domtooltips">dht11<span class="domtooltips_tooltip" style="display: none">DHT11/22 is a digital Temperature & Humidity Sensor</span></span>.h>
 
<span class="domtooltips">dht11<span class="domtooltips_tooltip" style="display: none">DHT11/22 is a digital Temperature & Humidity Sensor</span></span> <span class="domtooltips">DHT11<span class="domtooltips_tooltip" style="display: none">DHT11/22 is a digital Temperature & Humidity Sensor</span></span>;
 
#define DHT11PIN 6
double DPC;
 
// initialize the library with the numbers of the interface pins
 
LiquidCrystal lcd(12, 11, 2, 3, 5, 4);
 
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
 
Serial.begin(9600);
Serial.println("<span class="domtooltips">DHT11<span class="domtooltips_tooltip" style="display: none">DHT11/22 is a digital Temperature & Humidity Sensor</span></span> TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT11LIB_VERSION);
}
 
void loop() {
 
int chk = <span class="domtooltips">DHT11<span class="domtooltips_tooltip" style="display: none">DHT11/22 is a digital Temperature & Humidity Sensor</span></span>.read(DHT11PIN);
 
Serial.print("Read sensor: ");
switch (chk)
{
case 0: Serial.println("OK"); break;
case -1: Serial.println("Checksum error"); break;
case -2: Serial.println("Time out error"); break;
default: Serial.println("Unknown error"); break;
}
 
Serial.print("Humidity (%): ");
Serial.println((float)<span class="domtooltips">DHT11<span class="domtooltips_tooltip" style="display: none">DHT11/22 is a digital Temperature & Humidity Sensor</span></span>.humidity, DEC);
 
Serial.print("Temperature ( C): ");
Serial.println((float)<span class="domtooltips">DHT11<span class="domtooltips_tooltip" style="display: none">DHT11/22 is a digital Temperature & Humidity Sensor</span></span>.temperature, DEC);
 
Serial.print("Temperature ( F): ");
Serial.println(<span class="domtooltips">DHT11<span class="domtooltips_tooltip" style="display: none">DHT11/22 is a digital Temperature & Humidity Sensor</span></span>.fahrenheit(), DEC);
 
lcd.setCursor(0, 0);
lcd.print("H%:");
lcd.print(<span class="domtooltips">DHT11<span class="domtooltips_tooltip" style="display: none">DHT11/22 is a digital Temperature & Humidity Sensor</span></span>.humidity, DEC);
lcd.print(" F:");
printDouble((<span class="domtooltips">DHT11<span class="domtooltips_tooltip" style="display: none">DHT11/22 is a digital Temperature & Humidity Sensor</span></span>.fahrenheit()),100);
 
lcd.setCursor(0, 1);
DPC= <span class="domtooltips">DHT11<span class="domtooltips_tooltip" style="display: none">DHT11/22 is a digital Temperature & Humidity Sensor</span></span>.dewPoint();
 
Serial.print("Dew Point ( F): ");
Serial.println((DPC * 1.8) + 32);
Serial.println(DPC);
lcd.print("DP(F): ");
//lcd.print((1.8 * (<span class="domtooltips">DHT11<span class="domtooltips_tooltip" style="display: none">DHT11/22 is a digital Temperature & Humidity Sensor</span></span>.dewPoint(), DEC) + 32));
lcd.print((DPC * 1.8) + 32);
 
Serial.print("Dew Point ( C): ");
Serial.println(<span class="domtooltips">DHT11<span class="domtooltips_tooltip" style="display: none">DHT11/22 is a digital Temperature & Humidity Sensor</span></span>.dewPoint(), DEC);
 
Serial.print("Dew PointFast ( C): ");
Serial.println(<span class="domtooltips">DHT11<span class="domtooltips_tooltip" style="display: none">DHT11/22 is a digital Temperature & Humidity Sensor</span></span>.dewPointFast(), DEC);
 
delay(10000);
 
}
 
void printDouble( double val, unsigned int precision){
// prints val with number of decimal places determine by precision
// NOTE: precision is 1 followed by the number of zeros for the desired number of decimial places
// example: printDouble( 3.1415, 100); // prints 3.14 (two decimal places)
 
Serial.print (int(val)); //prints the int part
Serial.print("."); // print the decimal point
unsigned int frac;
if(val >= 0)
frac = (val - int(val)) * precision;
else
frac = (int(val)- val ) * precision;
 
Serial.println(frac,DEC) ;
lcd.print(val);
lcd.print(frac,DEC) ;
}

and i need some advice with calling the analog value to make the humidity comparator
Code:
if(valor.analogo<50) {
          digitalWrite(PIN3,HIGH);
          delay(500);
          digitalWrite(PIN3,LOW);
          if(valor.analogo>70) {
                  
             digitalWrite(PIN2,HIGH);
             delay(500);
             digitalWrite(PIN2,LOW);
          }
        }
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#include <<span class="domtooltips">dht11<span class="domtooltips_tooltip" style="display: none">DHT11/22 is a digital Temperature & Humidity Sensor</span></span>.h>
Does your include statement REALLY look like that?

Do not use the Copy For Forum option to post code.
Logged

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11718
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if(valor.analogo<50) {
          digitalWrite(PIN3,HIGH);
          delay(500);
          digitalWrite(PIN3,LOW);
          if(valor.analogo>70) {
                   
             digitalWrite(PIN2,HIGH);
             delay(500);
             digitalWrite(PIN2,LOW);
          }
        }

Clearly that's nonsense as if valor.analogo is < 50 it can't also be > 70.

You need to read the value from the pin every time you are going to test it: use  analogRead() directly.
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: