Help in code required for a plant sector revolutionizing project(Also im noob)

I am using the given components, use them together and providing the plants good conditions to live and provide monitoring(pls do not tell in reply that this project is better made ,I know).

Pls tell me is there a mistake in code. suggest a code where using my relay, my arduino would tell the water pump to supply water if soil moisture is low.And the lcd would display temp and humidity(and probably soil too).Using the dht sensor. Also check the description for link of other two modules (lcd and arduino wire)(I dont think wire is imp to anyone.) Also special thanks to people in forum that helped me a lot(link in description)

Links:
Lcd

arduino nano(I neither remember the link,nor found in my order history)

Same for my dht 11

Water pump

Relay 5v

Soil Moisture\

Soldering Iron

Nano cable

Special thanks to people solving problem of a begginer

My code for showing dht data on Serial monitor.

#include <dht.h>
#define dht_apin A0
dht DHT;

void setup() {
  Serial.println("Welcome to Plant Temperature reader");
  delay(1000);
}

void loop() {
  DHT.read11(dht_apin);

  Serial.printlm("Current temperature  =   ");
  Serial.print(DHT.temperature);
  Serial.println("Current temperature  =   ");
  Serial.print(DHT.humidity);
}

My code to show dht data on lcd

#include <LiquidCrystal.h>
#include <dht.h>

#define dht_apin A0
dht DHT;

const int rs =12, en = 11, d4 = 5,d5 = 4,d6 = 3,d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  Serial.begin(9600);
  delay(1000);
  Serial.println("Welcome to Plant Temperature reader");
  delay(1000);
  lcd.begin(16,2);
  delay(1000);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Temperature = ");
  lcd.setCursor(0,1);
  lcd.print("Humidity = ");
}

void loop() {
  DHT.read11(dht_apin);
  
  if(Serial.available()>0){

    lcd.setCursor(14,0);
    lcd.print(DHT.temperature);

    delay(1000);

    lcd.setCursor(14,1);
    lcd.print(DHT.temperature);
  
    delay(1000);

  }

  Serial.println("Current temperature  =   ");
  Serial.print(DHT.temperature);
  Serial.println("Current temperature  =   ");
  Serial.print(DHT.humidity);
  delay(1000);
}

Please follow the forum guidelines and post your code here, using code tags, to avoid the need to download it

In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

ok i understan lemme just do that

Sorry i cant do that!

What exactly can't you do ?

Done,Is it looking great now!(personally)

That's better

Notice how easy it is to scroll through the code and copy it for examination/testing

Now, what is it that you need help with ?

I am doing a project whos whole description along with the tools and modules.
Just want to use it as mentioned.

What have you tried so far ?

I have just created the code as everything is arriving in almost 2-3 days.But pls can you check the code for me(I have no idea)

Use this FREE simulator to test your code with your devices...

If you need help adding devices and connecting the devices... ask.

1 Like
if(Serial.available()>0)

Why does your code wait for Serial input before displaying data ?

Cause it waits for data of dht to come in serial monitor

@xfpd Ok the lcd is working but not displaying data and dht is sending digital data,and also its a dht22

Serial data will only be available() if it is input into the Serial interface. You cannot do that by using DHT.read() function

What does DHT.read() return if no data is available ?

I just want a min im sending a better code,when i do ill mention u

Hello
If you have the components then could you attach the pics of the wiring
I also think it would be a good idea to individually test the DHT code

I currently do not have components and im using the workwi mentioned above

@UKHeliBob
@xfpd
@arduinojanuary
Hey i completed code ,check it on wokwi

[plant - Wokwi ESP32, STM32, Arduino Simulator](Link to my project)

code here

#include <LiquidCrystal.h>
#include <dht.h>

#define dht_apin A0
dht DHT;

const int rs =12, en = 11, d4 = 5,d5 = 4,d6 = 3,d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  Serial.begin(9600);
  delay(1000);
  Serial.println("Welcome to Plant Temperature reader");
  delay(1000);
  lcd.begin(16,2);
  delay(1000);
  lcd.clear();
}

void loop() {
  DHT.read22(dht_apin);
  
  if(DHT.temperature>-30 && DHT.humidity>0){

    lcd.clear();

    lcd.setCursor(0,0);
    lcd.print("Temper..=");
    lcd.setCursor(0,1);
    lcd.print("Humidity=");

    lcd.setCursor(12,0);
    lcd.print(DHT.temperature);

    delay(1000);

    lcd.setCursor(12,1);
    lcd.print(DHT.humidity);
  
    delay(1000);

  }

  if(DHT.temperature<-30|| DHT.humidity== 0.0){
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("An error has");
    lcd.setCursor(0,1);
    lcd.print("occured!");
  }

  Serial.println("Current temperature=");
  Serial.println(DHT.temperature);
  Serial.println("Current Humidity=");
  Serial.println(DHT.humidity);
  delay(1000);
}

I see that your code works! Very good.

Welcome to Plant Temperature reader
Current temperature=
-0.40
Current Humidity=
54.00

But... humidity will always be above 0%

  if(DHT.temperature>-30 && DHT.humidity>0){