چند سالی است که با این کلیدهای هوشمند کولر آبی سرو کله میزنم
تصمیم گرفتم با اردینو یکی برای خودم درست کنم که جدا از کنترل دما رطوبت راهم کنترل کند و با بلوتوث موبایل هم قابل کنترل باشد
تجهیزاتی که دارم
آردینو مگا
شیلد با 5 کلید
رله 3 کاناله
سنسور دما و رطوبت DHT22
ماژول بلوتوث HC05
اطلاعات برنامه نویسی و الکترونیکی که دارم مربوط به 20 سال پیشه
ولی پروژه را تا جایی پیش بردم که در عمل کار میکند
حالا برای اصلاح و بهبود کد نویسی آن به کمک دوستان احتیاج دارم
آیا در این انجمن دوستان آشنا به کدنویسی آردینو هستند که به این پروژه علاقه داشته باشند تا در اصلاح و بهبود کد ها کمک کنند ؟
تصمیم گرفتم با اردینو یکی برای خودم درست کنم که جدا از کنترل دما رطوبت راهم کنترل کند و با بلوتوث موبایل هم قابل کنترل باشد
تجهیزاتی که دارم
آردینو مگا
شیلد با 5 کلید
رله 3 کاناله
سنسور دما و رطوبت DHT22
ماژول بلوتوث HC05
اطلاعات برنامه نویسی و الکترونیکی که دارم مربوط به 20 سال پیشه
ولی پروژه را تا جایی پیش بردم که در عمل کار میکند
حالا برای اصلاح و بهبود کد نویسی آن به کمک دوستان احتیاج دارم
آیا در این انجمن دوستان آشنا به کدنویسی آردینو هستند که به این پروژه علاقه داشته باشند تا در اصلاح و بهبود کد ها کمک کنند ؟
کد:
#include <DHT.h> //Used sample code for the DHT11 By Ladyada #include <LiquidCrystal.h> #include <DFR_Key.h> LiquidCrystal lcd(8, 9, 4, 5, 6, 7); DFR_Key keypad; // Uncomment whatever type you're using! //#define DHTTYPE DHT11 // DHT 11 #define DHTTYPE DHT22 // DHT 22 (AM2302) //#define DHTTYPE DHT21 // DHT 21 (AM2301) // Connect pin 1 (on the left) of the sensor to +5V // Connect pin 2 of the sensor to whatever your DHTPIN is // Connect pin 4 (on the right) of the sensor to GROUND // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor int sensePin = 21; //Arduino Pin number the sensor plugged into. The schematics that come with the LCD shield are incorrect. //Pin 2 on the arduino is actually pin 5 on the LCD shield. The headers that plug into the arduino's Digital pins 0 - 7, on the LCD Shield the exact middle pin is pin 2 on the arduino. //Use your multimeter to test continuity to find the pin you want. int currentButton = 0; //Current button pressed int displayTemp = 1; //Keeps track of what screen is currently being displayed. If displatTemp is 1 temp is showing. If 0 Humidity is showing. int displayHumid = 0; int setTemp = 23; //Default to set the desired temp int setHumid = 50; //Defualt to set the desired humidity int outputPin = 32; //Output pin to the relay to trip water pump control int outputPin1 = 26; //Output pin to the relay to trip cooler control on or off int outputPin2 = 28; //Output pin to the relay to trip cooler control speed low and high DHT dht(sensePin, DHTTYPE); void setup() { pinMode(outputPin, OUTPUT); pinMode(outputPin2, OUTPUT); lcd.begin(16, 2); lcd.clear(); lcd.setCursor(0, 0); //Serial.begin(9600); // it is starting delay for 10s in case of protecting cooler at start dht.begin(); lcd.setCursor(4,1); lcd.print("starttime"); delay (1000); } void loop() { // for (i=1 to 20000 step 500); currentButton = keypad.getKey(); //Read button press // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) //delay(5); float h = dht.readHumidity(); float t = dht.readTemperature(); //delay(2); if (isnan(h) || isnan(t)) { //Serial.println("Failed to read from DHT"); lcd.setCursor(9,0); lcd.print("-"); // lcd.clear(); // lcd.cursorTo(1,0); // lcd.printIn("Sensor Fail"); // lcd.cursorTo(2,0); // lcd.printIn("Check PWR & link"); } else { float temp = (t-3); //Convert *C to *F. if (displayTemp == 1) //Shows temp screen upon first boot { //lcd.clear(); lcd.setCursor(0,0); lcd.print("TEMP "); //lcd.setCursor(9,0); //lcd.print("+"); lcd.setCursor(11,0); lcd.print(temp); lcd.print(" "); lcd.print((char)223); // degree symbol lcd.print("C"); lcd.setCursor(0,1); lcd.print("SET TEMP "); lcd.print(setTemp); lcd.print(" "); lcd.print((char)223); lcd.print("c"); displayHumid = 0; } else{ //lcd.clear(); lcd.setCursor(0, 0); lcd.print("HUMIDITY "); lcd.print(int(h)); lcd.print(" %"); lcd.setCursor(0,1); lcd.print("SET HUMID "); lcd.print(setHumid); lcd.print(" %"); displayHumid = 1; } // Reads which buttons are pressed. // No button = 0 // Select button = 1 // Left button = 2 // Up Button = 3 // Down Button = 4 // Right Button = 5 if (currentButton == 5 && displayTemp == 1) { displayTemp = 0; //Turns display temp off so it will show humidity after pressing right button } // The following code toggles the screen when the corresponding button is pressed. // Also sets the screens to wrap around the display. // So if you hit right button once it will show humidity and if you hit right button again it will show temp. if (currentButton == 5 && displayHumid == 1) { displayTemp = 1; } if (currentButton == 2 && displayTemp == 1) { displayTemp = 0; } if (currentButton == 2 && displayHumid == 1) { displayTemp = 1; } if (currentButton == 3 && displayTemp == 1) //When up button is pressed and the temp screen is showing, increment the set temp { ++setTemp; } if (currentButton == 4 && displayTemp == 1) //When down button is pressed with the temp screen showing, decrement set temp { --setTemp; } if (currentButton == 3 && displayTemp == 0) //When up button is pressed and the humidity screen is showing, inc the set humidity { ++setHumid; } if (currentButton == 4 && displayTemp == 0) //When down button is pressed and humidity screen is showing, dec the set humidity { --setHumid; } if(temp >= setTemp) //Trip relay if temp is exceeded { Serial.print(temp); digitalWrite(outputPin, LOW); digitalWrite(outputPin1, LOW); digitalWrite(outputPin2, LOW); } else { digitalWrite(outputPin, HIGH); digitalWrite(outputPin1, HIGH); } //if (h >= setHumid) //If humidity is exceeded and fan is not on due to temp exceeded, turn fan on. // { // digitalWrite(outputPin, HIGH); // } //else // { // digitalWrite(outputPin, LOW); // } //if (h >= setHumid && digitalRead(outputPin) == HIGH) //If humidity is exceeded and fan is not on due to temp exceeded, turn fan on. //{ // digitalWrite(outputPin2, HIGH); //} } }
دیدگاه