Is there a problem or something

#include <DHT.h>
#define Type DHT11 
int sensePin=8;
DHT HT (sensePin,Type);
float humidity;
float tempC;
float tempF;
int setTime=500;
int ButtC=9;
int ButtF=10;
int ButtL=11;
int LightVal;
int LightP=A0;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  HT.begin();
  delay(setTime);
  pinMode(LightP,INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  humidity=HT.readHumidity();
  tempC=HT.readTemperature();
  tempF=HT.readTemperature(true);
  LightVal=analogRead(LightP);
  if (ButtC==HIGH) {
    Serial.print("C");
    Serial.println(tempC);
  }
  if (ButtF==HIGH) {
    Serial.print("F");
    Serial.println(tempF);
  }
  if (ButtL==HIGH) {
    Serial.print("Light= ");
    Serial.println(LightVal);
  }
}

Because it keeps saying it's wrong.



Here is my format:

if (ButtC==HIGH)

ButtC is 9 so how can in be HIGH

Did you want:

if (digitalRead(ButtC)==HIGH)


There are others too . . .


Your switches are wired wrong.


Use the below format:

if(digitalRead(ButtF) == HIGH)

Thanks for the information given, I'm a beginner so I don't actually understand the stuff.

It says some strange things over here.
Code:

#include <DHT.h>
#define Type DHT11 
int sensePin=8;
DHT HT (sensePin,Type);
float humidity;
float tempC;
float tempF;
int setTime=500;
int ButtC=9;
int ButtF=10;
int ButtL=11;
int LightVal;
int LightP=A0;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  HT.begin();
  delay(setTime);
  pinMode(LightP,INPUT);
  pinMode(ButtC,INPUT_PULLUP);
  pinMode(ButtF,INPUT_PULLUP);
}

void loop() {
  // put your main code here, to run repeatedly:
  humidity=HT.readHumidity();
  tempC=HT.readTemperature();
  tempF=HT.readTemperature(true);
  LightVal=analogRead(LightP);
  if (digitalRead(ButtC)==HIGH) {
    Serial.print("C");
    Serial.println(tempC);
  }
  if (digitalRead(ButtF)==HIGH) {
    Serial.print("F");
    Serial.println(tempF);
  }
  if (digtalRead(ButtL==HIGH)) {
    Serial.print("Light= ");
    Serial.println(LightVal);
  }
}

This is my format:

Why are you opening up a new thread ?


What ?

Because it still doesn't work. :person_tipping_hand: :person_tipping_hand: :roll_eyes:

You should then carry on with the thread rather than opening up a new one.

What seems to be the problem now ?


Do you have a DH11, 21 or 22 ?


if (digitalRead(ButtC)==HIGH)
If you are looking for a switch push/close, change to:
if (digitalRead(ButtC)==LOW)

I have merged your cross-posts @albert_wu1234.

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.

Repeated cross-posting can result in a suspension from the forum.

In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

I'm using a DHT11

Spelling and syntax:
if (digitalRead(ButtL)==HIGH) {


#include <DHT.h>

#define Type DHT22

const byte LightP      = A0;

const byte sensePin    = 8;
const byte ButtC       = 9;
const byte ButtF       = 10;
const byte ButtL       = 11;

int setTime            = 500;
int LightVal;

float humidity;
float tempC;
float tempF;

DHT HT (sensePin, Type);

//********************************************************************
void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  HT.begin();
  delay(setTime);

  pinMode(ButtC, INPUT_PULLUP);
  pinMode(ButtF, INPUT_PULLUP);
  pinMode(ButtL, INPUT_PULLUP);

} //END of   setup()


//********************************************************************
void loop()
{
  // put your main code here, to run repeatedly:
  humidity = HT.readHumidity();

  tempC = HT.readTemperature();
  tempF = HT.readTemperature(true);

  LightVal = analogRead(LightP);

  //****************************
  if (digitalRead(ButtC) == LOW)
  {
    Serial.print("C ");
    Serial.println(tempC);
  }

  //****************************
  if (digitalRead(ButtF) == LOW)
  {
    Serial.print("F ");
    Serial.println(tempF);
  }

  //****************************
  if (digitalRead(ButtL) == LOW)
  {
    Serial.print("Light = ");
    Serial.println(LightVal);
  }

} //END of   loop()

There's nothing wrong with the syntax (the compiler would've bitched if there were), it's just that the semantics are wrong. :sunglasses:

1 Like

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