1

I am using ESP32 and SHT21 temp+humidity sensor but while compiling the code I get the following error:

variable "SHT21" is not a type name

I see an SHT21 class defined in the SHT21.cpp file in the library folder. I don't know much about classes so could you please tell what is wrong with the SHT21 class in this case?

Here is the link to the library: https://github.com/markbeee/SHT21

Sketch:

#include <Arduino.h>

#include <Wire.h>
#include "SHT21.h"

SHT21 SHT21;

void setup()
{
  SHT21.begin();
  Serial.begin(9600);
}

void loop()
{
  Serial.print("Humidity(%RH): ");
  Serial.print(SHT21.getHumidity());
  Serial.print("     Temperature(C): ");
  Serial.println(SHT21.getTemperature());
  
  delay(1000);
}
2
  • 3
    Don't name your instance the same as the class. It confuses the compiler as it never knows what you're talking about. Commented Sep 23, 2020 at 11:26
  • Ah Ok! I see it. Thanks for the tip. It compiles without error now. Commented Sep 23, 2020 at 16:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.