Adventures with Arduino Part 34

I am currently looking at a project for the Tech jam.  Or essentially a modification of an existing project.   This is a revisit of the Temperature and Humidify project.   Rather than display on an LCD screen the idea is that it sets of an alarm should either or both fall below a certain value.

The first step was to modify the original code to send data to the serial port.  In fact the code for this was already there, just commented out.  So it was simply a case of commenting:

#include <LiquidCrystal.h>
#include "DHT.h"
#define DHTPIN 8     // pin DHT is connected
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);  
#define DHTTYPE DHT11   
 
DHT dht(DHTPIN, DHTTYPE);
void setup() {
  dht.begin();
  lcd.begin(16, 2);
}
void loop() {
   float h = dht.readHumidity();
  float t = dht.readTemperature();
  // t = t* 9/5 + 32; // display as farenheit
    t = t; // display as centigrade
    if (isnan(t) || isnan(h)) {
    lcd.setCursor(0, 0);
    lcd.print("Failed to read from DHT");
    //Serial.println("Failed to read from DHT");
  } else {
    //lcd.clear();
    //lcd.setCursor(0, 0);
    //lcd.print("Humidity: ");
    //lcd.print(h);
    //lcd.print("%");
    //lcd.setCursor(0, 1);
    //lcd.print("Temp: ");
    //lcd.print(t);
    //lcd.print(" C");
    delay(1000); // add delay to stop flickering screen
    Serial.begin(9600);
    Serial.print("Humidity: "); 
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: "); 
    Serial.print(t);
    Serial.println(" C");
  }
}

I had to also enable the serial port.   The result was that it now sends data to the serial port.  This can be read via the Serial monitor utility in the Arduino IDE.

 

Serial.begin(9600);

In order to enable the serial port.

INTERPRETING AND DOING SOMETHING WITH THE OUTPUT

Once we have some output, and variables to hold the values we want.  We can start doing things depending on these values.  Project 8 in the Arduino handbook provides some code that is similar to what we are looking for.

{
if(analogRead(0) > 900){ // this number depends soil moisture
 
digitalWrite(buzzPin, HIGH);
digitalWrite(LED,HIGH);
 
delay(1000); // waits for 1 second
digitalWrite(buzzPin,LOW);
digitalWrite(LED,HIGH);
 
} else{
digitalWrite(buzzPin,LOW);
digitalWrite(LED,LOW);
}
}
 
}

This clearly needs to be modified. You also need to add 2x LED to the project and enable these within the code.  Once I have done this and also modified the code I will make a new post with the new code block.