Temp monitor with SMS Alarm

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 = (alarm
9.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
}

4 Likes

Please edit your post. Code should be formatted.
Wrap the code by pressing this magic button (Backtick`) 3 times (before the code and after it):**

Example:

 ``` <--- insert this 
 Paste your code here
 ``` <--- insert this 

This makes your code beautiful with highlighted syntax, like this:

//comment goes here 
void helloWorld() { 
   String message =  "hello" + "world"; 
}

You can also select the code and press </> button in the top menu:

Thanks for sharing your project! Like the history part! :slight_smile:

One More time but prettier code :slight_smile:

/**************************************************************
 * Blynk is a platform with iOS and Android apps to control
 * Arduino, Raspberry Pi and the likes over the Internet.
 * You can easily build graphic interfaces for all your
 * projects by simply dragging and dropping widgets.
 *
 *   Downloads, docs, tutorials: http://www.blynk.cc
 *   Blynk community:            http://community.blynk.cc
 *   Social networks:            http://www.fb.com/blynkapp
 *                               http://twitter.com/blynk_app
 *
 * Blynk library is licensed under MIT license
 * This example code is in public domain.
 *
 **************************************************************
Works with Yun abd DS-18 Temp Sensor.  Set temp for alarm and will email/Txt when below alarm condition at 1 per minute.
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[] = "3b040945785244bea81746efe4d5c788";

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((floatTempC*9.0)/5.0+32.0, 8, 9, t_buffer);
  Blynk.virtualWrite(5, t_buffer);
  float alarmF = (alarm*9.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 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

}