Project tutorial
Very low power temp and humidity monitor with min and max

Very low power temp and humidity monitor with min and max © GPL3+

A very low power consumption rechargeable temperature and humidity monitor that can run off a rechargeable battery for 12 days or more.

  • 18 views
  • 0 comments
  • 0 respects

Components and supplies

About this project

I needed a temperature and humidity sensor that would show maximum and minimum levels recorded so that I could monitor the levels in my greenhouse. I do not have any power in the greenhouse so the aim was to reduce power consumption as much as possible so that it could run on a rechargeable battery for long periods.

The solution to this was to have the Arduino enter a low power state for a period before waking and taking new reading then repeating the cycle. To achieve this I used the rocketscream low power library to put the processor to sleep, waking every 24 seconds to check the temperature and humidity, which takes less than a second.

(NOTE: I have created a variation of this project Temp and Humidity Monitor with Graphs and Battery Monitor which you may also like to check out. Does not use power saving but the battery still lasts 5 days and the battery monitor lets you know when it needs recharging.)

My first version used an Ardino Nano R3 with a 16x2 backlit LCD display. This worked well and power consumption was as follows:

Asleep:                               24 seconds    5.6mA
    Checking temp./humid. between sleeps  <1 second     14mA
                                          So on average 6.0mA
    With backlight on                                   28.5mA

Using a 1, 000 mAh rechargeable battery the system should last for up to 7 days between charges – frequently turning on the backlight will obviously reduce this. In fact my version has been running for over 8 days and is still operational.

The second version used an Arduino Pro Mini with an OLED 128*64 display. The display does not need a backlight and is easier to read in bright daylight. The power consumption of this was:

Asleep:                               24 seconds    3.23mA
    Checking temp./humid. between sleeps  <1 second     6.8mA
                                          So on average 3.4mA 
    Awake - displaying

Using a 1, 000 mAh rechargeable battery the system should last for up to 12 days between charges – frequently turning on the display will reduce this, but it is low consumption so should not be noticeable.

I have included schematics and code for both versions. Either version should run on most Arduinos.

The code (OLED version)

The code uses the following libraries:

#include <DHT.h>            // This is the DHT sensor library by Adafruit
	#include "LowPower.h"       // Low-Power library from rocketscream
		  		     // required for the OLED display 
	#include <SPI.h>            // Synchronous serial data protocol library
	#include <Wire.h>           // IC2 communications library
	#include <Adafruit_GFX.h>   // Adafruit Graphics Core Library
	#include <Adafruit_SSD1306.h>  // SSD1306 library for Monochrome 128x64 and 128x32 OLEDs

And these fonts from the Adafruit Graphics Core Library:

#include <Fonts/FreeMonoBold9pt7b.h> 
	#include <Fonts/FreeSans9pt7b.h>

The main areas of interest in the code is the the loop() which puts the processor to sleep.

// Check to see if has been awake for the keepAwakeFor period
 // if so allow to go to sleep
 if ((millis() - timeWoken) > (keepAwakeFor * 1000)) {
   awake = false;
   // Sleep for 24 seconds
   for (int i = 0; i < 3; i++){
     display.clearDisplay(); 
     display.drawBitmap(random(10, 110), random(10, 48), snooze, 16, 16, WHITE);
     display.display();
     // Allow wake up pin to trigger interrupt on low.
     attachInterrupt(0, wakeUp, LOW);
     // Enter power down state with ADC and BOD module disabled.
     // Wake up when wake up pin is low or after 8 seconds.
     // If wake up button pressed then as long as button held down for more
     // than a few milliseconds it will fall through any remaining sleep loops      
     LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
     // Disable external pin interrupt on wake up pin.
     detachInterrupt(0);
   }
 }

We first check if the system has been awake for loner than the time set to remain awake after the last button was pressed. timeWoken is millis() elapsed at the point the button was pressed.

if ((millis() - timeWoken) > (keepAwakeFor * 1000))...

If this time has passed then we loop 3 times, displaying the snooze icon in a random place each time to avoid burn in and putting the processor to sleep for 8 seconds. The interrupt on pin 2 is enabled before entering sleep. If the pin goes LOW by pressing the Mode button, this will wake the processor and continue running the code. If nit in the last loop at this point, subsequent sleep loops will fall through as they will happen very quickly before the button is released.

After 3 loops, 24 seconds, the system then runs a loop 3 times to check the sensor readings and update the minimum and maximum values. (Note: Just checking once did not result in a successful reading but looping 3 times corrected this). It also checks if the processor is awake and, if it is displays the settings. The enum mode keeps track of whether the temperature or humidity is to be displayed.

Finally, if the system is awake, the buttons are checked to see if one has been pressed:

Mode button (pin 2) will toggle the display between temperature and humidity

Reset button (pin 3) will reset the value of the minimum and maximum readings

The interrupt

If the system is asleep and the Mode button is pressed then the interrupt is called:

void wakeUp()
	{
		// Handler for the pin interrupt.
		timeWoken = millis();               // Reset so remains awake for awake period
		awake = true;
		justWoken = true;
	}

This simply sets the time the system was woken, sets the awake flag and also sets justWoken which is used to default to the temperature display (in the loop()) and also to invoke a delay before the buttons are next checked.

The code (LCD 16x2 version)

The code for the LCD 16x2 display version is very similar with changes only being required for display handling and controlling the backlight.

Fewer libraries are needed:

// Include driver for the DHT
	// This is the DHT sensor library by Adafruit
	#include <DHT.h>
	// Include the library driver for display:
	#include <LiquidCrystal.h>
	// Include Low-Power library from rocketscream
	#include "LowPower.h"

In the main loop() the status if the backlight is also checked and turned off if it has been on for the period set in lightTimeOut.

// Check if need to turn backlight off
   if (lightOn && ((millis() - timeLightTurnedOn) > (lightTimeOut * 1000)))
     TurnBacklightOff();

The backlight is turned on when the mode button is pressed.

On/Off switch

If you wish to add an on/off switch insert this in the wire from the charger module OUT+ to the Arduino board. This will allow you to charge the battery with the unit switched off.

Regulating the battery charging

The TP4056 charger used includes a regulating resistor of 1.1K ohm that provides a charge at a rate of 1,000mAh. This is really too high for the 1,000mAh battery used which should be charged at a maximum of 500mAh. It is fiddly but you can remove the board mounted resistor (R3), or I find it easier to break it by scraping a knife across it as this leaves the post to solder to, and solder on an external resistor to reduce the current. Here is the table showing resistor values and current produced. (Check with a meter that you are still reading the correct resistance across the connection as it is easy to short these and this could cause damage.)

Code

Temo/Humid monitor OLED version codeArduino
/*   Paul Brace April 2021
 *   Very low power consumption temperature and humidity monitor
 *     with minimum and maximum monitoring
 *   Board - Arduino Pro Mini
 *   Display - OLED 128x64 IC2
 *   Aim was to reduce power consumption as much as possible so
 *     can be run on a rechargeable battery for long periods
 *   This is achieved by:
 *         1. Using the rocketscream low power library to put the processor 
 *            to sleep waking every 24 seconds to check the temperature and 
 *            humidity, which takes less than a second.
 *         2. Displaying a small sleep icon to reduce the number of lit pixels  
 *            The sleep icon also moves every 8 seconds to avoid screen burn-in 
 *   The mode button is used to wake the processor for a set period, display   
 *     the readings and switch between the temperature and humidity displays.
 *   The processor remains awake for the period specified in keepAwakeFor.
 *   The reset button is used to reset the minimum and maximum values
 *     when the processor has been woken by the mode button being pressed.
 *   Power consumption with the suggested components:
 *      Asleep:                               24 seconds    3.23mA
 *      Checking temp./humid. between sleeps  <1 second     6.8mA
 *                                            So on average 3.4mA                                            
 *                                          
 *   Using a 1,000 mAh rechargeable battery the system should last for up 
 *     to 12 days between charges – frequently turning on the display will reduce this.
 *   
 *   Note on using the 3.7v rechargeable battery.
 *    The Nano specification is that it requires a 5v supply, however
 *    for this project it runs perfectly well on a 3.7v rechargeable battery
 *    with the supply connected to the 5v pin.
 *    It is also safe to recharge when in use as the voltage will only increase to 4.2v
 */

// Include drivers
#include <DHT.h>            // This is the DHT sensor library by Adafruit
#include "LowPower.h"       // Low-Power library from rocketscream
                            // required for the OLED display 
#include <SPI.h>            // Synchronous serial data protocol library
#include <Wire.h>           // IC2 communications library
#include <Adafruit_GFX.h>   // Adafruit Graphics Core Library
#include <Adafruit_SSD1306.h>  // SSD1306 library for Monochrome 128x64 and 128x32 OLEDs 
#include <Fonts/FreeMonoBold9pt7b.h>  // Include fonts to be used
#include <Fonts/FreeSans9pt7b.h>


#define DATA_PIN 4                    // Pin used to collect data from the DHT
#define DHTTYPE DHT11                 // DHT Type  
//#define DHTTYPE DHT22               // If you have a DHT22 comment the DHT11 and
                                      // uncomment DHT22
// Create the sensor object and assign pin
DHT dht(DATA_PIN, DHTTYPE);


#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// The pins for I2C are defined by the Wire-library. 
// On an arduino UNO/Nano and Pro Mini: A4(SDA), A5(SCL)
// On an arduino MEGA 2560:             20(SDA), 21(SCL)
// On an arduino LEONARDO:              2(SDA),  3(SCL), ...
#define OLED_RESET   -1 // Reset pin # (or -1 if no reset on display)
#define SCREEN_ADDRESS 0x3C // See datasheet for Address (Yours could be 0x3D)

// Creat eobject for the SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define MODE_BUTTON 2             // Activate display and switched between temperature and humidity
#define RESET_BUTTON 3            // If pressed when awake resets min and max settings

float temp;       //Current temperature
float humid;      //Current humidity
float minTemp;    //The minimum temperature recorded
float maxTemp;    //The maximum temperature recorded
float minHumid;   //The minimum humidity recorded
float maxHumid;   //The maximum humidity recorded

enum mode {
  dispTemp,        // Temperature currently displayed
  dispHumid        // Humidity currently displayed
};

mode currentMode;   // Current display setting

bool awake;                        // True if system woken by pressing Mode button
bool justWoken;                    // True on activation of interrupt so system knows to wait for button to be released.
unsigned long timeWoken;           // Time last woken or a button press
int keepAwakeFor = 15;             // Number of seconds before allow to go back to sleep

const int wakeUpPin = MODE_BUTTON; // Set the pin that will wake up from power saving mode

// Icon displayed when system is asleep
static const unsigned char PROGMEM snooze[] =
{ B00000000, B00001110,
  B00000000, B00000100,
  B00000000, B00001110,
  B00000011, B11000000,
  B00000011, B11000000,
  B00000000, B10000000,
  B00000001, B00000000,
  B00000011, B11000000,
  B00000011, B11000000,
  B11111000, B00000000,
  B11111000, B00000000,
  B00010000, B00000000,
  B00100000, B00000000,
  B01000000, B00000000,
  B11111000, B00000000,
  B11111000, B00000000,
};

// Arrows used to indicate maximum and minimum
static const unsigned char PROGMEM upArrow[]{
  B00000000,
  B00011000,
  B00111100,
  B01111110,
  B11111111,
  B00011000,
  B00011000,
  B00011000
};

static const unsigned char PROGMEM downArrow[]{
  B00011000,
  B00011000,
  B00011000,
  B11111111,
  B01111110,
  B00111100,
  B00011000,
  B00000000
};

void setup() {
  minTemp = 99;    //Set to a figure that is going to be too high
  maxTemp = -9;    //Set to a figure that is going to be too low
  minHumid = 99;   //Set to a figure that is going to be too high
  maxHumid = -9;   //Set to a figure that is going to be too low
  pinMode(MODE_BUTTON, INPUT_PULLUP);  // Use INPUT_PULLUP - will go LOW when pressed
  pinMode(RESET_BUTTON, INPUT_PULLUP);
  // Start sensor
  dht.begin();
  // Initialise display
  display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS); 
  display.setTextColor(WHITE);
  currentMode = dispTemp;
  awake = true;
  timeWoken = millis();         // Set so initially remains awake for set period
}

void loop() {
  // Check to see if has been awake for the keepAwakeFor period
  // if so allow to go to sleep
  if ((millis() - timeWoken) > (keepAwakeFor * 1000)) {
    awake = false;
    // Sleep for 24 seconds
    for (int i = 0; i < 3; i++){
      display.clearDisplay(); 
      display.drawBitmap(random(10, 110), random(10, 48), snooze, 16, 16, WHITE);
      display.display();
      // Allow wake up pin to trigger interrupt on low.
      attachInterrupt(0, wakeUp, LOW);
      // Enter power down state with ADC and BOD module disabled.
      // Wake up when wake up pin is low or after 8 seconds.
      // If wake up button pressed then as long as button held down for more
      // than a few milliseconds it will fall through any remaining sleep loops      
      LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
      // Disable external pin interrupt on wake up pin.
      detachInterrupt(0);
    }
  }

  // If woken by Mode button press then default to temperature display
  if (justWoken)
     currentMode = dispTemp; 

  // Repeat read and check buttons 3 times once every 1/10th second to ensure get up to date readings
  // as the system may go back to sleep on next loop
  for (int i = 0; i < 3; i++) {
    delay(100);
    // Get readings, update minimum and maximum values
    // and display if system is awake as a result of Mode button press
    humid = dht.readHumidity();                   // read humidity
    temp = dht.readTemperature();                 // read temperature
    if (temp < minTemp)
      minTemp = temp;
    if (temp > maxTemp)
      maxTemp = temp;
    if (humid < minHumid)
      minHumid = humid;
    if (humid > maxHumid)
      maxHumid = humid;
    // Update display if awake
    if ((currentMode == dispTemp) && (awake))
      ShowTemperature();
    if ((currentMode == dispHumid) && (awake))
      ShowHumidity();

    // If awake due to Mode button press the check if any buttons have been pressed
    if (awake)
      CheckButtons();
  }
}

// To ensure numbers align add a space if required
String FormatNumber(float value){
  if (value < 10.0 && value > 0.0)
    return " " + String(value);
  else
    return String(value);
}

void ShowTemperature() {
  display.clearDisplay();
  display.setTextSize(1);
  display.setFont(&FreeSans9pt7b);  // Font used for text
  display.setCursor(0, 15);
  display.print("Temp:");
  display.drawBitmap(20, 35-9, upArrow, 8, 8, WHITE);
  display.drawBitmap(20, 55-9, downArrow, 8, 8, WHITE);
  display.setFont(&FreeMonoBold9pt7b);  // Font used for numbers
  display.setCursor(60, 15);
  display.print(FormatNumber(temp) + "c");
  display.setCursor(60, 35);
  display.print(FormatNumber(maxTemp) + "c");
  display.setCursor(60, 55);
  display.print(FormatNumber(minTemp) + "c");
  display.display(); 
}

void ShowHumidity() {
  display.clearDisplay();
  display.setTextSize(1);
  display.setFont(&FreeSans9pt7b);  // Font used for text
  display.setCursor(0, 15);
  display.print("Humid:");
  display.drawBitmap(20, 35-9, upArrow, 8, 8, WHITE);
  display.drawBitmap(20, 55-9, downArrow, 8, 8, WHITE);
  display.setFont(&FreeMonoBold9pt7b);    // Font used for numbers
  display.setCursor(60, 15);
  display.print(FormatNumber(humid) + "%");
  display.setCursor(60, 35);
  display.print(FormatNumber(maxHumid) + "%");
  display.setCursor(60, 55);
  display.print(FormatNumber(minHumid) + "%");
  display.display(); 
}

void CheckButtons() {
  // If just woken up then pause for 1/2 second to allow button to be released
  if (justWoken){
    delay(500);
    justWoken = false;
  }
  // If the mode or reset button has been pressed pin will go LOW
  // Check if mode button pressed if so switch mode between displays
  if (digitalRead(MODE_BUTTON) == LOW) {
    timeWoken = millis();           // Reset so remains awake for set period after switching mode
    //awake = true;
    if (currentMode == dispTemp) {
      currentMode = dispHumid;
      ShowHumidity();
      delay(500);                     // Give time to release button
    }
    else {
      currentMode = dispTemp;
      ShowTemperature();
      delay(500);                     // Give time to release button
    }
  }

  // Check if reset button pressed
  // Is the system awake?
  // If so the reset min and max values
  if (digitalRead(RESET_BUTTON) == LOW) {
    if (awake) {
      maxTemp = -9;
      minTemp = 99;
      maxHumid = -9;
      minHumid = 99;
      delay(500);                     // Give time to release button
    }
  }
}

void wakeUp()
{
  // Handler for the pin interrupt.
  timeWoken = millis();               // Reset so remains awake for awake period
  awake = true;
  justWoken = true;
}
Temp/Humid monitor LCD version codeArduino
/*   Paul Brace April 2021
 *   Very low power consumption temperature and humidity monitor
 *     with minimum and maximum monitoring
 *   Board - Arduino Nano 3
 *   Display - LCD 16x2 
 *   
 *   Aim was to reduce power consumption as much as possible so
 *     can be run on a rechargeable battery for long periods
 *   This is achieved by:
 *         1. Turning the backlight off after a set period 
 *         2. Using the rocketscream low power library to put the processor 
 *            to sleep waking every 24 seconds to check the temperature and 
 *            humidity, which takes less than a second.
 *   The mode button is used to wake the processor for a set period , turn 
 *     the backlight on and switch between the temperature and humidity displays.
 *   The processor remains awake for the period specified in keepAwakeFor.
 *   The backlight remains on for the period specified in timeLightTurnedOn
 *       (Note: this should be less than keepAwakeFor or the light will not be 
 *        turned off until the next awake cycle). 
 *   The reset button is used to reset the minimum and maximum values
 *     when the backlight is on.
 *   Power consumption with the suggested components:
 *      Asleep:                               24 seconds    5.6mA
 *      Checking temp./humid. between sleeps  <1 second     14mA
 *                                            So on average 6.0mA                                            
 *                                          
 *      With backlight on                                   28.5mA
 *      
 *   Using a 1,000 mAh rechargeable battery the system should last for up 
 *     to 7 days between charges – frequently turning on the backlight will obviously 
 *     reduce this.
 *   
 *   Note on using the 3.7v rechargeable battery.
 *    The Nano specification is that it requires a 5v supply, however
 *    for this project it runs perfectly well on a 3.7v rechargeable battery
 *    with the supply connected to the 5v pin.
 *    It is also safe to recharge when in use as the voltage will only increase to 4.2v
 */

// Include driver for the DHT
// This is the DHT sensor library by Adafruit
#include <DHT.h>
// Include the library driver for display:
#include <LiquidCrystal.h>
// Include Low-Power library from rocketscream
#include "LowPower.h"

// Pin used to collect data from the DHT
#define DATA_PIN 4

// DHT Type. If you have a DHT22 comment the DHT11 and
// uncomment DHT22
#define DHTTYPE DHT11
//#define DHTTYPE DHT22

// Create the sensor object and assign pin
DHT dht(DATA_PIN, DHTTYPE);

// Create an lcd object and assign the pins
// LiquidCrystal lcd( RS, EN, D4,D5, D6, D7)
LiquidCrystal lcd(12, 13, 6, 7, 8, 9);

#define MODE_BUTTON 2             // Wake processor/turn backlight on and switch display between temperature and humidity
#define RESET_BUTTON 3            // If pressed when light on then resets min and max settings
#define BACKLIGHT_PIN 5           // Connected to backlight on LCD

float temp;       //Current temperature
float humid;      //Current humidity
float minTemp;    //The minimum temperature recorded
float maxTemp;    //The maximum temperature recorded
float minHumid;   //The minimum humidity recorded
float maxHumid;   //The maximum humidity recorded

enum mode {
  dispTemp,        // Temperature currently displayed
  dispHumid        // Humidity currently displayed
};

mode currentMode;   // Current display setting

bool awake;                        // True if system woken by pressing Mode button
bool justWoken;                    // True on activation of interrupt so system knows to wait for button to be released. 
bool lightOn;                      // True if backlight on
unsigned long timeLightTurnedOn;   // Time backlight was last turned on
int lightTimeOut = 10;             // Number of seconds light remains on (should be less than keepAwakeFor)
unsigned long timeWoken;           // Time last woken or a button press
int keepAwakeFor = 15;             // Number of seconds before allow to go back to sleep

const int wakeUpPin = MODE_BUTTON; // Set the pin that will wake up from power saving mode

// Arrows used to indicate maximum and minimum
byte upArrow[8] = {
  B00000,
  B00100,
  B01110,
  B10101,
  B00100,
  B00100,
  B00000,
};

byte downArrow[8] = {
  B00000,
  B00100,
  B00100,
  B10101,
  B01110,
  B00100,
  B00000,
};

void setup() {
  minTemp = 99;    //Set to a figure that is going to be too high
  maxTemp = -9;    //Set to a figure that is going to be too low
  minHumid = 99;   //Set to a figure that is going to be too high
  maxHumid = -9;   //Set to a figure that is going to be too low
  pinMode(MODE_BUTTON, INPUT_PULLUP);  // Use INPUT_PULLUP - will go LOW when pressed
  pinMode(RESET_BUTTON, INPUT_PULLUP);
  pinMode(BACKLIGHT_PIN, OUTPUT);
  // Start sensor
  dht.begin();
  // Initalise diplay
  lcd.begin(16, 2);
  lcd.noAutoscroll();
  lcd.display();
  lcd.clear();
  // Create up and down arrow characters
  lcd.createChar(0, upArrow);
  lcd.createChar(1, downArrow);
  
  TurnBacklightOn();
  currentMode = dispTemp;
  awake = true;
  timeWoken = millis();         // Set so initially remains awake for set period
}

void loop() {
  // Check to see if has been awake for the keepAwakeFor period
  // if so allow to go to sleep
  if ((millis() - timeWoken) > (keepAwakeFor * 1000)) {
    awake = false;
    // Sleep for 24 seconds
    for (int i = 0; i < 3; i++){
      // Allow wake up pin to trigger interrupt on low.
      attachInterrupt(0, wakeUp, LOW);
      // Enter power down state with ADC and BOD disabled.
      // Wake up when wake up pin goes low or after 8 seconds.
      // If wake up button pressed then as long as button held down for more
      // than a few milliseconds it will fall through any remaining sleep loops
      LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
      // Disable external pin interrupt on wake up pin.
      detachInterrupt(0);
    }
  }

  // If woken by Mode button press then default to temperature display
  if (justWoken)
     currentMode = dispTemp; 
  
  // Repeat read 3 times, once every 1/10th second, to ensure get up to date readings
  // as the system may go back to sleep on next loop
  for (int i = 0; i < 3; i++) {
    delay(100);

    // Check if need to turn backlight off
    if (lightOn && ((millis() - timeLightTurnedOn) > (lightTimeOut * 1000)))
      TurnBacklightOff();
    // get readings, update minimum and maximum values and
    // refresh display
    humid = dht.readHumidity();                   // read humidity
    temp = dht.readTemperature();                 // read temperature
    // Set min and max values if required
    if (temp < minTemp)
      minTemp = temp;
    if (temp > maxTemp)
      maxTemp = temp;
    if (humid < minHumid)
      minHumid = humid;
    if (humid > maxHumid)
      maxHumid = humid;
    if (currentMode == dispTemp)
      ShowTemperature();
    else
      ShowHumidity();
    // If awake due to Mode button press the check if any buttons have been pressed
    if (awake)
      CheckButtons();
  }
}

// To ensure numbers align add a space if required
String formatNumber(float value){
  if (value < 10.0 && value > 0.0)
    return " " + String(value);
  else
    return String(value);
}

void ShowTemperature() {
  lcd.setCursor(0, 0);
  lcd.print("Temp: " + String(temp) + "c   ");
  lcd.setCursor(0, 1);
  lcd.write(byte(1));
  lcd.print(String(minTemp) + "c  ");
  lcd.setCursor(9, 1);
  lcd.write(byte(0));
  lcd.print(String(maxTemp) + "c  ");
}

void ShowHumidity() {
  // Display current temp on line 0
  lcd.setCursor(0, 0);
  lcd.print("Humid: " + String(humid) + "%   ");
  lcd.setCursor(0, 1);
  lcd.write(byte(1));
  lcd.print(String(minHumid) + "%  ");
  lcd.setCursor(9, 1);
  lcd.write(byte(0));
  lcd.print(String(maxHumid) + "%  ");
}

void CheckButtons() {
  // If just woken up then pause for 1/2 second to allow button to be released
  if (justWoken){
    delay(500);
    justWoken = false;
  }
  // If the mode or reset button has been pressed the associated pin will go LOW
  // Check if mode button pressed if so switch mode between displays
  if (digitalRead(MODE_BUTTON) == LOW) {
    timeWoken = millis();           // Reset so remains awake for the awake period after switching mode
    TurnBacklightOn();              // In case off and so also remains on for set period
    // Switch displays
    if (currentMode == dispTemp) {
      currentMode = dispHumid;
      ShowHumidity();
      delay(500);                   // Give time to release button
    }
    else {
      currentMode = dispTemp;
      ShowTemperature();
      delay(500);                  // Give time to release button
    }

  }

  // Check if reset button pressed
  // Is light currently on?
  // If so the reset min and max values
  if (digitalRead(RESET_BUTTON) == LOW) {
    if (lightOn) {
      maxTemp = -9;
      minTemp = 99;
      maxHumid = -9;
      minHumid = 99;
      delay(350);                 // Give time to release button
    }
  }
}

void TurnBacklightOn() {
  // Turn backlight on
  lightOn = true;
  timeLightTurnedOn = millis();
  digitalWrite(BACKLIGHT_PIN, HIGH);
}

void TurnBacklightOff() {
  // Turn backlight off
  lightOn = false;
  digitalWrite(BACKLIGHT_PIN, LOW);
}

void wakeUp()
{
  // Handler for the pin interrupt.
  timeWoken = millis();         // Reset so remains awake for awake period
  TurnBacklightOn();
  awake = true;
  justWoken = true;
}

Schematics

Temp/Humid monitor OLED Breadbaord
Monitor oled version breadboard in4sz6pyhx
Temp/Humid monitor OLED Schematic
Monitor oled version schematic nwjx7z929n
Temp/Humid monitor LCD Breadboard
Monitor lcd version breadboard ddouyhj84m
Temp/Humid monitor LCD Schematic
Monitor lcd version schematic 6p0j2m4qvv

Comments

Similar projects you might like

Temperature and Humidity Logger Per Hour

Project tutorial by lefteris1993

  • 6,169 views
  • 0 comments
  • 16 respects

Temperature + Humidity on LCD

Project showcase by interpeo

  • 33,658 views
  • 17 comments
  • 64 respects

MKR1000 Temp and Humidity Sensor

Project tutorial by Don Coleman

  • 27,565 views
  • 11 comments
  • 41 respects

DHT11 Humidity + Temperature Sensor with 16x2 LCD display

Project showcase by onatto22

  • 50,416 views
  • 13 comments
  • 58 respects

Humidity Sensor-Controlled Bathroom Exhaust Fan

Project showcase by LIMPINGLIM

  • 12,425 views
  • 12 comments
  • 35 respects

Low Power RF Beacon for Remote Sensing & Communication

Project tutorial by Shahariar

  • 9,267 views
  • 1 comment
  • 20 respects
Add projectSign up / Login