Image of eBits Academy airquality illustration

Troubleshooting Common Arduino IDE Problems - Air Quality Monitoring Station Series, Episode 11

  • March 18, 2025
  • |
  • Teofil Corad

Lesson objectives

The goal of this lesson is to give you the skills needed to identify and solve common problems that can arise when coding for the ESP32 and interacting with sensors. We will cover troubleshooting techniques and solutions to errors related to code, hardware connections, and library use.


Introduction

When you start programming and working with your ESP32 and sensors, it is important to be prepared for possible errors. Debugging is a critical skill that ensures your code works correctly and your hardware operates as intended.

In this lesson, we go through the most common errors and solutions so you can diagnose and solve problems quickly and efficiently.


Common problems and solutions

1. Library not found or compilation errors

Symptoms:

  • Error messages indicating that a library cannot be found.
  • Functions from a library are not defined.

Possible causes:

  • The required library is not installed.
  • The library version is not compatible with your code.

Solutions:

  • Check the library installation:
    • Go to Sketch > Include Library > Manage Libraries… in Arduino IDE and search for the required library. If it is not installed, install it via the Library Manager.
  • Verify #include statements:
    • Make sure the name in the #include directive matches the installed library. For example, if you use Adafruit AHT10, your code should include:
    #include <Adafruit_AHTX0.h>
  • Update libraries:
    • Check for updates in the Library Manager and update both boards and libraries to avoid compatibility problems.

2. Sensor does not respond or initialize

Symptoms:

  • Error messages such as "Failed to find AHT10 chip” or "No data from sensor."
  • Sensor values do not appear in the Serial Monitor.

Possible causes:

  • Incorrect or loose wiring connections.
  • Power supply problems.
  • The sensor module is not initialized correctly.

Solutions:

  • Check wiring connections:

    • Make sure all connections between the ESP32 and the sensor are correct.
    • For the AHT10 sensor, the connections should be:
      • VCC → 3.3V on the ESP32
      • GND → GND on the ESP32
      • SDA → GPIO21 (the ESP32 SDA pin)
      • SCL → GPIO22 (the ESP32 SCL pin)
  • Verify the power supply:

    • Make sure the sensor receives sufficient power. The AHT10 operates on 3.3V from the ESP32.
  • Initialization code:

    • Check that aht.begin() is called correctly in the setup() function:
    if (!aht.begin()) {
      Serial.println("Failed to find AHT10 chip");
      while (1) { delay(10); } // Stopper programmet, hvis initialisering fejler
    }

3. Incorrect or unexpected sensor values

Symptoms:

  • Sensor values are inconsistent or random.

Possible causes:

  • Incorrect sensor calibration.
  • Electrical noise/interference.
  • Logic errors in data processing.

Solutions:

  • Check the sensor calibration:

    • The AHT10 is normally precalibrated, but make sure the code does not inadvertently change the calibration data.
  • Ensure correct data handling:

    • Check that getEvent() is used correctly to read data:
    sensors_event_t humidity_event;
    sensors_event_t temp_event;
    aht_humidity->getEvent(&humidity_event);
    aht_temp->getEvent(&temp_event);
    
    Serial.print("Temperature: ");
    Serial.print(temp_event.temperature);
    Serial.println(" °C");
    
    Serial.print("Humidity: ");
    Serial.print(humidity_event.relative_humidity);
    Serial.println(" % rH");

4. Serial Monitor shows no data

Symptoms:

  • No output in the Serial Monitor.
  • The output does not match the expected data.

Possible causes:

  • Incorrect baud rate setting.
  • Serial output is not initialized.
  • The USB cable or connection is faulty.

Solutions:

  • Check the baud rate:

    • The baud rate in the Serial Monitor must match the value in Serial.begin().
    Serial.begin(115200);  // Sørg for at Serial Monitor også er sat til 115200 baud
     
    • Verify serial initialization:

      • Make sure Serial.begin() is called in setup():
      void setup() {
        Serial.begin(115200);
      }
      
  • Check cables and connections:

    • Try a different USB cable or another port, as some cables only support charging and not data transfer.

Troubleshooting tips

Use Serial.print() for debugging

  • Insert Serial.print() statements in the code to follow the execution flow and track variables.

Read error messages carefully

  • Arduino IDE often provides precise error descriptions that can help locate the problem.

Check the documentation

  • Read the sensor datasheets and library documentation to understand correct usage and troubleshooting.

 


List of required components:

 


Summary

In this lesson, you have learned about the most common problems that can arise when programming the ESP32 and using sensors. We have covered library errors, sensor initialization, incorrect readings and Serial Monitor problems.

By taking a systematic approach to debugging you can efficiently identify and solve problems so your code and hardware work optimally.

Remember: Troubleshooting is an iterative process. Do not get frustrated — every error you solve brings you closer to a successful project! 

About the measurements: The station in this series measures temperature and relative humidity using the AHT10. These are indoor climate readings, not direct measurements of CO2, VOCs, or particles. The series name “air quality monitoring” should be understood with this limitation.

Leave a comment

Please note, comments need to be approved before they are published.