Emmett
Published

Automated single-room Humidifier

This project interfaces with existing humidifier technology to effortlessly restore the optimal humidity level of a room.

IntermediateShowcase (no instructions)88
Automated single-room Humidifier

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
DFRobot SHT-31 Humidity & temperature Sensor
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Tactile Switch, SMD
Tactile Switch, SMD
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Servo Attachment

Image

Image

Image

Code

AutomatedHumidity

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <adafruit-sht31.h>

// Include Particle Device OS APIs
SerialLogHandler logHandler(LOG_LEVEL_INFO);


#include "Particle.h"

SYSTEM_MODE(AUTOMATIC);



Adafruit_SHT31 sht31 = Adafruit_SHT31();

Servo servo1;
bool isOn = false;
int servoPin = D16;  
int setDefault = D2; 
int set = D3;
bool pressingSet = false;
bool pressingDefault = false;
int target = 65;
bool functionRunning = false;
void setup() {
    servo1.attach(servoPin);
    servo1.write(30); 
    pinMode(set, INPUT_PULLUP);
    pinMode(setDefault, INPUT_PULLUP);
    Serial.begin(9600);
    if(! sht31.begin(0x44)){
        Serial.println("Couldnt find SHT31");
    }
}
void loop() {
    
    if(functionRunning == false){
        checkVal();
    }
    if(digitalRead(set) == LOW && pressingSet == false){
        Serial.println("Button Pressed");
        setBase();
        pressingSet = true;
    }
    if(digitalRead(set) == HIGH){
        pressingSet = false; 
    }
    if(digitalRead(setDefault) == LOW && pressingDefault == false){
        setDefaultValue();
        pressingDefault = true;
    }
    if(digitalRead(setDefault) == HIGH){
        pressingDefault = false;
    }
    delay(10);
}

void setDefaultValue(){
    target = 65;
    Serial.println("Target reset to default");
}

void checkVal(){
    float val = sht31.readHumidity();

    if (!isnan(val)) {
        Serial.print("Humidity: ");
        Serial.print(val);
        Serial.println(" %");
    } else {
        Serial.println("Failed to read humidity");
    }
    
    functionRunning = true;
    if(val<target-5 && isOn == false){
        lowValReached();
    }
    if(val>target+5 && isOn == true){
        targetValReached();
    }
    delay(3800); //how often the function checks for the humidity
    functionRunning = false;
}

void setBase(){
    target = sht31.readHumidity();
    Serial.println("Target set to current humidity");
}
void lowValReached(){
    functionRunning = true;
    servo1.write(55);   // Rotate to 30 degrees
    delay(1200);          
    servo1.write(30);    // Return to 0 degrees
    isOn = true;
    Serial.println("Minimum value reached, turned on");
    functionRunning = false;
}
void targetValReached(){
    functionRunning = true;
    servo1.write(55);   // Rotate to 30 degrees
    delay(1200);          
    servo1.write(30);    // Return to 0 degrees
    delay(1200);   
    servo1.write(55);   // Rotate to 30 degrees
    delay(1200);          
    servo1.write(30);    // Return to 0 degrees
    isOn = false;
    Serial.println("Target value reached, turned off");
    functionRunning = false;
}

Credits

Emmett
1 project • 0 followers

Comments