Go Down

Topic: problema en comparacion con valores analogos (Read 503 times) previous topic - next topic

eclipsear

estoy haciendo un codigo que involucre el sensor dht11, lcd para visualizar los valores y una comparacion en la humedad y temperatura pero tengo problemas con la comparacion a la hora de leer los datos. Por ejemplo que a menor que 50% de humedad haya una salida de un led o mayor que 70% la salida de otro led. No logro visualizar la union de los dos

Codigo dht11 en F + lcd
Code: [Select]
#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) ;
}


y en la comparacion necesito llamar a la variable analoga y compararla
Code: [Select]
if(valor.analogo<50) {
         digitalWrite(PIN3,HIGH);
         delay(500);
         digitalWrite(PIN3,LOW);
         if(valor.analogo>70) {
                 
            digitalWrite(PIN2,HIGH);
            delay(500);
            digitalWrite(PIN2,LOW);
         }
       }

Go Up