Hello all! I need some help with a project I'm trying to improve upon! I've set up a 10k thermistor and LCD screen to my Arduino Uno and programed it to where the temperature that the thermistor is reading is shown on the LCD in degrees Fahrenheit. I used the attached schematic and the flowing code and it works perfectly! I was wondering if there is any way I could attach a Piezo Element to my board and program it to where when the thermistor reads a range of specified temperatures the Piezo Element will buzz? If so, what do I need to add to my current code? Please be as detailed as possible I'm still pretty new at this and still learning!
Thanks in advance!
LCD Thermistor Reading code:
/*
Sketch that reads temperature from a thermistor and displays
the result on an LCD screen
LCD Connections:
- LCD RS pin to digital pin 2
- LCD Enable pin to digital pin 3
- LCD D4 pin to digital pin 4
- LCD D5 pin to digital pin 5
- LCD D6 pin to digital pin 6
- LCD D7 pin to digital pin 7
- LCD R/W pin to ground
*/
//include the LCD library
#include <LiquidCrystal.h>
// analog input pin used for thermistor input
#define TEMPINPUT A0
// thermistor resistance at 25 degrees C
#define THERMISTORNOMINAL 10000
// thermistor temperature at nominal resistance
#define TEMPERATURENOMINAL 25
// beta coefficient of the thermistor (usually 3000-4000)
#define BCOEFFICIENT 3950
// the value of the 'other' voltage divider resistor
#define SERIESRESISTOR 10000
// how many samples to take and average, more takes longer
// but is more 'smooth'
#define NUMSAMPLES 20
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2,3,4,5,6,7);
void setup(void) {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Current Temp:");
}
void loop(void) {
int i=0; //used for average
float temp_adc; //latest temperature input ADC value
float temp_avg = 0; //average temperature input ADC value
float temp_resistance; //resistance calculated from avg ADC value
//read analog voltage on temp input pin - will be between 0 and 1023
//take NUMSAMPLES and average values
for (i=0;i<NUMSAMPLES;i++)
{
temp_adc = analogRead(TEMPINPUT);
temp_avg = temp_avg + temp_adc / NUMSAMPLES;
}
//convert ACDC value to resistance
temp_resistance = THERMISTORNOMINAL / (1023.0/temp_avg-1.0);
//the following equations convert the thermistor resistance
//to a temperature in degrees Fahrenheit
float steinhart;
steinhart = temp_resistance / THERMISTORNOMINAL; // (R/Ro)
steinhart = log(steinhart); // ln(R/Ro)
steinhart /= BCOEFFICIENT; // 1/B * ln(R/Ro)
steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
steinhart = 1.0 / steinhart; // Invert
steinhart -= 273.15; // convert to C
steinhart = (steinhart + 40)*9.0/5.0 - 40; // convert to F
//Move cursor to the first position in the second row
lcd.setCursor(0,1);
//Print temperature
lcd.print(steinhart);
//lcd.print(" ");
lcd.print((char)223); //Print degree symbol
lcd.print("F");
delay(100);
}
