Go Down

Topic: Simple CODE problem please help me guys :( (Read 924 times) previous topic - next topic

alialsaffar

Jun 26, 2016, 02:18 am Last Edit: Jun 26, 2016, 02:23 am by alialsaffar
i made a simple temperature sensor device using an lcd and dht11 and offcourse  arduino uno

please tell me why when i press the button and when it's HIGH it show the error message please help me


Code: [Select]
#include <LiquidCrystal.h>

#include <SimpleDHT.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// for DHT11,
//      VCC: 5V or 3V
//      GND: GND
//      DATA: 2
int pinDHT11 = 8;
SimpleDHT11 dht11;
int buttonState = 0;
int buttonPin = 7;
void setup() {
  Serial.begin(115200);
  pinMode(buttonPin, INPUT);
  lcd.begin(16, 2); lcd.home(); lcd.print("Loading...");
  delay(2000); lcd.clear();
 
}

void loop() {
  // start working...
  // this is fir keyboard typing
if (Serial.available()) {
    // wait a bit for the entire message to arrive
    delay(100);
    // clear the screen
    lcd.clear();
    // read all the available characters
    while (Serial.available() > 0) {
      // display each character to the LCD
      lcd.write(Serial.read()); delay(100);
    } delay(3000);}
    // keyboard typing finished
    ////////////////////////
    else {
  Serial.println("=================================");
  Serial.println("Sample DHT11...");

  // read without samples.
  byte temperature = 0;
  byte humidity = 0;
  if (dht11.read(pinDHT11, &temperature, &humidity, NULL)) {
    lcd.begin(16, 2);  lcd.print("Error, Check it Plz");//put autoscroll
    Serial.print("Read DHT11 failed.");
    delay(1000); lcd.clear(); return;
  }

  Serial.print("Sample OK:  " );
  Serial.print((int)temperature); Serial.print(" *C, ");
  Serial.print((int)humidity); Serial.println(" %");
  // read button state
buttonState = digitalRead(buttonPin);
// condition

if (buttonState == HIGH) {
  lcd.clear();
  lcd.setCursor(0, 0);
   lcd.print("Temperature = "); lcd.print(temperature );
} else {
 
   lcd.setCursor(0, 0);
  lcd.print("Humidity = "); lcd.print(humidity );

 
   lcd.setCursor(0, 1);
  lcd.print("Created By Ali");
  delay(1000);  }
 
  } }

ieee488



please tell me why when i press the button and when it's HIGH it show the error message please help me


What error message?

alialsaffar

If look through the code there is an error message that pops if there isn't humidity & temperature reading it also pops when i press the button,

aarg

Have you tried the DHT11 with the example sketch that comes with the DHT library?
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

alialsaffar

The code works fine without the if conditions but when i add the if condition it mess up

UKHeliBob

Code: [Select]
dht11.read(pinDHT11, &temperature, &humidity, NULL)Does this return true if a successful reading was taken ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

nickgammon

Code: [Select]
lcd.begin(16, 2);  lcd.print("Error, Check it Plz");//put autoscroll
    Serial.print("Read DHT11 failed.");
    delay(1000); lcd.clear(); return;


Can you please put one statement per line? This is incredibly hard to read.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

aarg

The code works fine without the if conditions but when i add the if condition it mess up
Which if condition? There are several.
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

Go Up