EZP-Temperature-Humidity-4-1
Jump to navigation
Jump to search
/* YourSmartDuino-EM EZP-TEMPERATURE-HUMIDITY - WHAT IT DOES: Measures and displays Temperature and Humidity - Changes from C to F with a switch - Uses the KEYES Easy-Plug Modules - V3. 2/13/2019 Questions: terry@yourduino.com - SEE the comments after "//" on each line below - CONNECTIONS: KEYES Easy-Plug Control Board V2.0 NOTE: Different Software examples use a different sets of modules. /*-----( Import needed libraries )-----*/ // Get the LCD I2C Library here: // https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads // Move any other LCD libraries to another folder or delete them // See Library "Docs" folder for possible commands etc. #include <LiquidCrystal_I2C.h> #include <dhtnew.h> // DHT11 Temperature-Humidity Sensor // [Rob Tillaart's new version: It finds out what module is being used /*----------------( Declare Constants and Pin Numbers )-------------------*/ #define LED_MODULE_PIN 6 #define BUZZER_PIN 7 #define ONBOARD_LED_PIN 13 //----( DIGITAL INPUT Pins)---- #define SWITCH_PIN A3 // Used for a variety of On-OFF Devices #define DHT11_PIN 8 // Temperature/Humidity Sensor //------( LOCAL DEFINITIONS )--------- #define ON 1 #define OFF 0 /*--------------------( Declare objects )-------------------------*/ LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Define the LCD Display DHTNEW Temp_Humid_Sensor(DHT11_PIN); // Define the DHT11 Temperature / humidity sensor /*------------------------( Declare Variables )-----------------------------------*/ float temperatureC; float temperatureF; float humidityPercent; boolean TempIsC = true; // For switching between C and F void setup() /******************* SETUP: RUNS ONCE *************************/ { Serial.begin(115200); // Start up the Serial Monitor lcd.begin(16, 2); // initialize the lcd for 16 chars 2 lines, turn on backlight lcd.noBacklight(); delay(500); lcd.backlight(); // finish with backlight on lcd.setCursor(0, 0); //Start at character 0 on line 0 lcd.print(F("YourSmart!Duino")); lcd.setCursor(0, 1); //Start at character 0 on line 0 lcd.print(F("YourDuino.com")); // pinMode(LED_MODULE_PIN, OUTPUT); pinMode(ONBOARD_LED_PIN, OUTPUT); pinMode(BUZZER_PIN, OUTPUT); pinMode(SWITCH_PIN, INPUT_PULLUP); Serial.println("Option 4: Temperature / Humidity"); lcd.setCursor(0, 0); //Start at character 0 on line 0 //-----------1234567890123456---------- lcd.print(F("4: Temp-Humidity")); lcd.setCursor(0, 1); //Start at character 0 on line 1 lcd.print(F("DHT11 Sensor ")); delay(2000); }//--(end setup )--- void loop() /********************** LOOP: RUNS CONSTANTLY ************************/ { /*-------------( Option 4 )--------------- User connects: switch to A3 DHT11 Temperature/Humidity sensor to D8 LCD display to I2C */ Temp_Humid_Sensor.read(); delay(1000); lcd.setCursor(0, 0); //Start at character 0 on line 0 lcd.print("Humidity = "); humidityPercent = Temp_Humid_Sensor.humidity; lcd.print(humidityPercent, 0); lcd.print("%"); if (digitalRead(SWITCH_PIN ) == OFF) //Active pushbutton TempIsC = true; else TempIsC = false; if (TempIsC == true) { lcd.setCursor(0, 1); //Start at character 0 on line 1 lcd.print("Temperature= "); temperatureC = Temp_Humid_Sensor.temperature; lcd.print(temperatureC, 0); lcd.print("C"); } else { lcd.setCursor(0, 1); //Start at character 0 on line 1 lcd.print("Temperature= "); temperatureC = Temp_Humid_Sensor.temperature; temperatureF = (temperatureC * (9.0 / 5.0)) + 32.0; lcd.print(temperatureF, 0); lcd.print("F"); } }//--(end main loop )--- /*--------------------( Declare User-written Functions )------------------------*/ //NONE //*********( THE END )***********