Temperature open Lid

 avatar
unknown
plain_text
2 years ago
1.3 kB
4
Indexable
#include <dht.h>
#include <Servo.h>

Servo myservo;
dht DHT;

#define DHT11_PIN 7



void setup(){
  Serial.begin(9600);
  myservo.attach(9);
}

int pos = 0;
boolean calibrated = false;

boolean calibrate(boolean cal) {
  if(cal = false) {
    myservo.write(0);
    return true;
    Serial.println("Kalibracija zavrsena");
  }
  else {
    return true;
  }
  
}

void openLid() {
  while(pos < 180) { 
    myservo.write(pos);              
    delay(15);  
    pos = pos + 1;   
    Serial.print("Position = ");
    Serial.println(pos);                  
  }
}
void closeLid() {
  while(pos > 0) { 
    myservo.write(pos);              
    delay(15);  
    pos = pos - 1;
    Serial.print("Position = ");
    Serial.println(pos);                     
  }
}

void loop(){
  
  int chk = DHT.read11(DHT11_PIN);
  Serial.print("Temperature = ");
  Serial.println(DHT.temperature);
  Serial.print("Position = ");
  Serial.println(pos);



  if(calibrate(calibrated) == true) {
    Serial.println("Proso test");
    if(DHT.temperature >= 25) {
      openLid();
    }
    else if(DHT.temperature <= 24.5) {
      closeLid();
    }
  }
  else {
    calibrated = calibrate(calibrated);
  }
  
  
  delay(3000);
}

Editor is loading...