Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include "HTU21D.h"
- // initiate HTU21D //
- HTU21D myHumidity;
- // define pins for the two relays//
- int lRelay = 11;
- int hRelay = 13;
- //define the threshold values for humidity and temperature//
- int tempThresh = 38;
- int humdThresh = 60;
- //define floats for temperature and humidity//
- float humd;
- float temp;
- void setup() {
- Serial.begin(9600);
- myHumidity.begin();
- pinMode(lRelay, OUTPUT);
- pinMode(hRelay, OUTPUT);
- //start with relays off//
- digitalWrite(lRelay, LOW);
- digitalWrite(hRelay, LOW);
- }
- void loop() {
- readSensor();
- if (humd < humdThresh){
- digitalWrite(hRelay, HIGH);
- }else{
- digitalWrite(hRelay, LOW);
- }
- if (temp < tempThresh){
- digitalWrite(lRelay, HIGH);
- }else{
- digitalWrite(lRelay, LOW);
- }
- delay(10000);
- }
- //function to turn on relay for humidifier when humidity is below threshold//
- void runHumd(){
- do{
- readSensor();
- digitalWrite(hRelay, HIGH);
- delay(10000);
- }
- while(humd <=humdThresh);
- }
- //function to turn on relay for lights when temperature is below threshold//
- void runTemp(){
- do{
- readSensor();
- digitalWrite(lRelay, HIGH);
- delay(10000);
- }
- while(temp <=tempThresh);
- }
- //function for checking the sensor every 10 seconds//
- void readSensor(){
- humd = myHumidity.readHumidity();
- temp = myHumidity.readTemperature();
- Serial.print("Time:");
- Serial.print(millis());
- Serial.print(" Temperature:");
- Serial.print(temp, 1);
- Serial.print("C");
- Serial.print(" Humidity:");
- Serial.print(humd, 1);
- Serial.print("%");
- Serial.println();
- delay(10000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement