LCD Temp alarm

Hi all I’m new to the form and Arduino i have programed to Arduino’s thanks to info i found online. I have programed a uno with the info from this link I need help trying to make it alarm say at temp of 40f I Can’t seem to find info that helps me out i would like it to sound a pizeo.

Any help you can provide would be great

Code is attached

tempLCDsketch_dec09a.ino (3.44 KB)

Is your LCD currently working and showing the correct temperatures?

Hi KenF

Yes i did get it to display and the temps are displaying. Just wondering if there is a way to trigger a pizeo for a high temp alert.

Thanks

There must be hundreds of other projects out there that show you how to attach a piezo to an Arduino. Goggle isn't finding them for you?

Looking at what others have done should help you form better questions. If you post a link here and say "I like {this example} because the code is simple but I want to use the bigger/louder piezo from {this example}" then you might get a better answer.

This IS easy. Piezo buzzers come in various forms though. If you get one with the "built in sound driver" then all you have to do is connect it to one of your output pins and send that pin HIGH when the temperature is higher than your threshold.

If you have one without the built in sound driver you'll have to provide it with on/off pulses, which can be a bit trickier if you don't want your sketch to come to a standstill while you're doing it. (although could be worth it for the learning exercise).

Thanks for the info I’ll look into this.

One thing i did notice with the dht11 is i can’t do negative temps so i need help adding the dht22 to the code i tried changing dht11 to read dht22 but i get it to compile i have been reading to make sure the library is up to date which i think it is

The error is

tempLCDsketch_dec09a:18: error: ‘dht22’ does not name a type
tempLCDsketch_dec09a.ino: In function ‘void loop()’:
tempLCDsketch_dec09a:43: error: ‘dht22’ was not declared in this scope

/* YourDuino.com Example Software Sketch
   dht22 Humidity and Temperature Sensor test
   Displayed on I2C LCD Display
   Credits: Rob Tillaart
   http://arduino-info.wikispaces.com/PROJECT-Temp-Humidity-Display
   terry@yourduino.com */
   
/*-----( Import needed libraries )-----*/
#include <dht22.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

/*-----( Declare objects )-----*/
// set the LCD address to 0x27 for a 20 chars 4 line display
// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
dht22 DHT22;
int i=0;

/*-----( Declare Constants, Pin Numbers )-----*/
#define dht22PIN 2

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  Serial.begin(9600); //(Remove all 'Serial' commands if not needed)
  lcd.begin(20,4);         // initialize the lcd for 20 chars 4 lines, turn on backlight
  lcd.backlight();
  // Print a message to the LCD.
  //lcd.setCursor(0, 1);
  lcd.print("dht22 Temp/Humid");

lcd.setCursor(0, 1);
 
  lcd.print("Console");
 
}/*--(end setup )---*/

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{


  int chk = dht22.read(dht22PIN);

  Serial.print("Read sensor: ");
  switch (chk)
  {
    case 0: Serial.println("OK"); break;
    case -1: Serial.println("Checksum error"); break;
    case -2: Serial.println("Time out error"); break;
    default: Serial.println("Unknown error"); break;
  }
  lcd.setCursor(0, 3);

  lcd.print("C=");
  lcd.print((float)dht22.temperature, 0);
  Serial.print("Temperature (oC): ");
  Serial.println((float)dht22.temperature, 2);

  lcd.print(" F=");
  lcd.print(Fahrenheit(dht22.temperature), 0);
  Serial.print("Temperature (oF): ");
  Serial.println(Fahrenheit(dht22.temperature), 2);
  
  lcd.print("  H=");
  lcd.print((float)dht22.humidity, 0);
  lcd.print("%");
  Serial.print("Humidity (%): ");
  Serial.println((float)dht22.humidity, 2);  

  Serial.print("Temperature (K): ");
  Serial.println(Kelvin(dht22.temperature), 2);

  Serial.print("Dew Point (oC): ");
  Serial.println(dewPoint(dht22.temperature, dht22.humidity));

  Serial.print("Dew PointFast (oC): ");
  Serial.println(dewPointFast(dht22.temperature, dht22.humidity));

  delay(2000);
}/* --(end main loop )-- */

/*-----( Declare User-written Functions )-----*/
//
//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
        return 1.8 * celsius + 32;
}

//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
        return celsius + 273.15;
}

// dewPoint function NOAA
// reference: http://wahiduddin.net/calc/density_algorithms.htm 
double dewPoint(double celsius, double humidity)
{
        double A0= 373.15/(273.15 + celsius);
        double SUM = -7.90298 * (A0-1);
        SUM += 5.02808 * log10(A0);
        SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
        SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
        SUM += log10(1013.246);
        double VP = pow(10, SUM-3) * humidity;
        double T = log(VP/0.61078);   // temp var
        return (241.88 * T) / (17.558-T);
}

// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
        double a = 17.271;
        double b = 237.7;
        double temp = (a * celsius) / (b + celsius) + log(humidity/100);
        double Td = (b * temp) / (a - temp);
        return Td;
}

/* ( THE END ) */
dht22 DHT22;

DHT22 dht22;

Thanks Vaclav for your reply I updated the code but still get errors compiling

dht22tempLCDsketch_dec09a:18: error: ‘DHT22’ does not name a type
dht22tempLCDsketch_dec09a.ino: In function ‘void loop()’:
dht22tempLCDsketch_dec09a:43: error: ‘dht22’ was not declared in this scope

/* YourDuino.com Example Software Sketch
   dht22 Humidity and Temperature Sensor test
   Displayed on I2C LCD Display
   Credits: Rob Tillaart
   http://arduino-info.wikispaces.com/PROJECT-Temp-Humidity-Display
   terry@yourduino.com */
   
/*-----( Import needed libraries )-----*/
#include <dht22.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

/*-----( Declare objects )-----*/
// set the LCD address to 0x27 for a 20 chars 4 line display
// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
DHT22  dht22;
int i=0;

/*-----( Declare Constants, Pin Numbers )-----*/
#define dht22PIN 2

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  Serial.begin(9600); //(Remove all 'Serial' commands if not needed)
  lcd.begin(20,4);         // initialize the lcd for 20 chars 4 lines, turn on backlight
  lcd.backlight();
  // Print a message to the LCD.
  //lcd.setCursor(0, 1);
  lcd.print("dht22 Temp/Humid");

lcd.setCursor(0, 1);
 
  lcd.print("Console");
 
}/*--(end setup )---*/

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{


  int chk = dht22.read(dht22PIN);

  Serial.print("Read sensor: ");
  switch (chk)
  {
    case 0: Serial.println("OK"); break;
    case -1: Serial.println("Checksum error"); break;
    case -2: Serial.println("Time out error"); break;
    default: Serial.println("Unknown error"); break;
  }
  lcd.setCursor(0, 3);

  lcd.print("C=");
  lcd.print((float)dht22.temperature, 0);
  Serial.print("Temperature (oC): ");
  Serial.println((float)dht22.temperature, 2);

  lcd.print(" F=");
  lcd.print(Fahrenheit(dht22.temperature), 0);
  Serial.print("Temperature (oF): ");
  Serial.println(Fahrenheit(dht22.temperature), 2);
  
  lcd.print("  H=");
  lcd.print((float)dht22.humidity, 0);
  lcd.print("%");
  Serial.print("Humidity (%): ");
  Serial.println((float)dht22.humidity, 2);  

  Serial.print("Temperature (K): ");
  Serial.println(Kelvin(dht22.temperature), 2);

  Serial.print("Dew Point (oC): ");
  Serial.println(dewPoint(dht22.temperature, dht22.humidity));

  Serial.print("Dew PointFast (oC): ");
  Serial.println(dewPointFast(dht22.temperature, dht22.humidity));

  delay(2000);
}/* --(end main loop )-- */

/*-----( Declare User-written Functions )-----*/
//
//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
        return 1.8 * celsius + 32;
}

//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
        return celsius + 273.15;
}

// dewPoint function NOAA
// reference: http://wahiduddin.net/calc/density_algorithms.htm 
double dewPoint(double celsius, double humidity)
{
        double A0= 373.15/(273.15 + celsius);
        double SUM = -7.90298 * (A0-1);
        SUM += 5.02808 * log10(A0);
        SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
        SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
        SUM += log10(1013.246);
        double VP = pow(10, SUM-3) * humidity;
        double T = log(VP/0.61078);   // temp var
        return (241.88 * T) / (17.558-T);
}

// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
        double a = 17.271;
        double b = 237.7;
        double temp = (a * celsius) / (b + celsius) + log(humidity/100);
        double Td = (b * temp) / (a - temp);
        return Td;
}

/* ( THE END ) */

Quick up date i update the code and was able to fix a library file not found issue and the error is now

dht22tempLCDsketch_dec09a:18: error: expected unqualified-id before numeric constant dht22tempLCDsketch_dec09a.ino: In function 'void loop()': dht22tempLCDsketch_dec09a:43: error: 'dht22' was not declared in this scope

krogerssolar: was able to fix a library file not found issue and the error is now

How? Did you install the library correctly or just remove the include?

I updated it to have #include <DHT.h> before it was #include <dht22.h>

the libraries folder has a DHT folder with the DHT.h and DHT.cpp

along with a folder DHT22 with the same files

/* YourDuino.com Example Software Sketch
   dht22 Humidity and Temperature Sensor test
   Displayed on I2C LCD Display
   Credits: Rob Tillaart
   http://arduino-info.wikispaces.com/PROJECT-Temp-Humidity-Display
   terry@yourduino.com */
   
/*-----( Import needed libraries )-----*/
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

/*-----( Declare objects )-----*/
// set the LCD address to 0x27 for a 20 chars 4 line display
// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

DHT22  dht22;
int i=0;

/*-----( Declare Constants, Pin Numbers )-----*/
#define dht22PIN 2

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  Serial.begin(9600); //(Remove all 'Serial' commands if not needed)
  lcd.begin(20,4);         // initialize the lcd for 20 chars 4 lines, turn on backlight
  lcd.backlight();
  // Print a message to the LCD.
  //lcd.setCursor(0, 1);
  lcd.print("dht22 Temp/Humid");

lcd.setCursor(0, 1);
 
  lcd.print("Console");
 
}/*--(end setup )---*/

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{


  int chk = dht22.read(dht22PIN);

  Serial.print("Read sensor: ");
  switch (chk)
  {
    case 0: Serial.println("OK"); break;
    case -1: Serial.println("Checksum error"); break;
    case -2: Serial.println("Time out error"); break;
    default: Serial.println("Unknown error"); break;
  }
  lcd.setCursor(0, 3);

  lcd.print("C=");
  lcd.print((float)dht22.temperature, 0);
  Serial.print("Temperature (oC): ");
  Serial.println((float)dht22.temperature, 2);

  lcd.print(" F=");
  lcd.print(Fahrenheit(dht22.temperature), 0);
  Serial.print("Temperature (oF): ");
  Serial.println(Fahrenheit(dht22.temperature), 2);
  
  lcd.print("  H=");
  lcd.print((float)dht22.humidity, 0);
  lcd.print("%");
  Serial.print("Humidity (%): ");
  Serial.println((float)dht22.humidity, 2);  

  Serial.print("Temperature (K): ");
  Serial.println(Kelvin(dht22.temperature), 2);

  Serial.print("Dew Point (oC): ");
  Serial.println(dewPoint(dht22.temperature, dht22.humidity));

  Serial.print("Dew PointFast (oC): ");
  Serial.println(dewPointFast(dht22.temperature, dht22.humidity));

  delay(2000);
}/* --(end main loop )-- */

/*-----( Declare User-written Functions )-----*/
//
//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
        return 1.8 * celsius + 32;
}

//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
        return celsius + 273.15;
}

// dewPoint function NOAA
// reference: http://wahiduddin.net/calc/density_algorithms.htm 
double dewPoint(double celsius, double humidity)
{
        double A0= 373.15/(273.15 + celsius);
        double SUM = -7.90298 * (A0-1);
        SUM += 5.02808 * log10(A0); 
        SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
        SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
        SUM += log10(1013.246);
        double VP = pow(10, SUM-3) * humidity;
        double T = log(VP/0.61078);   // temp var
        return (241.88 * T) / (17.558-T);
}

// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
        double a = 17.271;
        double b = 237.7;
        double temp = (a * celsius) / (b + celsius) + log(humidity/100);
        double Td = (b * temp) / (a - temp);
        return Td;
}

/* ( THE END ) */

DHT22 dht22; ??? ( why is this stupid site converting multiple ? to smiley faces?)

On Github which I would consider "the latest" the class name is in lower case "dht".(Pretty unusual using lower case IMHO- unless it is redefined somewher - I did not check).

So either try dht dht22;

or check the Github version to see what could be wrong.

Thanks Vaclav

that did the trick i change it to dht dht22; but also had to update the #include <dht.h> to lowercase and it complied just fine

so the code now looks like this

/* YourDuino.com Example Software Sketch
   dht22 Humidity and Temperature Sensor test
   Displayed on I2C LCD Display
   Credits: Rob Tillaart
   http://arduino-info.wikispaces.com/PROJECT-Temp-Humidity-Display
   terry@yourduino.com */
   
/*-----( Import needed libraries )-----*/
#include <dht.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

/*-----( Declare objects )-----*/
// set the LCD address to 0x27 for a 20 chars 4 line display
// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

dht dht22;
int i=0;

/*-----( Declare Constants, Pin Numbers )-----*/
#define dht22PIN 2

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  Serial.begin(9600); //(Remove all 'Serial' commands if not needed)
  lcd.begin(20,4);         // initialize the lcd for 20 chars 4 lines, turn on backlight
  lcd.backlight();
  // Print a message to the LCD.
  //lcd.setCursor(0, 1);
  lcd.print("dht22 Temp/Humid");

lcd.setCursor(0, 1);
 
  lcd.print("Console");
 
}/*--(end setup )---*/

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{


  int chk = dht22.read(dht22PIN);

  Serial.print("Read sensor: ");
  switch (chk)
  {
    case 0: Serial.println("OK"); break;
    case -1: Serial.println("Checksum error"); break;
    case -2: Serial.println("Time out error"); break;
    default: Serial.println("Unknown error"); break;
  }
  lcd.setCursor(0, 3);

  lcd.print("C=");
  lcd.print((float)dht22.temperature, 0);
  Serial.print("Temperature (oC): ");
  Serial.println((float)dht22.temperature, 2);

  lcd.print(" F=");
  lcd.print(Fahrenheit(dht22.temperature), 0);
  Serial.print("Temperature (oF): ");
  Serial.println(Fahrenheit(dht22.temperature), 2);
  
  lcd.print("  H=");
  lcd.print((float)dht22.humidity, 0);
  lcd.print("%");
  Serial.print("Humidity (%): ");
  Serial.println((float)dht22.humidity, 2);  

  Serial.print("Temperature (K): ");
  Serial.println(Kelvin(dht22.temperature), 2);

  Serial.print("Dew Point (oC): ");
  Serial.println(dewPoint(dht22.temperature, dht22.humidity));

  Serial.print("Dew PointFast (oC): ");
  Serial.println(dewPointFast(dht22.temperature, dht22.humidity));

  delay(2000);
}/* --(end main loop )-- */

/*-----( Declare User-written Functions )-----*/
//
//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
        return 1.8 * celsius + 32;
}

//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
        return celsius + 273.15;
}

// dewPoint function NOAA
// reference: http://wahiduddin.net/calc/density_algorithms.htm 
double dewPoint(double celsius, double humidity)
{
        double A0= 373.15/(273.15 + celsius);
        double SUM = -7.90298 * (A0-1);
        SUM += 5.02808 * log10(A0); 
        SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
        SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
        SUM += log10(1013.246);
        double VP = pow(10, SUM-3) * humidity;
        double T = log(VP/0.61078);   // temp var
        return (241.88 * T) / (17.558-T);
}

// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
        double a = 17.271;
        double b = 237.7;
        double temp = (a * celsius) / (b + celsius) + log(humidity/100);
        double Td = (b * temp) / (a - temp);
        return Td;
}

/* ( THE END ) */

Vaclav: ( why is this stupid site converting multiple ? to smiley faces?)

Because, despite 500+ posts, you still haven't worked out how to use code tags.