Remote Heater Operation Project : Suggestions for improvement

I have been working on a project to allow remote operation of a propane heater at my remote cabin. The problem I worked to solve was that our cabin is in a very cold region of the rocky and we frequently visit in the winter. When we arrive at the cabin it is not uncommon for the temperature to be negative 10-20º F. Our primary source of heat is a propane heater with a single dial for temperature control. On a typical occasion it will take several hours for the cabin to warm, and even longer for our stored water to thaw out. Using a small servo motor, a basic Arduino board, and two temperature sensors we now have a controller for the heater along with indoor and outdoor temperatures.

The issue that I have had since the install is that every few days I will notice a lost data point in my temperature readings, which is followed by an increase of the inside temperature near the heater. I suspect this is most likely the result of the servo motor resetting to its zero position after a reset, and not receiving input from the board to return to the 180 position. (Based on the location of the dial I have to run the motor backwards for temperature control). My thoughts for how to resolve the situation are

  1. Provide a backup power source (lithium battery pack with 120v adapter) - while this would prevent a reset in the event of a power outage I am not certain this is the true issue.
  2. Provide coding that will instruct the motor to return to the 180 position after a reset.
    (my familiarity with Arduino code is very limited and while I imagine this is within the realm of possibility I am not certain how to achieve this)
  3. Determine why there is a reset in the first place (could this be sloppy coding on my end, powering the board via USB, etc.)

– Any input regarding optimization of code or solutions to this issue would be greatly appreciated!

Here are some pictures of my setup for reference.



My code is

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define BLYNK_PRINT Serial  
#include <Servo.h>

char auth[] = "myth";

char ssid[] = "mynetwork";

char pass[] = "mypass";

Servo servo;

BLYNK_WRITE(V3) {

servo.write(param.asInt());

}

/* TIMER */
#include <SimpleTimer.h>
SimpleTimer timer;

/* DS18B20 Temperature Sensor */
#include <OneWire.h>
#include<DallasTemperature.h> 
#define ONE_WIRE_BUS 2 // DS18B20 on arduino pin2 corresponds to D4 on physical board
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
int temp_0;
int temp_1;

void setup() 
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  DS18B20.begin();
  timer.setInterval(60000L, getSendData);
  Serial.println(" ");
  Serial.println("Testing Dual Sensor data");
  servo.attach(15); 
}

void loop() 
{
  timer.run(); // Initiates SimpleTimer
  Blynk.run();
}

/***************************************************
 * Send Sensor data to Blynk
 **************************************************/
void getSendData()
{
  DS18B20.requestTemperatures(); 
  temp_0 = DS18B20.getTempFByIndex(0); // Sensor 0 will capture Temp in Celcius
  temp_1 = DS18B20.getTempFByIndex(1); // Sensor 0 will capture Temp in Fahrenheit

  Serial.print("Temp_0: ");
  Serial.print(temp_0);
  Serial.print(" oF . Temp_1: ");
  Serial.print(temp_1);
  Serial.println(" oF");
   
  Blynk.virtualWrite(1, temp_0); //virtual pin V1
  Blynk.virtualWrite(2, temp_1); //virtual pin V2
} 

We don’t really teach Programming 101 here, but suggestions we can give :stuck_out_tongue_winking_eye:

For the most simplistic method, simply include a specific servo positioning command in the Setup.

Or perhaps just resync V3 upon boot/reconnection to last recorded setting, also in setup or as a function.

There are almost endless other ways of doing similar checks, resets, syncing, etc… but that is where practice helps.

Great thank you very much for the suggestion. I was able to get it to work by adding the default position line of code. The other question I have is I would like to know when the board senses that the cabin is heating up.

I added a temperature >75 email notification, however I get an email every time it reads a temp greater than this. Is there a way to specify a range of temperatures for which I receive a temperature alert?

The code I am using now is

if(temp_0 >75) {
    Blynk.email("***", "ESP8266 Alert", "Temperature over 75F!");
    Blynk.notify("ESP8266 Alert - Temperature over 75F!");
  }

The answer lies with Control Structure, Comparison Operators and Boolean Operators.

You can set flag variables and use Control & Comparison structures, so that after one email is sent, no others are allowed… if Flag == 0 set Flag to 1 and send email, else if Flag == 1 do nothing more, etc. And you can also chose to clear/reset that flag with a timer.

And as you are already aware, Boolean is simply a way for looking for a set condition or range of data as required… if Temp < x || > y (if greater than x or less than y) then do z, etc.

So combining these into a function can give you a pre-set timeframe of when and how often to send out a notification email. You could even include the actual temp data in such email.

Check these out in the STRUCTURE - The elements of Arduino (C++) code portion of the Arduino reference page…

https://www.arduino.cc/reference/en/