Devices & Components
Arduino Uno Rev3
Thermoelectric Peltier Cooler
MOSFET Transistor, Switching
Thermistor, 100 K
Ultrasonic Nebuliser / Mist Maker / Fogger
Through Hole Resistor, 150 ohm
Jumper wires (generic)
AC/DC Power Supply, 12 V
MOSFET High Power 210A
DC/DC Transformer, 12-24V, 1A
DHT22 Temperature Sensor
0.96" OLED 64x128 Display Module
Heated Bed for 3D Printing
5 mm LED: Green
Rotary Encoder with Push-Button
5 mm LED: Red
Wire, Wrapping Wire
Breadboard (generic)
Resistor 100 ohm
Software & Tools
Arduino IDE
Project description
Code
Code Humidity
arduino
This is our code used to handle the switching of the nebulisers in order to maintain stable humidity conditions at a desired level.
1// load libraries 2#include "DHT.h" 3#include "U8glib.h" 4U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0); 5 6//set Pin for T/RH Sensor and specify type, give character string for output 7#define DHTPIN 2 8#define DHTTYPE DHT22 9DHT dht(DHTPIN, DHTTYPE); 10char str [10]; 11 12//Hardware Pins 13const int Fog = 3; //nebulisers 14const int Fan = 6; //CPU Fans for air circulation 15const int OK = 7; //rotary encoder push 16const int CCW = 8; //rotary encoder counterclockwise 17const int CW = 9; //rotary encoder clockwise 18 19//Global Variables 20int ack = 0; 21int RH_set = 35; //start value for setting 22int SET = 0; 23int Direction = 0; 24boolean T_condition = true; 25boolean RH_condition = true; 26long previousMillis = 0; 27long interval = 2000; 28 29void setup() 30{ 31 pinMode(Fog, OUTPUT); 32 pinMode(Fan, OUTPUT); 33 pinMode(OK, OUTPUT); 34 pinMode(CCW, OUTPUT); 35 pinMode(CW, OUTPUT); 36 37 digitalWrite(Fog, LOW); 38 digitalWrite(OK, HIGH); 39 digitalWrite(CCW, HIGH); 40 digitalWrite(CW, HIGH); 41 42 Serial.begin(9600); 43 dht.begin(); 44 45 // show start page on OLED display; delay for 1.5s 46 u8g.firstPage(); 47 do 48 { 49 u8g.setFont(u8g_font_helvB14); 50 u8g.drawStr(10, 20, "Climate"); 51 u8g.drawStr(10, 40, "Chamber"); 52 } while (u8g.nextPage()); 53 54 delay(1500); 55} 56 57void loop() 58{ 59 if (SET == 0) 60 { 61 float T = dht.readTemperature(); 62 float RH = dht.readHumidity(); 63 64 // show setting menu on OLED display 65 u8g.firstPage(); 66 do 67 { 68 u8g.setFont(u8g_font_helvB08); 69 u8g.drawStr(10, 20, "Set Humidity:"); 70 u8g.setPrintPos(20, 40); 71 u8g.print(RH_set); 72 u8g.drawStr(40, 40, "%"); 73 } while (u8g.nextPage()); 74 delay(100); 75 76 77 while (RH_condition) 78 { 79 // +5 when encoder is rotated clockwise; set upper-limit to 100 80 if (digitalRead(CW) == LOW) 81 { 82 RH_set = RH_set + 5; 83 if (RH_set > 100) 84 { 85 RH_set = 100; 86 } 87 88 // show value changes on OLED display 89 u8g.firstPage(); 90 do 91 { 92 u8g.setFont(u8g_font_helvB08); 93 u8g.drawStr(10, 20, "Set Humidity:"); 94 u8g.setPrintPos(20, 40); 95 u8g.print(RH_set); 96 u8g.drawStr(40, 40, "%"); 97 } while (u8g.nextPage()); 98 delay(100); 99 } 100 101 // -5 when encoder is rotated counterclockwise; set lower-limit to 30 102 if (digitalRead(CCW) == LOW) 103 { 104 RH_set = RH_set - 5; 105 if (RH_set < 30) 106 { 107 RH_set = 30; 108 } 109 110 // show value changes on OLED display 111 u8g.firstPage(); 112 do 113 { 114 u8g.setFont(u8g_font_helvB08); 115 u8g.drawStr(10, 20, "Set Humidity:"); 116 u8g.setPrintPos(20, 40); 117 u8g.print(RH_set); 118 u8g.drawStr(40, 40, "%"); 119 } while (u8g.nextPage()); 120 delay(200); 121 } 122 if (digitalRead(OK) == LOW) 123 { 124 delay(100); 125 RH_condition = false; 126 } 127 } 128 129 // confirm setting to don't repeat this process 130 SET = 1; 131 } 132 133 // continously read actual conditions via the DHT22 every 2 seconds: 134 //if the difference between the current time and last time the DHT22 was read is bigger than the interval at which you want it to be read -> read DHT22 135 unsigned long currentMillis = millis(); 136 if (currentMillis - previousMillis > interval) 137 { 138 // save the last time you read the DHT22 139 previousMillis = currentMillis; 140 141 float RH = dht.readHumidity(); 142 float T = dht.readTemperature(); 143 144 // show DHT22 reading on OLED display 145 u8g.firstPage(); 146 do 147 { 148 float T = dht.readTemperature(); 149 float RH = dht.readHumidity(); 150 u8g.setFont(u8g_font_helvB08); 151 u8g.drawStr( 2, 20, "Temperature:"); 152 u8g.setPrintPos(80, 20); 153 u8g.print(T); 154 u8g.drawStr( 110, 20, "*C"); 155 u8g.drawStr( 3, 50, "Humidity:"); 156 u8g.setPrintPos(80, 50); 157 u8g.print(RH); 158 u8g.drawStr( 112, 50, "%"); 159 } while (u8g.nextPage()); 160 161 //humidity control: 162 //if humidity equal to or above set point -> nebulisers stay off 163 if (RH >= RH_set) 164 { 165 delay(3000); 166 if (RH >= RH_set) 167 { 168 digitalWrite(Fog, LOW); 169 analogWrite(Fan, 180); 170 } 171 } 172 173 //if humidity below set point -> nebulisers turn on for 2s; 174 if (RH < RH_set) 175 { 176 delay(3000); 177 if (RH < RH_set) 178 { 179 digitalWrite(Fog, HIGH); 180 analogWrite(Fan, 180); 181 delay(2000); 182 digitalWrite(Fog, LOW); 183 } 184 } 185 } 186} 187
Comments
Only logged in users can leave comments