HELP ME!

Hi I was just got my DHT 11 sensor and wants to make project with arduino, DHT11, buzzer, LCD and RGB led.

I've write this code : -

// including the LCD library
#include <LiquidCrystal.h>

// including the DHT library
#include "DHT.h"






// Naming the componets and defining there pins on arduino
#define buzzer 13

#define red A3

#define green A4

#define blue A5

#define on 6

#define of 7


// initializing the LCD library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


// initializing the DHT11 library with the various arguments
#define DHTPIN 8     // digital pin is connected to

#define DHTTYPE DHT11   // DHT 11

DHT dht(DHTPIN, DHTTYPE);

long t = 240000;
boolean x = false;



void setup() {
  // seting up the DHT sensor
  dht.begin();

  analogWrite(red, 0);
  analogWrite(green, 0);
  analogWrite(blue, 0);


  // seting up the LCD's number of columns and rows
  lcd.begin(16, 2);


  // Printing the welcome message to the LCD
  lcd.print("hello, world!");


  // telling the work of its connected components
  pinMode(buzzer, OUTPUT);
  pinMode (red, OUTPUT);
  pinMode (green, OUTPUT);
  pinMode (blue, OUTPUT);
  pinMode (on , INPUT);
  pinMode (of , INPUT);


  tone(buzzer, 80);
  tone(buzzer, 300);
  tone(buzzer, 500);
  tone(buzzer, 800);
  tone(buzzer, 1000);
  tone(buzzer, 100);
  tone(buzzer, 50);
  digitalWrite (buzzer, LOW);

  lcd.clear();
}



void loop() {

  analogWrite(red, 0);
  analogWrite(green, 255);
  analogWrite(blue, 0);

  if (digitalRead(on) == HIGH) {
    x == true;
  }

  if (digitalRead(of) == HIGH) {
    x == false;
  }

  if (x == true)
  {
    // Reading temperature or humidity
    float h = dht.readHumidity();
    // Read temperature as Celsius (the default)
    float t = dht.readTemperature();

    // Check if any reads failed and exit early (to try again).
    if (isnan(h) || isnan(t)) {
      Serial.println("Failed to read from DHT sensor!");
      lcd.println("Failed to read from DHT sensor!");
      analogWrite(red, 255);
      analogWrite(green, 0);
      analogWrite(blue, 0);
      tone(buzzer, 80);

      return;

    }

    // Compute heat index in Celsius (isFahreheit = false)
    float hic = dht.computeHeatIndex(t, h, false);

    Serial.print("Humidity: ");
    Serial.print(h);
    lcd.print("Humidity: ");
    lcd.print(h);
    lcd.println(" %");
    Serial.print(" %\t");

    Serial.print("Temperature: ");
    Serial.print(t);
    lcd.print("Temperature: ");
    lcd.print(t);
    lcd.print(" ^C");
    Serial.print(" ^C ");
    Serial.print(" %\t");

    Serial.print("Heat index: ");
    Serial.print(hic);
    Serial.print(" ^C ");
    lcd.print("Heat index: ");
    lcd.print(hic);
    lcd.print(" ^C ");

    if (t <= 10) {
      analogWrite(red, 255);
      analogWrite(green, 255);
      analogWrite(blue, 255);
    }
    else if ((t > 10) && (t < 18)) {
      analogWrite(red, 255);
      analogWrite(green, 0);
      analogWrite(blue, 255);
    }

    else if ((t > 18) && (t < 22)) {
      analogWrite(red, 0);
      analogWrite(green, 255);
      analogWrite(blue, 255);
    }
    else if ((t > 22) && (t < 38)) {
      analogWrite(red, 255);
      analogWrite(green, 255);
      analogWrite(blue, 0);
    }
    else {
      analogWrite(red, 0);
      analogWrite(green, 0);
      analogWrite(blue, 255);
      tone(buzzer, 90);
      delay(5000);
    }
    digitalWrite (buzzer, LOW);
    delay(t);

  }

  else {
    lcd.print("Please Power off");
    lcd.print("  if I'm done  ");
  }
}

Please tell me will it'll work?

Why don't you try it and tell us?

Because IDE says there is no problem in code but when I see to serial monitor, LCD and led. It didn't work as I expected.

If you let us know what it did wrong, you'll get better advice. e.g. what did you expect it to do, and what did it actually do?

I notice you've got your =='s mixed up with your ='s in a couple of places, by the way.

You have no Serial.begin.

Could that be one of your issues?

Actually I want to make a project which will show temp., humidity and heat index with RGB as indicator of temp. when I press a button and turn off when I press another button. I also wanted to the welcome beeb and alert beeb at some cases.

So, before you wrote this all-singing, all-dancing version, you had a test program that just output messages to the serial monitor.
How did that go?

TheMemberFormerlyKnownAsAWOL:
So, before you wrote this all-singing, all-dancing version, you had a test program that just output messages to the serial monitor.
How did that go?

I've tested the all components whth different codes and all go well but when I combined them in one code it didn't work as I expected.

So, have you put back the Serial.begin, and did it make a difference?

new_guy:
I've tested the all components whth different codes and all go well but when I combined them in one code it didn't work as I expected.

Did you integrate them one at a time into your combined code, or did you try to do it all in one shot?

If you did it one at a time, you should know what addition caused the problem.

If you tried to do it all at one time, that's a recipe for failure.

It should be pointed-out that A3, A4, and A5 are not PWM pins.

I have tried all the things but it didn't. Please rewrite my code and test it (if you have necessary components) for me as I was only 10 years old boy and I live in hostel so I didn't have any elders' support.

If you post your corrected code, maybe we can comment on that.

Allow me 30 min. as I'm returning to my room.

In the mean time please try to find the error and post your corrected code. I can Give you 1 more day to test it.

// including the LCD library
#include <LiquidCrystal.h>

// including the DHT library
#include "DHT.h"






// Naming the componets and defining there pins on arduino
#define buzzer 13

#define red A3

#define green A4

#define blue A5

#define on 6

#define of 7


// initializing the LCD library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


// initializing the DHT11 library with the various arguments
#define DHTPIN 8     // digital pin is connected to

#define DHTTYPE DHT11   // DHT 11

DHT dht(DHTPIN, DHTTYPE);

long t = 240000;
boolean x = true;



void setup() {
  Serial.begin(9600);

  // seting up the DHT sensor
  dht.begin();

  analogWrite(red, 0);
  analogWrite(green, 0);
  analogWrite(blue, 0);


  // seting up the LCD's number of columns and rows
  lcd.begin(16, 2);


  // Printing the welcome message to the LCD
  lcd.print("hello, world!");


  // telling the work of its connected components
  pinMode(buzzer, OUTPUT);
  pinMode (red, OUTPUT);
  pinMode (green, OUTPUT);
  pinMode (blue, OUTPUT);
  pinMode (on , INPUT);
  pinMode (of , INPUT);


  tone(buzzer, 80);
  tone(buzzer, 300);
  tone(buzzer, 500);
  tone(buzzer, 800);
  tone(buzzer, 1000);
  tone(buzzer, 100);
  tone(buzzer, 50);
  digitalWrite (buzzer, LOW);

  lcd.clear();
}



void loop() {

  analogWrite(red, 0);
  analogWrite(green, 255);
  analogWrite(blue, 0);

  if (digitalRead(on) == HIGH) {
    x = true;
  }

  if (digitalRead(of) == HIGH) {
    x = false;
  }

  if (x == true)
  {
    // Reading temperature or humidity
    float h = dht.readHumidity();
    // Read temperature as Celsius (the default)
    float t = dht.readTemperature();

    // Check if any reads failed and exit early (to try again).
    if (isnan(h) || isnan(t)) {
      Serial.println("Failed to read from DHT sensor!");
      lcd.println("Failed to read from DHT sensor!");
      analogWrite(red, 255);
      analogWrite(green, 0);
      analogWrite(blue, 0);
      tone(buzzer, 80);
      lcd.clear();

      return;

    }

    // Compute heat index in Celsius (isFahreheit = false)
    float hic = dht.computeHeatIndex(t, h, false);

    Serial.print("Humidity: ");
    Serial.print(h);
    lcd.print("Humidity: ");
    lcd.print(h);
    lcd.println(" %");
    Serial.print(" %\t");
   lcd.setCursor(1, 0);
    Serial.print("Temperature: ");
    Serial.print(t);
    lcd.print("Temperature: ");
    lcd.print(t);
    lcd.print(" ^C");
    Serial.print(" ^C ");
    Serial.print(" %\t");
    delay (4800);
    lcd.clear();
    Serial.print("Heat index: ");
    Serial.print(hic);
    Serial.print(" ^C ");
    lcd.print("Heat index: ");
    lcd.print(hic);
    lcd.print(" ^C ");

    if (t <= 10) {
      analogWrite(red, 255);
      analogWrite(green, 255);
      analogWrite(blue, 255);
    }
    else if ((t > 10) && (t < 18)) {
      analogWrite(red, 255);
      analogWrite(green, 0);
      analogWrite(blue, 255);
    }

    else if ((t > 18) && (t < 22)) {
      analogWrite(red, 0);
      analogWrite(green, 255);
      analogWrite(blue, 255);
    }
    else if ((t > 22) && (t < 38)) {
      analogWrite(red, 255);
      analogWrite(green, 255);
      analogWrite(blue, 0);
    }
    else {
      analogWrite(red, 0);
      analogWrite(green, 0);
      analogWrite(blue, 255);
      tone(buzzer, 90);
      delay(5000);
    }
    digitalWrite (buzzer, LOW);
    delay(t);
    lcd.clear();

  }

  else {
    lcd.print("Please Power off");
    lcd.setCursor(1,0);
    lcd.print("  if I'm done  ");
  }
}

You're still doing analogWrite to non-PWM pins.
With the values you're using, it'll work, but one day, it'll not do what you want/expect, so stop doing it now, and use digitalWrite.

How are the on and of pins wired ?
Are they connected to anything when the button is not pressed ?