#include <Arduino.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
LiquidCrystal_I2C lcd(0x27, 2, 16);

int Dmpin = A0;

#define DHTPIN 5
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE, 15);
/* Connect HC-05 TX to Arduino RX and HC-05 RX to Arduino TX */
SoftwareSerial Bluetooth(2, 3); /* RX, TX */

void setup()
{  
  Serial.begin(9600);
  Serial.println("Arduino is ready");
 
  Bluetooth.begin(9600);  
  Serial.println("Bluetooth is ready");
  delay(50);

  dht.begin();

  lcd.begin();
  float hum = dht.readHumidity();
  float temp = dht.readTemperature();
  lcd.setCursor(6, 0);
  lcd.print("t/v:");
  lcd.setCursor(10, 0);
  lcd.print(temp);
  lcd.setCursor(12, 0);
  lcd.setCursor(10, 1);
  lcd.print(hum);
  delay(100);

}

void loop(){
  int DmValue = analogRead(Dmpin);
  int Dm = map(DmValue, 0, 750, 100, 0);
  int hum = dht.readHumidity();
  int temp = dht.readTemperature();
  if(Bluetooth.available())
  {  
    char c = Bluetooth.read();
    if(c == '1')
    {
       Bluetooth.print(Dm);
       Serial.println(Dm);
       delay(300);
    }
    if(c == '3')
    {
       Bluetooth.print(hum); 
       Serial.println(hum);
       delay(300);
             
    }
    if(c == '2')
    {
       Bluetooth.print(temp);
       Serial.println(temp);
       delay(300);         
    }
      /// Bluetooth.println(Serial.read());          
    }

  lcd.setCursor(0, 0);
  lcd.print("Dm:");
  lcd.setCursor(3, 0);
  lcd.print(Dm);
  if (Dm < 20) {
    digitalWrite(2, HIGH);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    lcd.setCursor(0, 1);
    lcd.print("  1 ");
  }
  if ((Dm > 20) && (Dm < 50)) {
    digitalWrite(2, LOW);
    digitalWrite(3, HIGH);
    digitalWrite(4, LOW);
    lcd.setCursor(0, 1);
    lcd.print("  2 ");
  }
  if (Dm > 50) {
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, HIGH);
    lcd.setCursor(0, 1);
    lcd.print("  3 ");
  }
  }
