Issue obtaining data from MQ135 Sensor

I'm using an Esp32 devkit v1 for this program. My code is:

#include <MQ135.h>
#include <DHT.h>
#include <ThingSpeak.h>
#include <WiFi.h>

const char* ssid = "xxxxxxxxxxxxx";
const char* password = "xxxxxxxxxxx";

unsigned long channelID = 1;                
const char* writeAPIKey = "xxxxxxxxxxxxxxxx";    

WiFiClient client;

#define PIN_MQ135 12 // MQ135 Analog Input Pin
#define DHTPIN 13 // DHT Digital Input Pin
#define DHTTYPE DHT11 // DHT11 or DHT22, depends on your sensor

MQ135 mq135_sensor(PIN_MQ135);
DHT dht(DHTPIN, DHTTYPE);

float temperature, humidity; // Temp and Humid floats, will be measured by the DHT

void setup() {
  Serial.begin(9600);
     if(WiFi.status() != WL_CONNECTED){
      Serial.print("Attempting to connect");
      while(WiFi.status() != WL_CONNECTED){
        WiFi.begin(ssid, password);
        delay(5000);
      }
      Serial.println("Connected.");
  dht.begin();

}
}

void loop() {
  humidity = dht.readHumidity();
  temperature = dht.readTemperature();

  // Check if any reads failed and exit early (to try again).
  if (isnan(humidity) || isnan(temperature)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }


  float rzero = mq135_sensor.getRZero();
  float correctedRZero = mq135_sensor.getCorrectedRZero(temperature, humidity);
  float resistance = mq135_sensor.getResistance();
  float ppm = mq135_sensor.getPPM();
  float correctedPPM = mq135_sensor.getCorrectedPPM(temperature, humidity);

  Serial.print("MQ135 RZero: ");
  Serial.print(rzero);
  Serial.print("\t Corrected RZero: ");
  Serial.print(correctedRZero);
  Serial.print("\t Resistance: ");
  Serial.print(resistance);
  Serial.print("\t PPM: ");
  Serial.print(ppm);
  Serial.print("ppm");
  Serial.print("\t Corrected PPM: ");
  Serial.print(correctedPPM);
  Serial.println("ppm");

  delay(300);
}

My problem is that before adding the following line of code: WiFi.begin(ssid, password); the sensor data is displayed correctly, but after adding that line, the following messages are displayed on the monitor.

Although the DHT11 sensor value is not printed in the code, it still displays the readings normally with or without adding the aforementioned line of code.

I need to establish the WiFi connection in order to send the data to ThingSpeak. How could I solve this problem?

this is the same as Problema obteniendo datos de Sensor MQ135

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum. It will help you get the best out of the forum in the future.

Thank you.


➜ Take note that you should use English if you post in the general forum, you can use Spanish in the Spanish speaking categories which is where I moved your post (and closed it for the time being)

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