I am brand new to this and only received my Uno 8 days ago. (And have never coded before, So please be gentle with me)
This has probably been covered many times before.
I needed an alarm system for the freezer because the kids are forever leaving the door open. Unfortunately there is only one place in the kitchen that the freezer can go, and it is a tight fit.
Because of this a simple "switch" wouldn't work because of the space constraints, and the freezer door only needs to be left open a couple of mm's to cause a problem.
I measured the temperature at ground level and thought if I can monitor this, knowing that any cold air from an open freezer door will "sink" I might be on to a solution.
I will post the complete code below, anything to do with the lcd and wire can be deleted, it was just me wanting to have a play and look at the numbers
The calibration may be a bit off, I originally wanted to set the buzzer off at below 5 degrees, but couldn't seem to get it that low even with an ice cube in poly bag sat on the sensor!!!
I used an LM35 sensor and basic active buzzer
So chuffed this worked first time.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
float tempC; //defines that the temp is a decimal number//
int reading; //defines that the reading is an integer//
int tempPin = 0; //sets sensor pin to pin 0 (analog)//
int buzzPin = (8); //sets buzzer output pin NB this is a digital pin//
LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7,3,POSITIVE); //sets the I2C address for the lcd//
void setup()
{
analogReference(INTERNAL); //defines that the ref voltage will be 1.1v//
Serial.begin(9600); //starts serial port and sets baud rate//
pinMode (buzzPin, OUTPUT); //sets the buzzer pin as an output//
lcd.begin (20,4); // states that the lcd is a 20 x 4 display)
lcd.backlight (); // turns the lcd backlight on//
}
void loop()
{
reading = analogRead(tempPin); //takes the reading from the sensor and//
tempC = reading / 9.31; //converts it into Celsius and prints the value//
Serial.println(tempC); //to the console //
lcd.setCursor(0,0); // starts the lcd display at top left//
lcd.print (tempC); // prints the sensor reading to the lcd//
delay(2000); // repeats after 2 seconds//
if (tempC < 9.00){ //if the temerature is below 9 degrees C, //
digitalWrite (buzzPin, HIGH); //turns the buzzer on - if above 5dgrees C, //
delay(2000); // wait 2 secs//
}else{ }
digitalWrite (buzzPin, LOW); // turns the buzzer off//
}
It has now been hard wired to a Nano (obviously without the display) and powered by a PP9, sits in a little project box just under the freezer.
Rob.