Wifi begin HW-038 problem

Hello,
I measure temperature, humidity, water and air quality with esp 32 d1 r32 card and I want it to send an e-mail depending on the situation. But Wifi begin(ssid,pass); Because of the code, the water level always goes up to 100. The sensor you are using is HW-038. Can you help with the subject?

#include "ESP32_MailClient.h"
#include "MQ135.h"
#include "DHT.h"
#include <LiquidCrystal_I2C.h>

const char* ssid = "test";
const char* password = "test";
#define emailSenderAccount    "sdf@sdfsf.com"    
#define emailSenderPassword   "dgfhdh"
#define emailRecipient        "sdf.ghf@fgd.com"
#define smtpServer            "smtp.office365.com"
#define smtpServerPort        587
#define emailSubject          "IT ODASI UYARI"
#define DHTPIN 17
#define DHTTYPE DHT11
#define MQ135PIN 34
MQ135 mq135(MQ135PIN);
LiquidCrystal_I2C lcd(0x27, 16, 2);
DHT dht(DHTPIN, DHTTYPE);


SMTPData smtpData;
const int analogInPin = 14; // HW-038 sensörünü analog pine bağlayın
int sensorValue = 0;        // sensör verisi
float voltage = 0;          // sensör voltajı
float waterLevel = 0;       // su seviyesi
float minVoltage = 0.20;    // sensör minimum voltajı
float maxVoltage = 4.00;    // sensör maksimum voltajı

void sendCallback(SendStatus info);

void setup(){
  Serial.begin(9600);
  Serial.println();
  Serial.print("Connecting");

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(200);
  }

  Serial.println();
  Serial.println("WiFi connected.");
  Serial.println();
  Serial.println("Preparing to send email");
  Serial.println();

  dht.begin();
  lcd.begin();
  lcd.backlight();
  dht.begin();
  lcd.setCursor(0, 0);
  lcd.print("sdf sdf");
  delay(8000);
}

void loop() {
  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();
  int air_quality = mq135.getPPM();

  sensorValue = analogRead(analogInPin);    // analog pinden veri oku
  voltage = sensorValue * (3.3 / 4095.0);    // voltaj hesapla

  if (voltage > minVoltage) {               // minimum voltaj kontrolü
    waterLevel = 100;                       // su seviyesi 0%
  } else if (voltage < maxVoltage) {        // maksimum voltaj kontrolü
    waterLevel = 0;                         // su seviyesi 100%
  } else {
    waterLevel = 100 - (voltage - minVoltage) * 100 / (maxVoltage - minVoltage);  // su seviyesi hesapla
  }
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Sicaklik: ");
  lcd.print(temperature);
  lcd.print("C");
  lcd.setCursor(0, 1);
  lcd.print("Nem: ");
  lcd.print(humidity);
  lcd.print("%");
  delay(5000);
  lcd.clear();
  
  lcd.setCursor(0, 0);
  lcd.print("Hava:");
  lcd.print(air_quality/1000);
  lcd.print("ppm");
  lcd.setCursor(0, 1);
  lcd.print("Su seviyesi: ");
  lcd.print(waterLevel);
  lcd.print("%");
  delay(5000);
  lcd.clear();
  if(temperature > 27.0)
  {
  
   smtpData.setLogin(smtpServer, smtpServerPort, emailSenderAccount, emailSenderPassword);
   smtpData.setSender("ESP32", emailSenderAccount);
   smtpData.setPriority("High");
   smtpData.setSubject(emailSubject);
   smtpData.setMessage("<div><h1 style=\"color:red;\">Sıcaklık Uyarısı!</h1><p>Lokasyon:EKO ENDUSTRI IT ODASI</p><p>Sensör:Sıcaklık</p><p> Sıcaklık Değeri:23 °C Üzerinde </p></div>", true);
   smtpData.addRecipient(emailRecipient);
   smtpData.setSendCallback(sendCallback);
   if (!MailClient.sendMail(smtpData))
    Serial.println("Error sending Email, " + MailClient.smtpErrorReason());

  }
   smtpData.empty();
   
 
  if(humidity > 65.0)
  {
   smtpData.setLogin(smtpServer, smtpServerPort, emailSenderAccount, emailSenderPassword);
   smtpData.setSender("ESP32", emailSenderAccount);
   smtpData.setPriority("High");
   smtpData.setSubject(emailSubject);
   smtpData.setMessage("<div><h1 style=\"color:red;\">Nem Uyarısı!</h1><p>Lokasyon:EKO ENDUSTRI IT ODASI</p><p>Sensör:Nem</p><p>Nem Değeri:65(%RH) Değerinin Üzerinde</p></div>", true);
   smtpData.addRecipient(emailRecipient);
   smtpData.setSendCallback(sendCallback); 
   if (!MailClient.sendMail(smtpData))
    Serial.println("Error sending Email, " + MailClient.smtpErrorReason());

  }
   smtpData.empty();

  if(air_quality/1000 > 2500.0)
  {
   smtpData.setLogin(smtpServer, smtpServerPort, emailSenderAccount, emailSenderPassword);
   smtpData.setSender("ESP32", emailSenderAccount);
   smtpData.setPriority("High");
   smtpData.setSubject(emailSubject);
   smtpData.setMessage("<div><h1 style=\"color:red;\">Hava Kalite Uyarısı!</h1><p>Lokasyon:EKO ENDUSTRI IT ODASI</p><p>Sensör:Hava Kalitesi</p><p>Hava Kalitesi:4000 ppm  Değerinin Üzerinde</p></div>", true);
   smtpData.addRecipient(emailRecipient);
   smtpData.setSendCallback(sendCallback); 
   if (!MailClient.sendMail(smtpData))
    Serial.println("Error sending Email, " + MailClient.smtpErrorReason());

  }
   smtpData.empty();



   if(waterLevel < 99)
  {
   smtpData.setLogin(smtpServer, smtpServerPort, emailSenderAccount, emailSenderPassword);
   smtpData.setSender("ESP32", emailSenderAccount);
   smtpData.setPriority("High");
   smtpData.setSubject(emailSubject);
   smtpData.setMessage("<div><h1 style=\"color:red;\">Su Seviyesi Uyarısı!</h1><p>Lokasyon:EKO ENDUSTRI IT ODASI</p><p>Sensör:Su</p><p>Su değeri:Belirlenen Seviyenin Üzerinde</p></div>", true);
   smtpData.addRecipient(emailRecipient);
   smtpData.setSendCallback(sendCallback); 
   if (!MailClient.sendMail(smtpData))
    Serial.println("Error sending Email, " + MailClient.smtpErrorReason());

  }
   smtpData.empty();
   
  }
   
 
void sendCallback(SendStatus msg) {
    
    Serial.println(msg.info());
    float temperature = dht.readTemperature();
    float humidity = dht.readHumidity();
    int air_quality = mq135.getPPM();

    sensorValue = analogRead(analogInPin);    // analog pinden veri oku
    voltage = sensorValue * (3.3 / 4095.0);    // voltaj hesapla

   if (voltage > minVoltage) {               // minimum voltaj kontrolü
    waterLevel = 100;                       // su seviyesi 0%
    } else if (voltage < maxVoltage) {        // maksimum voltaj kontrolü
    waterLevel = 0;                         // su seviyesi 100%
    } else {
    waterLevel = 100 - (voltage - minVoltage) * 100 / (maxVoltage - minVoltage);  // su seviyesi hesapla
    }
    lcd.setCursor(0, 0);
    lcd.print("Sicaklik: ");
    lcd.print(temperature);
    lcd.print("C");
    
    lcd.setCursor(0, 1);
    lcd.print("Nem: ");
    lcd.print(humidity);
    lcd.print("%");
    delay(5000);
    lcd.clear();
  
    lcd.setCursor(0, 0);
    lcd.print("Hava:");
    lcd.print(air_quality/1000);
    lcd.print("ppm");
    lcd.setCursor(0, 1);
    lcd.print("Su seviyesi: ");
    lcd.print(waterLevel);
    lcd.print("%");
    delay(5000);
    lcd.clear();

Not sure if I understand if this is one problem or multiple problems.
1)

Can you elaborate a bit?

Your topic has been moved to a more suitable location on the forum. It does not sound like you have a problem with the IDE.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.