RememberAir - helps you remember to air your room
RememberAir utilizes humidity sensor and distance sensor to help you keep your room at safe humidity levels.
Components and supplies
1
5 mm LED: Red
3
Resistor 220 ohm
1
High Brightness LED, White
1
DHT11 Temperature & Humidity Sensor (3 pins)
1
Resistor 10k ohm
1
5 mm LED: Yellow
1
LED, Blue
1
Arduino UNO
1
5 mm LED: Green
1
Ultrasonic Sensor - HC-SR04 (Generic)
Project description
Code
code draft
c_cpp
1#include <DHT.h> 2 3#define WINDOWPIN 2 4#define CONTROLLED 13 5#define DHTPIN 3 6#define DHTTYPE DHT11 7#define REDLED 10 8#define YELLOWLED 11 9#define GREENLED 12 10#define TRIPWIRETRIGGER 7 11#define TRIPWIREECHO 6 12#define ACTIONLED 8 13 14class Tripwire { 15 public: 16 Tripwire(){ 17 pinMode(TRIPWIRETRIGGER, OUTPUT); 18 pinMode(TRIPWIREECHO, INPUT); 19 }; 20 ~Tripwire(){}; 21 bool isTripped() { 22 // sample 3 times to eliminate most noise 23 bool wasTripped = 1; 24 for(int i = 0; i < 3; i++) { 25 // pulse to check obstacles 26 digitalWrite(TRIPWIRETRIGGER, HIGH); 27 delayMicroseconds(10); 28 digitalWrite(TRIPWIRETRIGGER, LOW); 29 // read to check echo time 30 unsigned long duration = pulseIn(TRIPWIREECHO, HIGH); 31// Serial.print(duration); Serial.print("\ 32"); 33 // check if wire was tripped (aka lower duration than threshold) 34 wasTripped &= duration <= tripDuration; 35 } 36 Serial.print("\ 37Tripwire tripped? "); Serial.print(wasTripped); 38 return wasTripped; 39 } 40 private: 41 unsigned long tripDuration = 3000; 42}; 43 44class Window { 45 public: 46 Window() { 47 pinMode(WINDOWPIN, INPUT); 48 } 49 ~Window(){}; 50 bool isClosed() { 51 bool state = digitalRead(WINDOWPIN); 52 for (int counter = 0; counter < stableTime; counter++) { 53 delay(1); 54 bool temp = digitalRead(WINDOWPIN); 55 if (temp != state) counter = 0; 56 state = temp; 57 } 58 if (state) { 59 Serial.print("\ 60window is closed"); 61 } else { 62 Serial.print("\ 63window is open"); 64 } 65 return state; 66 } 67 private: 68 int stableTime = 10; 69}; 70 71class LED { 72 public: 73 LED(){ 74 randomSeed(analogRead(0)); 75 }; 76 ~LED(){}; 77 void setPin(byte pin) { 78 ledPin = pin; 79 pinMode(ledPin, OUTPUT); 80 } 81 byte getPin() {return ledPin;}; 82 void setOn() { 83 isOn = 1; 84 digitalWrite(ledPin, HIGH); 85 } 86 void setOff() { 87 isOn = 0; 88 digitalWrite(ledPin, LOW); 89 } 90 void randomBlink(int duration) { 91 int counter = 0; 92 while (counter < duration) { 93 toggle(); 94 int randomTime = random(100, 1000); 95 counter += randomTime; 96 delay(randomTime); 97 } 98 setOff(); 99 } 100 void toggle() { 101// Serial.print("toggling");Serial.print(isOn); 102 if (isOn) { 103 setOff(); 104 } else { 105 setOn(); 106 } 107 } 108 private: 109 byte ledPin; 110 bool isOn = 0; 111}; 112 113LED controlLed; 114LED redLed; 115LED yellowLed; 116LED greenLed; 117LED actionLed; 118Window window; 119DHT dht(DHTPIN, DHTTYPE); 120const float upperHumidityBound = 80; 121const float lowerHumidityBound = 60; 122Tripwire wire; 123// for indicating humidity, imaginary 124LED humidityLed; 125// bool for indicting if human intervention is requiredd to remedy humidity values 126bool isActionRequired; 127 128void setup() { 129 // put your setup code here, to run once: 130 Serial.begin(9600); 131 Serial.print("setup\ 132"); 133 134 controlLed.setPin(CONTROLLED); 135 redLed.setPin(REDLED); 136 yellowLed.setPin(YELLOWLED); 137 greenLed.setPin(GREENLED); 138 actionLed.setPin(ACTIONLED); 139 window = Window(); 140 141 dht.begin(); 142} 143 144void loop() { 145 // put your main code here, to run repeatedly: 146 if (window.isClosed()) { 147 controlLed.setOff(); 148 } else { 149 controlLed.setOn(); 150 } 151 152 delay(2000); //sampling rate of DHT @0.5Hz 153 //turn off current HumidityLed 154 float humidity = dht.readHumidity(); 155 Serial.print("\ 156humidity: "); Serial.print(humidity); 157// float temperature = dht.readTemperature(); 158// Serial.print(temperature); 159 humidityLed.setOff(); 160 if (humidity >= upperHumidityBound) { 161 humidityLed = redLed; 162 if (window.isClosed()) { 163 isActionRequired = 1; 164 } else { 165 isActionRequired = 0; 166 } 167 } else if (humidity >= lowerHumidityBound) { 168 humidityLed = yellowLed; 169 } else { 170 humidityLed = greenLed; 171 if (!window.isClosed()) { 172 isActionRequired = 1; 173 } else { 174 isActionRequired = 0; 175 } 176 } 177 humidityLed.setOn(); 178 Serial.print("\ 179 Action required? ");Serial.print(isActionRequired); 180 if(wire.isTripped()&& isActionRequired) { 181 Serial.print("\ 182take Action!"); 183 actionLed.randomBlink(10000); 184 } 185 Serial.print("\ 186--------------------------------------"); 187} 188
Downloadable files
Plan
how to place your parts
Plan
Plan
how to place your parts
Plan
Comments
Only logged in users can leave comments