My first version was built 20 years ago and consisted of an analog telephone dialer attached to the mercury switch of an old mechanical thermostat. It played a prerecorded message when the temp dropped below freezing.
Fast forward 20 years and now using a Yun, Blynk and a DS-18 sensor. I can graph history and remotely set the alarm limits so an SMS message is sent when the temp goes below the alarm set level. The code is not anything to be proud of but it works.
Works with Yun and DS-18 Temp Sensor. Set temp for alarm and will email/Txt when below alarm condition at 1 per minute. Alarm can be disabled with switch. Slider sets alarm temp.
Sensor is hooked to Pin 7 with 4.7K pull up resistor.
Uses Blynk , also graphs temp.
**************************************************************/
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <Bridge.h>
#include <SPI.h>
#include <BlynkSimpleYun.h>
#include <SimpleTimer.h>
#include <OneWire.h>
#include <DallasTemperature.h>
//Data wire plugged to digital pin 7 (temp sensor)
#define ONE_WIRE_BUS 7
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
char auth[] = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;
WidgetLCD lcd(2); // display info in LCD widget
float temp;
int alarm; // for slider
int button; // for email switch
SimpleTimer timer;
void setup()
{
Serial.begin(9600);
Blynk.begin(auth);
// Or specify server using one of those commands:
//Blynk.begin(auth, “server.org”, 8442);
//Blynk.begin(auth, server_ip, port);
// Setup a function to be called every second
timer.setInterval(3000, readTemp);
}
// that you define how often to send data to Blynk App.
void sendUptime();
BLYNK_WRITE(1){alarm=param.asInt();}
BLYNK_WRITE(V3){button=param.asInt();}
void readTemp()
{
sensors.requestTemperatures();
float floatTempC = sensors.getTempCByIndex(0);
char t_buffer[15];
dtostrf((floatTempC9.0)/5.0+32.0, 8, 9, t_buffer);
Blynk.virtualWrite(5, t_buffer);
float alarmF = (alarm9.0)/5.0+32.0;
lcd.clear(); //Use it to clear the LCD Widget
lcd.print(4, 0, alarmF); // use: (position X: 0-15, position Y: 0-1, “Message you want to print”)
lcd.print(4, 1, “Alarm F”);
// send email if temp is below and email button activated.
if ((floatTempC < alarm) && (button == 1))
Blynk.email("5551234567@vtext.com", “Temp Alert”, “Temp below Alarm”);
}
void loop()
{
Blynk.run();// Initiates Blynk
timer.run(); // Initiates SimpleTimer
}