Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15287

If/Else statement

$
0
0

I'm obviously new. Tinkering around but have no actual experience with this.

I want pin 2 (relay) high when the temp sensor is between 1 and 55 degrees, and pin 3 (heater) high when the temp is below 5. I finally got it to compile, but when I ice the sensor heater never comes on, and when I raise the temp of the sensor it got over 65 and pin2 never dropped out.

I started by editing an example code from adafruit so I don't REALLY understand the serial portion of the code. the bit at the end is mine.

Help?

#include <Adafruit_AHTX0.h>

Adafruit_AHTX0 aht;

Adafruit_Sensor *aht_humidity, *aht_temp;

  const int Relay = A2;
  const int Heater = A3;
  int val = 0;

void setup(void) {
  pinMode(Relay,OUTPUT);
  pinMode(Heater,OUTPUT);

  Serial.begin(9600);
  while (!Serial)
    delay(10); 

  Serial.println("Adafruit AHT10/AHT20 test!");

  if (!aht.begin()) {
    Serial.println("Failed to find AHT10/AHT20 chip");
    while (1) {
      delay(10);
    }
  }

  Serial.println("AHT10/AHT20 Found!");
  aht_temp = aht.getTemperatureSensor();
  aht_temp->printSensorDetails();

  aht_humidity = aht.getHumiditySensor();
  aht_humidity->printSensorDetails();
}

void loop() {
  sensors_event_t humidity;
  sensors_event_t temp;
  aht_humidity->getEvent(&humidity);
  aht_temp->getEvent(&temp);

  Serial.print("\t\tTemperature ");
  Serial.print(temp.temperature);
  Serial.println(" deg C");

  delay(100);

  Serial.print(temp.temperature);
  Serial.print(",");

  Serial.print(humidity.relative_humidity);

  Serial.println();
  delay(10);

val=aht_temp;
  if (val<=5.0)
  {
    digitalWrite(Heater, HIGH);
  }
  else if (val>5)
  {
  digitalWrite(Heater, LOW);
  }
  
  if (1.00<=val<=55) 
  { 
  digitalWrite(Relay, HIGH);
  }
  else if (val<1.00)
  {
  digitalWrite(Relay, LOW);
  }
  else if (val>55)
  {
    digitalWrite(Relay, LOW);
  }
 
  
}


13 posts - 5 participants

Read full topic


Viewing all articles
Browse latest Browse all 15287

Trending Articles