Re: Defender Arduino Design October 10, 2019 03:23PM | Admin Registered: 7 years ago Posts: 164 |
New Season: Defender Arduino Design April 17, 2020 02:59PM | Moderator Registered: 4 years ago Posts: 27 |
Re: New Season Defender Arduino Design April 17, 2020 04:25PM | Admin Registered: 7 years ago Posts: 164 |
Quote
... You mentioned last year about doing a separate blog page - how could that work? You already have a very detailed page; would it be easy to add a separate thread?
Re: Defender Arduino Design May 17, 2020 12:18AM | Registered: 4 years ago Posts: 27 |
//Mosquito Magnet Defender
//Version 17 25 April 2020
#include <Wire.h>
#include <SD.h>
#include <SPI.h>
#include <dht.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SoftwareSerial.h>
#define amb_temp 8// ambient DHT temp/humidity
#define igPin 9 //igniter
#define fanPin 10 // fan
#define valvePin 11 // propane valve
#define sd_card 53
#define gasPin A0
#define thermistorPin A1
#define Temperature_ONE_WIRE_BUS 2 // good temp sensors
#include "SSD1306AsciiAvrI2c.h"//OLED Display driver and address
#define OLED_ADDRESS 0x3C //set I2c Address, OLED specific
dht DHT;
SSD1306AsciiAvrI2c oled;
OneWire oneWire(2); // DS18B20 temperaure sensors
DallasTemperature sensors(&oneWire);
SoftwareSerial BTserial(19,18); // RX | TX
bool start = false;
float chk;
int ignit =0;
float start_time = 300;// total igiition cycle until timeout; 300 seconds works
float lightoff = 10.1;// delta T (deg F) for ignition
float temp = 0;
float dTemp = 0;
float aTemp, iTemp,a2Temp;
unsigned long readsec,initTime;
int elapsed;
float propane_hours, total_hours, propane_days, total_days;
float x = 0, y = 0, z = 0;
int sec = 0;
byte iMinute = 0;
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
float hours, dec_hour, dec_min;
String stat = "INITIALIZE"; String stat2 = "unassigned";
float gas_sensor, thermistor;
File myFile;
#define DS3231_I2C_ADDRESS 0x68 // Real time clock
byte decToBcd(byte val){
return( (val/10*16) + (val%10) );}
byte bcdToDec(byte val){
return( (val/16*10) + (val%16) );}
void setup(){
Serial.begin(9600);
BTserial.begin(9600);
initTime = millis()/1000;
pinMode(fanPin, OUTPUT);pinMode(igPin, OUTPUT);pinMode(valvePin, OUTPUT);
analogWrite(fanPin, 170);// Set fan to mid speed; range is 0-255
analogWrite(igPin, 0);// igniters off until called
sensors.begin();
delay(2000);
get_temps();
pinMode(sd_card, OUTPUT); // SD card init
Serial.print("Initializing SD card...");
if (!SD.begin(53)) {
Serial.println("initialization failed!");
return; }
Serial.println("initialization done.");
myFile = SD.open("Magnet.txt", FILE_WRITE); // if the file opened, write to it:
if (myFile) {
myFile.println("initializing SD card, Mosquito Magnet Mega Defender V17 w/ gas sensor & thermistor");
myFile.println("loop#,hours,dayofmonth,month,year,hour,min,sec,hours,stat,stat2,temp,amb_Temp,delta_Temp,humidiy,a2Temp,total_hrs,propane_hrs,total_days, propane_days, gas_sensor,thermistor");
myFile.close();
myFile = SD.open("ignition.txt", FILE_WRITE);
myFile.println("loop#,elapsed,temp,aTemp,dTemp,iTemp,stat,stat2,dayofmonth,month,year,Hour,Min,sec,gas_sensor,thermistor");
myFile.close();
}
oled.begin(&Adafruit128x64, OLED_ADDRESS); //OLED Display initialize
oled.setFont(Adafruit5x7);
uint32_t m = micros();
oled.clear();
refresh_oled(); //Show initialize screen to check temp sensors
delay(6000);// wait 6 seconds to allow OLED screen to be read and settle gas sensor
}
void loop(){
get_temps();
iMinute = minute;
readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
dec_min = minute; dec_hour = hour;
hours = dec_hour + (dec_min/60);
//##################### || is "normal" between breaks ; using "&&" runs 24/7 for testing and troubleshooting
if ((hours > 0.50 && hours < 6.0) || (hours > 9.5 && hours < 16.25)){ // sleep routine; sleeps late at night and mid day
stat = "SLEEPING";
start = false;
analogWrite(valvePin, LOW);//propane off
analogWrite(fanPin, 205);// Set fan to mid-high speed
}
else { // trapping routine
if (!start){ignite_cycle();} // runs igition if this is the first loop passed the start time
stat = "TRAPPING";
if (dTemp < lightoff -1){stat = "SHUTDOWN ";shut_down();} // shuts down if the hot section is not above ambient by lightoff delta
}
file_write();
serial_write();
refresh_oled();
bluetooth();
}
void ignite_cycle(){
stat = "IGNITION";
Serial.println("inside ignite_cycle");
for (int zz = 0; zz<= 255; zz++) { // start igniter slowly, about 19 seconds to max power
analogWrite(igPin,zz); Serial.print(zz);
if (zz > 210){ digitalWrite(valvePin, HIGH); Serial.print(" propane on");}//propane on at about 15 seconds
delay(75);Serial.println();
}
initTime = millis()/1000;
get_temps();
iTemp = temp;
stat2 = "igniter on";
while (elapsed < start_time && dTemp < lightoff) {
x++;
iMinute = minute;
readsec = millis()/1000;
elapsed = (readsec - initTime); // provides run time
get_temps();
readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
if ((temp-iTemp) > 1.65 && elapsed > 45) {
analogWrite(igPin, 0); // turn off igniter, stay in ignition monitoring loop til start_time is reached
analogWrite(fanPin, 210);// Set fan to mid-high speed
stat2 = "igniter off";
}
Serial.print("IGNITION delta Temp "); Serial.println(temp-iTemp); Serial.print("temp "); Serial.println(temp);
Serial.print("aTemp "); Serial.println(aTemp); Serial.print("Elapsed "); Serial.println(elapsed);
Serial.print(" thermistor "); Serial.println(thermistor);
myFile = SD.open("ignition.txt", FILE_WRITE);
myFile.print(x); myFile.print(",");myFile.print(elapsed); myFile.print(","); myFile.print(temp); myFile.print(","); myFile.print(aTemp); myFile.print(",");myFile.print(dTemp);
myFile.print(","); myFile.print(iTemp); myFile.print(","); myFile.print(stat); myFile.print(","); myFile.print(stat2); myFile.print(","); myFile.print(dayOfMonth); myFile.print(","); myFile.print(month); myFile.print(",");myFile.print(year);
myFile.print(","); myFile.print(hour); myFile.print(","); myFile.print(minute); myFile.print(","); myFile.print(second); myFile.print(","); myFile.print(hours);myFile.print(","); myFile.print(gas_sensor);myFile.print(","); myFile.println(thermistor);
myFile.close();
file_write();
oled.clear(); oled.set2X();
oled.println(stat); oled.set1X();oled.println();
oled.print(temp); oled.print(" ");oled.println(dTemp);
oled.print("temp"); oled.println(" dTemp"); oled.println();
oled.print(" Ignition time: "); oled.println(elapsed);
oled.print("hours: ");oled.println(hours);
bluetooth();
}
analogWrite(igPin,LOW); // stop igniter if still on
if (elapsed <= start_time){
start = true; x = 0;
stat2 = "Good Ignition";
analogWrite(fanPin, 210);// Set fan to mid-high speed
Serial.println(stat2);oled.println(stat2); delay(1000);}
else {start = false;
stat = "SHUTDOWN ";
stat2 = "No Ignition"; Serial.println(stat2);oled.println(stat2);
shut_down(); }
}
// Real time clock setup
void readDS3231time(byte *second,byte *minute,byte *hour,
byte *dayOfWeek,byte *dayOfMonth,byte *month,byte *year){
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
*second = bcdToDec(Wire.read() & 0x7f); *minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f); *dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read()); *month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
void shut_down(){
digitalWrite(valvePin, LOW);//propane off
analogWrite(igPin, LOW);//be sure ignition is off
analogWrite(fanPin, 245);// Set fan to high speed
x = 0;
while (x < 2400){// 600 = 1 hr; cool down; dry out any trapped biters
x++;
get_temps();
iMinute = minute;
readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
dec_min = minute; dec_hour = hour;
hours = dec_hour + (dec_min/60);
serial_write();
file_write();
refresh_oled();
bluetooth();
}
analogWrite(fanPin, LOW);// turn fan off
stat = "HALT";
Serial.println(stat);
refresh_oled();
while(1); //forever loop
}
void get_temps(){
sensors.requestTemperatures();
temp = sensors.getTempFByIndex(1);// Hot location initial temp
aTemp = sensors.getTempFByIndex(0);// Ambient location initial temp
dTemp = temp - aTemp;
chk = DHT.read11(amb_temp);
a2Temp = DHT.temperature*1.8+32;
gas_sensor = analogRead(gasPin);
thermistor = analogRead(thermistorPin);
delay(2000);
}
void file_write() {
if (iMinute != minute){
y++;
total_hours = y/60; total_days = total_hours/24;
if (start){z++; propane_hours = z/60; propane_days = propane_hours/24;} // adds time only if ignited
myFile = SD.open("Magnet.txt", FILE_WRITE);
myFile.print(y); myFile.print(",");myFile.print(hours); myFile.print(","); myFile.print(dayOfMonth); myFile.print(","); myFile.print(month); myFile.print(",");myFile.print(year);
myFile.print(","); myFile.print(hour); myFile.print(","); myFile.print(minute); myFile.print(","); myFile.print(second); myFile.print(","); myFile.print(hours);myFile.print(",");
myFile.print(stat); myFile.print(","); myFile.print(stat2); myFile.print(",");
myFile.print(temp); myFile.print(","); myFile.print(aTemp); myFile.print(","); myFile.print(dTemp); myFile.print(",");myFile.print(DHT.humidity); myFile.print(",");myFile.print(a2Temp);
myFile.print(","); myFile.print(total_hours,2); myFile.print(","); myFile.print(propane_hours,2); myFile.print(","); myFile.print(total_days,3); myFile.print(","); myFile.print(propane_days,3);
`myFile.close();
}
}
void refresh_oled(){ //Push data to the OLED display
oled.clear(); oled.set2X(); oled.println(stat);oled.set1X();
oled.print(temp); oled.print(" ");oled.print(aTemp);oled.print(" ");oled.println(DHT.humidity);
oled.println(" temp ambt humid.");
//oled.print(hour, DEC); oled.print(":");oled.print(minute, DEC); oled.print(":");oled.println(second, DEC);
oled.print("propane days: ");oled.println(propane_days,3);
oled.print("total days: ");oled.println(total_days,3);
oled.print("current hour: ");oled.print(hours,2);
}
void serial_write(){
Serial.print(stat);Serial.print(" Temp = "); Serial.print(temp); Serial.print(" Amb Temp = "); Serial.print(aTemp);
Serial.print(" dTemp = "); Serial.print(dTemp);Serial.print(" Humidity = "); Serial.println(DHT.humidity);
Serial.print(hour, DEC); Serial.print(":"); Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC);Serial.println(" ");
Serial.print(month, DEC);Serial.print("/"); Serial.print(dayOfMonth, DEC);Serial.print("/"); Serial.print(year, DEC);Serial.println();
Serial.print("Hours: ");Serial.print(hours); Serial.print(" run hrs ");Serial.println(total_hours,3);Serial.print(" Thermistor: "); Serial.println(thermistor);Serial.println();
}
void bluetooth(){ //Push data through the HC-05 bluetooth module
BTserial.print(stat);BTserial.print(",");
BTserial.print(hours,2);BTserial.print(",");
BTserial.print(temp);BTserial.print(",");
BTserial.print(aTemp);BTserial.print(",");
BTserial.print(total_days,3);BTserial.print(",");
BTserial.print(propane_days,3);BTserial.print(",");
BTserial.print(gas_sensor,3);BTserial.print(";"); // last output needs to have the ";"
}
Re: Defender Arduino Design June 15, 2020 06:15PM | Registered: 3 years ago Posts: 1 |
Re: Defender Arduino Design June 20, 2020 06:56PM | Registered: 4 years ago Posts: 27 |
Re: CO2 Canister June 22, 2020 03:22PM | Admin Registered: 7 years ago Posts: 164 |
Re: Defender Arduino Design June 22, 2020 04:23PM | Registered: 3 years ago Posts: 10 |
Re: Mega Defender Rev1 June 22, 2020 04:35PM | Admin Registered: 7 years ago Posts: 164 |
Re: Defender Arduino Design June 25, 2020 01:55PM | Registered: 4 years ago Posts: 23 |
Propane Cost June 25, 2020 06:40PM | Admin Registered: 7 years ago Posts: 164 |
Re: Propane Cost June 30, 2020 02:20AM | Registered: 4 years ago Posts: 27 |
Re: Defender Arduino Design July 01, 2020 10:15AM | Registered: 3 years ago Posts: 10 |
Re: Defender Arduino Design July 03, 2020 12:19AM | Registered: 4 years ago Posts: 27 |
Re: MOSFET getting warm July 03, 2020 09:33PM | Admin Registered: 7 years ago Posts: 164 |
Re: Defender Arduino Design September 13, 2020 08:34PM | Registered: 4 years ago Posts: 27 |
// Mega Defender Mosquito Magnet //Version 20 12 Sept 2020 #include <Wire.h> #include <SD.h> #include <SPI.h> #include <dht.h> #include <OneWire.h> #include <DallasTemperature.h> #include <SoftwareSerial.h> #define amb_temp 8// ambient DHT temp/humidity #define igPin 9 //igniter #define fanPin 10 // fan #define valvePin 11 // propane valve #define sd_card 53 #define gasPin A0 #define thermistorPin A1 #define Temperature_ONE_WIRE_BUS 2 // good temp sensors #include "SSD1306AsciiAvrI2c.h"//OLED Display driver and address #define OLED_ADDRESS 0x3C //set I2c Address, OLED specific dht DHT; SSD1306AsciiAvrI2c oled; OneWire oneWire(2); // DS18B20 temperaure sensors DallasTemperature sensors(&oneWire); SoftwareSerial BTserial(19,18); // RX | TX String rev = "20"; // Version number bool start = false, disp = true; float chk; int cool_time = 0; float start_time = 310;// total igiition cycle until timeout; ~300 seconds works float lightoff = 8.1;// delta T (deg F) for ignition float temp = 0; float dTemp = 0; float aTemp, iTemp, a2Temp, cTemp; unsigned long readsec,initTime; int elapsed; float propane_hours, total_hours, propane_days, total_days; float x = 0, y = 0, z = 0; int sec = 0; byte iMinute = 0; byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; float hours, dec_hour, dec_min; String stat = "INITIALIZE"; String stat2 = "unassigned"; float gas_sensor, thermistor; File myFile; #define DS3231_I2C_ADDRESS 0x68 // Real time clock byte decToBcd(byte val){ return( (val/10*16) + (val%10) );} byte bcdToDec(byte val){ return( (val/16*10) + (val%16) );} void setup(){ Serial.begin(9600); BTserial.begin(9600); initTime = millis()/1000; pinMode(fanPin, OUTPUT);pinMode(igPin, OUTPUT);pinMode(valvePin, OUTPUT); digitalWrite(valvePin, LOW);//propane off analogWrite(fanPin, 170);// Set fan to mid speed; range is 0-255 analogWrite(igPin, 0);// igniters off until called sensors.begin(); //delay(2000); get_temps(); oled.begin(&Adafruit128x64, OLED_ADDRESS); //OLED Display initialize oled.setFont(Adafruit5x7); uint32_t m = micros(); oled.clear(); Serial.println("Mosquito Magnet Mega Defender V" + rev); pinMode(sd_card, OUTPUT); // SD card init Serial.print("Initializing SD card..."); if (!SD.begin(53)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); oled.clear(); oled.set2X(); oled.println("SD CARD OK"); oled.print(" REV " + rev);oled.set1X(); myFile = SD.open("Magnet.txt", FILE_WRITE); // if the file opened, write to it: if (myFile) { myFile.println("Mosquito Magnet Mega Defender V" + rev); myFile.println("loop#,hours,dayofmonth,month,year,hour,min,sec,hours,time,date,stat,stat2,temp,amb_Temp,delta_Temp,humidiy,a2Temp,total_hrs,propane_hrs,total_days, propane_days, gas_sensor,thermistor"); myFile.close(); myFile = SD.open("ignition.txt", FILE_WRITE); myFile.println("loop#,elapsed,temp,aTemp,dTemp,iTemp,stat,stat2,dayofmonth,month,year,Hour,Min,sec,gas_sensor,thermistor"); myFile.close(); } get_temps(); readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); Serial.print(hour, DEC); Serial.print(":"); Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC);Serial.println(" "); Serial.print(month, DEC);Serial.print("/"); Serial.print(dayOfMonth, DEC);Serial.print("/"); Serial.print(year, DEC);Serial.println(); iMinute = minute; refresh_oled(); //Show initialize screen to check temp sensors delay(1500);// wait to allow OLED screen to be read and settle gas sensor //### Detect short power interupt, hot section still warm if (dTemp > 100 || dTemp < -5) { // check for a temp sensor failure stat = "TEMP FAIL"; shut_down; } int cool_minute; cool_minute = iMinute;\ while (dTemp>8 && cool_time < 16){// run fan, cool down until hot temp is within 8 degs or 16 minutes has passed stat = "POWER LOSS"; analogWrite(fanPin, 255);// Set fan to max speed; range is 0-255 readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); refresh_oled; if (cool_minute != minute){cool_time ++; cool_minute = minute;} file_write(); serial_write(); refresh_oled();bluetooth(); } file_write(); serial_write(); refresh_oled();bluetooth(); } void loop(){ get_temps(); readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); iMinute = minute; dec_min = minute; dec_hour = hour; hours = dec_hour + (dec_min/60); //##################### || is "normal" between breaks ; using "&&" runs 24/7 for testing and troubleshooting if ((hours > 0.25 && hours < 6.25) || (hours > 9.75 && hours < 16.00)){ // sleep routine; sleeps late at night and mid day stat = "SLEEPING"; start = false; digitalWrite(valvePin, LOW);//propane off analogWrite(fanPin, 230);// Set fan to mid-high speed } else { // trapping routine if (!start){ignite_cycle();} // runs igition if this is the first loop pass the start time stat = "TRAPPING"; if (dTemp < lightoff -1){stat = "SHUTDOWN ";shut_down();} // shuts down if the hot section is not above ambient by lightoff delta } file_write(); serial_write(); refresh_oled(); bluetooth(); } void ignite_cycle(){ stat = "WARM UP "; Serial.println("inside ignite_cycle"); analogWrite(fanPin, 160);// Set fan to mid-low speed for ignition; range is 0-255 refresh_oled(); for (int zz = 0; zz<= 255; zz++) { // start igniter slowly, about 19 seconds to max power analogWrite(igPin,zz); Serial.print(zz); if (zz > 210){ digitalWrite(valvePin, HIGH); Serial.print(" propane on");}//propane on at about 15 seconds delay(75);Serial.println(); } stat = "POST IGN"; initTime = millis()/1000; get_temps(); iTemp = temp; stat2 = "igniter on"; refresh_oled(); Serial.println(" POST IGNITER ");delay(1500); while (elapsed <= start_time && dTemp < lightoff) { x++; stat= "IGNITION"; iMinute = minute; readsec = millis()/1000; elapsed = (readsec - initTime); // provides run time get_temps(); readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); Serial.print(" x= "); Serial.println(x); if ((temp-iTemp) > 1.65 && elapsed > 55) { analogWrite(igPin, 0); // turn off igniter, stay in ignition monitoring loop til start_time or lightoff temp is reached analogWrite(fanPin, 225);// Set fan to mid-high speed stat2 = "igniter off"; } Serial.print("IGNITION delta Temp "); Serial.println(temp-iTemp); Serial.print("temp "); Serial.println(temp); Serial.print("aTemp "); Serial.println(aTemp); Serial.print("Elapsed "); Serial.println(elapsed); Serial.print(" gas sensor "); Serial.println(gas_sensor); Serial.print(" thermistor "); Serial.println(thermistor); myFile = SD.open("ignition.txt", FILE_WRITE); myFile.print(x); myFile.print(",");myFile.print(elapsed); myFile.print(","); myFile.print(temp); myFile.print(","); myFile.print(aTemp); myFile.print(",");myFile.print(temp-iTemp); myFile.print(","); myFile.print(iTemp); myFile.print(","); myFile.print(stat); myFile.print(","); myFile.print(stat2); myFile.print(","); myFile.print(dayOfMonth); myFile.print(","); myFile.print(month); myFile.print(",");myFile.print(year); myFile.print(","); myFile.print(hour); myFile.print(","); myFile.print(minute); myFile.print(","); myFile.print(second); myFile.print(","); myFile.print(hours);myFile.print(","); myFile.print(gas_sensor);myFile.print(","); myFile.println(thermistor); myFile.close(); file_write(); oled.clear(); oled.set2X(); oled.println(stat); oled.set1X();oled.println(); oled.print(temp); oled.print(" ");oled.println(temp-iTemp); oled.print("temp"); oled.println(" Temp rise"); oled.println(); oled.print(" Ignition time: "); oled.println(elapsed); oled.print(stat2);oled.println(" "); bluetooth(); } analogWrite(igPin,0); // stop igniter if still on if (elapsed > start_time || dTemp < lightoff){ start = false; stat = "SHUTDOWN "; stat2 = "No Ignition"; Serial.println(stat2);oled.println(stat2); shut_down(); } else {start = true; x = 0; // good lightoff stat2 = "Good Ignition"; analogWrite(fanPin, 240);// Set fan to mid-high speed Serial.println("Ignition cyle complete. Good lightofff");oled.println(stat2); delay(1000);} } // Real time clock setup void readDS3231time(byte *second,byte *minute,byte *hour, byte *dayOfWeek,byte *dayOfMonth,byte *month,byte *year){ Wire.beginTransmission(DS3231_I2C_ADDRESS); Wire.write(0); Wire.endTransmission(); Wire.requestFrom(DS3231_I2C_ADDRESS, 7); *second = bcdToDec(Wire.read() & 0x7f); *minute = bcdToDec(Wire.read()); *hour = bcdToDec(Wire.read() & 0x3f); *dayOfWeek = bcdToDec(Wire.read()); *dayOfMonth = bcdToDec(Wire.read()); *month = bcdToDec(Wire.read()); *year = bcdToDec(Wire.read()); } void shut_down(){ digitalWrite(valvePin, LOW);//propane off analogWrite(igPin, 0);//be sure ignition is off analogWrite(fanPin, 215);// Set fan x = 0; while (x < 2400){// 600 = 1 hr; cool down; dry out any trapped biters x++; get_temps(); iMinute = minute; readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); dec_min = minute; dec_hour = hour; hours = dec_hour + (dec_min/60); serial_write(); file_write(); refresh_oled(); bluetooth(); } analogWrite(fanPin, LOW);// turn fan off stat = "HALT"; Serial.println(stat); refresh_oled(); while(1); //forever loop } void get_temps(){ sensors.requestTemperatures(); temp = sensors.getTempFByIndex(1);// Hot location temp aTemp = sensors.getTempFByIndex(0);// Ambient location cTemp = sensors.getTempFByIndex(2);// 3rd location temp dTemp = temp - aTemp; chk = DHT.read11(amb_temp); a2Temp = DHT.temperature*1.8+32; gas_sensor = analogRead(gasPin); thermistor = analogRead(thermistorPin); delay(1600); } void file_write() { if (iMinute != minute){ y++; total_hours = y/60; total_days = total_hours/24; if (start){z++; propane_hours = z/60; propane_days = propane_hours/24;} // adds time only if ignited myFile = SD.open("Magnet.txt", FILE_WRITE); myFile.print(y); myFile.print(",");myFile.print(hours); myFile.print(","); myFile.print(dayOfMonth); myFile.print(","); myFile.print(month); myFile.print(",");myFile.print(year); myFile.print(","); myFile.print(hour); myFile.print(","); myFile.print(minute); myFile.print(","); myFile.print(second); myFile.print(","); myFile.print(hours);myFile.print(","); myFile.print(hour); myFile.print(":"); if (minute < 10){myFile.print("0");} myFile.print(minute); myFile.print(","); myFile.print(month); myFile.print("/"); myFile.print(dayOfMonth); myFile.print("/");myFile.print(year); myFile.print(","); myFile.print(stat); myFile.print(","); myFile.print(stat2); myFile.print(","); myFile.print(temp); myFile.print(","); myFile.print(aTemp); myFile.print(","); myFile.print(dTemp); myFile.print(",");myFile.print(DHT.humidity); myFile.print(",");myFile.print(a2Temp); myFile.print(","); myFile.print(total_hours,2); myFile.print(","); myFile.print(propane_hours,2); myFile.print(","); myFile.print(total_days,3); myFile.print(","); myFile.print(propane_days,3); myFile.print(",");myFile.print(gas_sensor);myFile.print(","); myFile.println(thermistor);myFile.close(); } } void refresh_oled(){ //Push data to the OLED display oled.clear(); oled.set2X(); if (disp){ oled.println(stat);//oled.set1X(); oled.print(temp,1); oled.print(" ");oled.println(aTemp,1);//oled.print(" ");oled.println(DHT.humidity); //oled.println(" temp ambt humid."); oled.print("Days: ");oled.println(total_days,1); disp = false; } else { oled.println(stat); oled.print("P_days:");oled.println(propane_days,1); oled.print("Time:");oled.print(hour, DEC); oled.print(":"); oled.println(minute, DEC); disp = true; } } void serial_write(){ Serial.print(stat);Serial.print(" Temp = "); Serial.print(temp); Serial.print(" Amb Temp = "); Serial.print(aTemp); Serial.print(" dTemp = "); Serial.print(dTemp);Serial.print(" Humidity = "); Serial.println(DHT.humidity); Serial.print(hour, DEC); Serial.print(":"); Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC);Serial.println(" "); Serial.print(month, DEC);Serial.print("/"); Serial.print(dayOfMonth, DEC);Serial.print("/"); Serial.print(year, DEC);Serial.println(); Serial.print("Time: ");Serial.print(hours); Serial.print(" run hrs ");Serial.println(total_hours,3);Serial.print(" Thermistor: "); Serial.println(thermistor);Serial.println(); } void bluetooth(){ //Push data through the HC-05 bluetooth module BTserial.print(stat);BTserial.print(","); BTserial.print(hours,2);BTserial.print(","); BTserial.print(temp);BTserial.print(","); BTserial.print(aTemp);BTserial.print(","); BTserial.print(total_days,3);BTserial.print(","); BTserial.print(propane_days,3);BTserial.print(","); BTserial.print(gas_sensor,3);BTserial.print(";"); // last output needs to have the ";" }
Re: Three Mega Defenders September 14, 2020 04:20PM | Admin Registered: 7 years ago Posts: 164 |
Re: Defender Arduino Design November 01, 2020 05:38PM | Registered: 4 years ago Posts: 27 |
// Mega Defender Mosquito Magnet //Version 20 4 Oct 2020 #include <Wire.h> #include <SD.h> #include <SPI.h> #include <dht.h> #include <OneWire.h> #include <DallasTemperature.h> #include <SoftwareSerial.h> #define amb_temp 8// ambient DHT temp/humidity #define igPin 9 //igniter #define fanPin 10 // fan #define valvePin 11 // propane valve #define sd_card 53 #define gasPin A0 #define thermistorPin A1 #define Temperature_ONE_WIRE_BUS 2 // good temp sensors #include "SSD1306AsciiAvrI2c.h"//OLED Display driver and address #define OLED_ADDRESS 0x3C //set I2c Address, OLED specific dht DHT; SSD1306AsciiAvrI2c oled; OneWire oneWire(2); // DS18B20 temperaure sensors DallasTemperature sensors(&oneWire); SoftwareSerial BTserial(19,18); // RX | TX bool start = false, disp = true; String rev = "20"; // Version number float chk; int cool_time = 0; float start_time = 310;// total igiition cycle until timeout; ~300 seconds works float lightoff = 8.1;// delta T (deg F) for ignition float temp = 0; float dTemp = 0; float aTemp, iTemp, a2Temp, cTemp; unsigned long readsec,initTime; int elapsed; float propane_hours, total_hours, propane_days, total_days; float x = 0, y = 0, z = 0; int sec = 0; byte iMinute = 0; byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; float hours, dec_hour, dec_min; String stat = "INITIALIZE"; String stat2 = "unassigned"; float gas_sensor, thermistor; File myFile; #define DS3231_I2C_ADDRESS 0x68 // Real time clock byte decToBcd(byte val){ return( (val/10*16) + (val%10) );} byte bcdToDec(byte val){ return( (val/16*10) + (val%16) );} void setup(){ Serial.begin(9600); BTserial.begin(9600); initTime = millis()/1000; pinMode(fanPin, OUTPUT);pinMode(igPin, OUTPUT);pinMode(valvePin, OUTPUT); digitalWrite(valvePin, LOW);//propane off analogWrite(fanPin, 170);// Set fan to mid speed; range is 0-255 analogWrite(igPin, 0);// igniters off until called sensors.begin(); //delay(2000); get_temps(); oled.begin(&Adafruit128x64, OLED_ADDRESS); //OLED Display initialize oled.setFont(Adafruit5x7); uint32_t m = micros(); oled.clear(); Serial.println("Mosquito Magnet Mega Defender V" + rev); pinMode(sd_card, OUTPUT); // SD card init Serial.print("Initializing SD card..."); if (!SD.begin(53)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); oled.clear(); oled.set2X(); oled.println("SD CARD OK"); oled.print(" REV " + rev);oled.set1X(); myFile = SD.open("Magnet.txt", FILE_WRITE); // if the file opened, write to it: if (myFile) { myFile.println("Mosquito Magnet Mega Defender V" + rev); myFile.println("loop#,hours,dayofmonth,month,year,hour,min,sec,hours,time,date,stat,stat2,temp,amb_Temp,delta_Temp,humidiy,a2Temp,total_hrs,propane_hrs,total_days, propane_days, gas_sensor,thermistor"); myFile.close(); myFile = SD.open("ignition.txt", FILE_WRITE); myFile.println("loop#,elapsed,temp,aTemp,dTemp,iTemp,stat,stat2,dayofmonth,month,year,Hour,Min,sec,gas_sensor,thermistor"); myFile.close(); } get_temps(); readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); Serial.print(hour, DEC); Serial.print(":"); Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC);Serial.println(" "); Serial.print(month, DEC);Serial.print("/"); Serial.print(dayOfMonth, DEC);Serial.print("/"); Serial.print(year, DEC);Serial.println(); iMinute = minute; refresh_oled(); //Show initialize screen to check temp sensors delay(1500);// wait to allow OLED screen to be read and settle gas sensor //### Detect short power interupt, hot section still warm if (dTemp > 100 || dTemp < -5) { // check for a temp sensor failure stat = "TEMP FAIL"; shut_down; } int cool_minute; cool_minute = iMinute; while (dTemp>8 && cool_time < 16){// run fan, cool down until hot temp is within 8 degs or 16 minutes has passed stat = "POWER LOSS"; analogWrite(fanPin, 255);// Set fan to max speed; range is 0-255 readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); refresh_oled; if (cool_minute != minute){cool_time ++; cool_minute = minute;} file_write(); serial_write(); refresh_oled();bluetooth(); } file_write(); serial_write(); refresh_oled();bluetooth(); } void loop(){ get_temps(); iMinute = minute; readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); dec_min = minute; dec_hour = hour; hours = dec_hour + (dec_min/60); //##################### || is "normal" between breaks ; using "&&" runs 24/7 for testing and troubleshooting if ((hours > 0.25 && hours < 6.25) || (hours > 9.75 && hours < 16.00)){ // sleep routine; sleeps late at night and mid day stat = "SLEEPING"; start = false; digitalWrite(valvePin, LOW);//propane off analogWrite(fanPin, 230);// Set fan to mid-high speed } else { // trapping routine if (!start){ignite_cycle();} // runs igition if this is the first loop pass the start time stat = "TRAPPING"; if (dTemp < lightoff -1){stat = "SHUTDOWN ";shut_down();} // shuts down if the hot section is not above ambient by lightoff delta } file_write(); serial_write(); refresh_oled(); bluetooth(); } void ignite_cycle(){ stat = "WARM UP "; Serial.println("inside ignite_cycle"); analogWrite(fanPin, 160);// Set fan to mid-low speed for ignition; range is 0-255 refresh_oled(); for (int zz = 0; zz<= 255; zz++) { // start igniter slowly, about 19 seconds to max power analogWrite(igPin,zz); Serial.print(zz); if (zz > 210){ digitalWrite(valvePin, HIGH); Serial.print(" propane on");}//propane on at about 15 seconds delay(75);Serial.println(); } stat = "POST IGN"; initTime = millis()/1000; get_temps(); iTemp = temp; stat2 = "igniter on"; refresh_oled(); Serial.println(" POST IGNITER ");delay(1500); while (elapsed <= start_time && dTemp < lightoff) { x++; stat= "IGNITION"; iMinute = minute; readsec = millis()/1000; elapsed = (readsec - initTime); // provides run time get_temps(); readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); Serial.print(" x= "); Serial.println(x); if ((temp-iTemp) > 1.65 && elapsed > 55) { analogWrite(igPin, 0); // turn off igniter, stay in ignition monitoring loop til start_time or lightoff temp is reached analogWrite(fanPin, 225);// Set fan to mid-high speed stat2 = "igniter off"; } Serial.print("IGNITION delta Temp "); Serial.println(temp-iTemp); Serial.print("temp "); Serial.println(temp); Serial.print("aTemp "); Serial.println(aTemp); Serial.print("Elapsed "); Serial.println(elapsed); Serial.print(" gas sensor "); Serial.println(gas_sensor); Serial.print(" thermistor "); Serial.println(thermistor); myFile = SD.open("ignition.txt", FILE_WRITE); myFile.print(x); myFile.print(",");myFile.print(elapsed); myFile.print(","); myFile.print(temp); myFile.print(","); myFile.print(aTemp); myFile.print(",");myFile.print(temp-iTemp); myFile.print(","); myFile.print(iTemp); myFile.print(","); myFile.print(stat); myFile.print(","); myFile.print(stat2); myFile.print(","); myFile.print(dayOfMonth); myFile.print(","); myFile.print(month); myFile.print(",");myFile.print(year); myFile.print(","); myFile.print(hour); myFile.print(","); myFile.print(minute); myFile.print(","); myFile.print(second); myFile.print(","); myFile.print(hours);myFile.print(","); myFile.print(gas_sensor);myFile.print(","); myFile.println(thermistor); myFile.close(); file_write(); oled.clear(); oled.set2X(); oled.println(stat); oled.set1X();oled.println(); oled.print(temp); oled.print(" ");oled.println(temp-iTemp); oled.print("temp"); oled.println(" Temp rise"); oled.println(); oled.print(" Ignition time: "); oled.println(elapsed); oled.print(stat2);oled.println(" "); bluetooth(); } analogWrite(igPin,0); // stop igniter if still on if (elapsed > start_time || dTemp < lightoff){ start = false; stat = "SHUTDOWN "; stat2 = "No Ignition"; Serial.println(stat2);oled.println(stat2); shut_down(); } else {start = true; x = 0; // good lightoff stat2 = "Good Ignition"; analogWrite(fanPin, 240);// Set fan to mid-high speed Serial.println("Ignition cyle complete. Good lightofff");oled.println(stat2); delay(1000);} } // Real time clock setup void readDS3231time(byte *second,byte *minute,byte *hour, byte *dayOfWeek,byte *dayOfMonth,byte *month,byte *year){ Wire.beginTransmission(DS3231_I2C_ADDRESS); Wire.write(0); Wire.endTransmission(); Wire.requestFrom(DS3231_I2C_ADDRESS, 7); *second = bcdToDec(Wire.read() & 0x7f); *minute = bcdToDec(Wire.read()); *hour = bcdToDec(Wire.read() & 0x3f); *dayOfWeek = bcdToDec(Wire.read()); *dayOfMonth = bcdToDec(Wire.read()); *month = bcdToDec(Wire.read()); *year = bcdToDec(Wire.read()); } void shut_down(){ digitalWrite(valvePin, LOW);//propane off analogWrite(igPin, 0);//be sure ignition is off analogWrite(fanPin, 215);// Set fan x = 0; while (x < 2400){// 600 = 1 hr; cool down; dry out any trapped biters x++; get_temps(); iMinute = minute; readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); dec_min = minute; dec_hour = hour; hours = dec_hour + (dec_min/60); serial_write(); file_write(); refresh_oled(); bluetooth(); } analogWrite(fanPin, LOW);// turn fan off stat = "HALT"; Serial.println(stat); refresh_oled(); while(1); //forever loop } void get_temps(){ sensors.requestTemperatures(); temp = sensors.getTempFByIndex(1);// Hot location temp aTemp = sensors.getTempFByIndex(0);// Ambient location cTemp = sensors.getTempFByIndex(2);// 3rd location temp dTemp = temp - aTemp; chk = DHT.read11(amb_temp); a2Temp = DHT.temperature*1.8+32; gas_sensor = analogRead(gasPin); thermistor = analogRead(thermistorPin); delay(1600); } void file_write() { if (iMinute != minute){ y++; total_hours = y/60; total_days = total_hours/24; if (start){z++; propane_hours = z/60; propane_days = propane_hours/24;} // adds time only if ignited myFile = SD.open("Magnet.txt", FILE_WRITE); myFile.print(y); myFile.print(",");myFile.print(hours); myFile.print(","); myFile.print(dayOfMonth); myFile.print(","); myFile.print(month); myFile.print(",");myFile.print(year); myFile.print(","); myFile.print(hour); myFile.print(","); myFile.print(minute); myFile.print(","); myFile.print(second); myFile.print(","); myFile.print(hours);myFile.print(","); myFile.print(hour); myFile.print(":"); if (minute < 10){myFile.print("0");} myFile.print(minute); myFile.print(","); myFile.print(month); myFile.print("/"); myFile.print(dayOfMonth); myFile.print("/");myFile.print(year); myFile.print(","); myFile.print(stat); myFile.print(","); myFile.print(stat2); myFile.print(","); myFile.print(temp); myFile.print(","); myFile.print(aTemp); myFile.print(","); myFile.print(dTemp); myFile.print(",");myFile.print(DHT.humidity); myFile.print(",");myFile.print(a2Temp); myFile.print(","); myFile.print(total_hours,2); myFile.print(","); myFile.print(propane_hours,2); myFile.print(","); myFile.print(total_days,3); myFile.print(","); myFile.print(propane_days,3); myFile.print(",");myFile.print(gas_sensor);myFile.print(","); myFile.println(thermistor);myFile.close(); } } void refresh_oled(){ //Push data to the OLED display oled.clear(); oled.set2X(); if (disp){ oled.println(stat);//oled.set1X(); oled.print(temp,1); oled.print(" ");oled.println(aTemp,1);//oled.print(" ");oled.println(DHT.humidity); //oled.println(" temp ambt humid."); oled.print("Days: ");oled.println(total_days,2); disp = false; } else { oled.println(stat); oled.print("P_days:");oled.println(propane_days,2); oled.print("Time:");oled.print(hour, DEC); oled.print(":"); oled.println(minute, DEC); disp = true; } } void serial_write(){ Serial.print(stat);Serial.print(" Temp = "); Serial.print(temp); Serial.print(" Amb Temp = "); Serial.print(aTemp); Serial.print(" dTemp = "); Serial.print(dTemp);Serial.print(" Humidity = "); Serial.println(DHT.humidity); Serial.print(hour, DEC); Serial.print(":"); Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC);Serial.println(" "); Serial.print(month, DEC);Serial.print("/"); Serial.print(dayOfMonth, DEC);Serial.print("/"); Serial.print(year, DEC);Serial.println(); Serial.print("Time: ");Serial.print(hours); Serial.print(" run hrs ");Serial.println(total_hours,3);Serial.print(" Thermistor: "); Serial.println(thermistor);Serial.println(); } void bluetooth(){ //Push data through the HC-05 bluetooth module BTserial.print(stat);BTserial.print(","); BTserial.print(hours,2);BTserial.print(","); BTserial.print(temp);BTserial.print(","); BTserial.print(aTemp);BTserial.print(","); BTserial.print(total_days,3);BTserial.print(","); BTserial.print(propane_days,3);BTserial.print(","); BTserial.print(gas_sensor,3);BTserial.print(";"); // last output needs to have the ";" }
Re: Defender Arduino Design April 17, 2021 05:27AM | Registered: 3 years ago Posts: 1 |
Re: Defender ESP8266 Design April 20, 2021 11:44PM | Admin Registered: 7 years ago Posts: 164 |
Re: Defender Arduino Design April 25, 2021 06:27AM | Registered: 3 years ago Posts: 2 |
Liberty vs Defender April 25, 2021 03:14PM | Admin Registered: 7 years ago Posts: 164 |
Quote
... As far as I can tell, all of the components besides the motherboards of my 2 magnets are essentially identical, so in my head, the Liberty should work exactly the same, just in a different case. Is that accurate, or are there details I am missing?
Re: Liberty vs Defender April 26, 2021 04:36PM | Registered: 3 years ago Posts: 2 |
Re: Defender Arduino Design April 29, 2021 12:21AM | Registered: 4 years ago Posts: 27 |
Re: Defender Arduino Design May 31, 2021 12:27PM | Registered: 4 years ago Posts: 27 |
// Mega Defender Mosquito Magnet //Version 20A 12 May 2021 #include <Wire.h> #include <SD.h> #include <SPI.h> #include <dht.h> #include <OneWire.h> #include <DallasTemperature.h> #include <SoftwareSerial.h> #define amb_temp 8// ambient DHT temp/humidity #define igPin 9 //igniter #define fanPin 10 // fan #define valvePin 11 // propane valve #define sd_card 53 #define gasPin A0 #define thermistorPin A1 #define Temperature_ONE_WIRE_BUS 2 // good temp sensors #include "SSD1306AsciiAvrI2c.h"//OLED Display driver and address #define OLED_ADDRESS 0x3C //set I2c Address, OLED specific dht DHT; SSD1306AsciiAvrI2c oled; OneWire oneWire(2); // DS18B20 temperaure sensors DallasTemperature sensors(&oneWire); SoftwareSerial BTserial(19,18); // RX | TX bool start = false, disp = true; String rev = "20A"; // Version number float chk; int cool_time = 0; float start_time = 310;// total igiition cycle until timeout; ~300 seconds works float lightoff = 8.1;// delta T (deg F) for ignition float temp = 0; float dTemp = 0; float aTemp, iTemp, a2Temp, cTemp; unsigned long readsec,initTime; int elapsed; float propane_hours, total_hours, propane_days, total_days; float x = 0, y = 0, z = 0; int sec = 0; byte iMinute = 0; byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; float hours, dec_hour, dec_min; String stat = "INITIALIZE"; String stat2 = "unassigned"; float gas_sensor, thermistor; File myFile; #define DS3231_I2C_ADDRESS 0x68 // Real time clock byte decToBcd(byte val){ return( (val/10*16) + (val%10) );} byte bcdToDec(byte val){ return( (val/16*10) + (val%16) );} void setup(){ Serial.begin(9600); BTserial.begin(9600); initTime = millis()/1000; pinMode(fanPin, OUTPUT);pinMode(igPin, OUTPUT);pinMode(valvePin, OUTPUT); digitalWrite(valvePin, LOW);//propane off analogWrite(fanPin, 170);// Set fan to mid speed; range is 0-255 analogWrite(igPin, 0);// igniters off until called sensors.begin(); //delay(2000); get_temps(); oled.begin(&Adafruit128x64, OLED_ADDRESS); //OLED Display initialize oled.setFont(Adafruit5x7); uint32_t m = micros(); oled.clear(); Serial.println("Mosquito Magnet Mega Defender V" + rev); pinMode(sd_card, OUTPUT); // SD card init Serial.print("Initializing SD card..."); if (!SD.begin(53)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); oled.clear(); oled.set2X(); oled.println("SD CARD OK"); oled.print(" REV " + rev);oled.set1X(); myFile = SD.open("Magnet.txt", FILE_WRITE); // if the file opened, write to it: if (myFile) { myFile.println("Mosquito Magnet Mega Defender V" + rev); myFile.println("loop#,hours,dayofmonth,month,year,hour,min,sec,hours,time,date,stat,stat2,temp,amb_Temp,delta_Temp,humidiy,a2Temp,total_hrs,propane_hrs,total_days, propane_days, gas_sensor,thermistor"); myFile.close(); myFile = SD.open("ignition.txt", FILE_WRITE); myFile.println("loop#,elapsed,temp,aTemp,dTemp,iTemp,stat,stat2,dayofmonth,month,year,Hour,Min,sec,gas_sensor,thermistor"); myFile.close(); } get_temps(); readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); Serial.print(hour, DEC); Serial.print(":"); Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC);Serial.println(" "); Serial.print(month, DEC);Serial.print("/"); Serial.print(dayOfMonth, DEC);Serial.print("/"); Serial.print(year, DEC);Serial.println(); iMinute = minute; refresh_oled(); //Show initialize screen to check temp sensors delay(1500);// wait to allow OLED screen to be read and settle gas sensor //### Detect short power interupt, hot section still warm if (dTemp > 100 || dTemp < -5) { // check for a temp sensor failure stat = "TEMP FAIL"; shut_down; } int cool_minute; cool_minute = iMinute; while (dTemp>8 && cool_time < 16){// run fan, cool down until hot temp is within 8 degs or 16 minutes has passed stat = "POWER LOSS"; analogWrite(fanPin, 255);// Set fan to max speed; range is 0-255 readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); refresh_oled; if (cool_minute != minute){cool_time ++; cool_minute = minute;} file_write(); serial_write(); refresh_oled();bluetooth(); } file_write(); serial_write(); refresh_oled();bluetooth(); } void loop(){ get_temps(); iMinute = minute; readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); dec_min = minute; dec_hour = hour; hours = dec_hour + (dec_min/60); //##################### || is "normal" between breaks ; using "&&" runs 24/7 for testing and troubleshooting if ((hours > 0.25 && hours < 6.25) || (hours > 9.75 && hours < 16.00)){ // sleep routine; sleeps late at night and mid day stat = "SLEEPING"; start = false; digitalWrite(valvePin, LOW);//propane off analogWrite(fanPin, 230);// Set fan to mid-high speed } else { // trapping routine if (!start){ignite_cycle();} // runs igition if this is the first loop pass the start time stat = "TRAPPING"; if (dTemp < lightoff -1){stat = "SHUTDOWN ";shut_down();} // shuts down if the hot section is not above ambient by lightoff delta } file_write(); serial_write(); refresh_oled(); bluetooth(); } void ignite_cycle(){ stat = "WARM UP "; Serial.println("inside ignite_cycle"); analogWrite(fanPin, 160);// Set fan to mid-low speed for ignition; range is 0-255 refresh_oled(); for (int zz = 0; zz<= 255; zz++) { // start igniter slowly, about 19 seconds to max power analogWrite(igPin,zz); Serial.print(zz); if (zz > 210){ digitalWrite(valvePin, HIGH); Serial.print(" propane on");}//propane on at about 15 seconds delay(75);Serial.println(); } stat = "POST IGN"; initTime = millis()/1000; get_temps(); iTemp = temp; stat2 = "igniter on"; refresh_oled(); Serial.println(" POST IGNITER ");delay(1500); while (elapsed <= start_time && dTemp < lightoff) { x++; stat= "IGNITION"; iMinute = minute; readsec = millis()/1000; elapsed = (readsec - initTime); // provides run time get_temps(); readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); Serial.print(" x= "); Serial.println(x); if ((temp-iTemp) > 1.65 && elapsed > 55) { analogWrite(igPin, 0); // turn off igniter, stay in ignition monitoring loop til start_time or lightoff temp is reached analogWrite(fanPin, 225);// Set fan to mid-high speed stat2 = "igniter off"; } Serial.print("IGNITION delta Temp "); Serial.println(temp-iTemp); Serial.print("temp "); Serial.println(temp); Serial.print("aTemp "); Serial.println(aTemp); Serial.print("Elapsed "); Serial.println(elapsed); Serial.print(" gas sensor "); Serial.println(gas_sensor); Serial.print(" thermistor "); Serial.println(thermistor); myFile = SD.open("ignition.txt", FILE_WRITE); myFile.print(x); myFile.print(",");myFile.print(elapsed); myFile.print(","); myFile.print(temp); myFile.print(","); myFile.print(aTemp); myFile.print(",");myFile.print(temp-iTemp); myFile.print(","); myFile.print(iTemp); myFile.print(","); myFile.print(stat); myFile.print(","); myFile.print(stat2); myFile.print(","); myFile.print(dayOfMonth); myFile.print(","); myFile.print(month); myFile.print(",");myFile.print(year); myFile.print(","); myFile.print(hour); myFile.print(","); myFile.print(minute); myFile.print(","); myFile.print(second); myFile.print(","); myFile.print(hours);myFile.print(","); myFile.print(gas_sensor);myFile.print(","); myFile.println(thermistor); myFile.close(); file_write(); oled.clear(); oled.set2X(); oled.println(stat); oled.set1X();oled.println(); oled.print(temp); oled.print(" ");oled.println(temp-iTemp); oled.print("temp"); oled.println(" Temp rise"); oled.println(); oled.print(" Ignition time: "); oled.println(elapsed); oled.print(stat2);oled.println(" "); bluetooth(); } analogWrite(igPin,0); // stop igniter if still on if (elapsed > start_time || dTemp < lightoff){ start = false; stat = "SHUTDOWN "; stat2 = "No Ignition"; Serial.println(stat2);oled.println(stat2); shut_down(); } else {start = true; x = 0; // good lightoff stat2 = "Good Ignition"; analogWrite(fanPin, 240);// Set fan to mid-high speed Serial.println("Ignition cyle complete. Good lightofff");oled.println(stat2); delay(1000);} } // Real time clock setup void readDS3231time(byte *second,byte *minute,byte *hour, byte *dayOfWeek,byte *dayOfMonth,byte *month,byte *year){ Wire.beginTransmission(DS3231_I2C_ADDRESS); Wire.write(0); Wire.endTransmission(); Wire.requestFrom(DS3231_I2C_ADDRESS, 7); *second = bcdToDec(Wire.read() & 0x7f); *minute = bcdToDec(Wire.read()); *hour = bcdToDec(Wire.read() & 0x3f); *dayOfWeek = bcdToDec(Wire.read()); *dayOfMonth = bcdToDec(Wire.read()); *month = bcdToDec(Wire.read()); *year = bcdToDec(Wire.read()); } void shut_down(){ digitalWrite(valvePin, LOW);//propane off analogWrite(igPin, 0);//be sure ignition is off analogWrite(fanPin, 215);// Set fan x = 0; while (x < 2400){// 600 = 1 hr; cool down; dry out any trapped biters x++; get_temps(); iMinute = minute; readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); dec_min = minute; dec_hour = hour; hours = dec_hour + (dec_min/60); serial_write(); file_write(); refresh_oled(); bluetooth(); } analogWrite(fanPin, LOW);// turn fan off stat = "HALT"; Serial.println(stat); refresh_oled(); while(1); //forever loop } void get_temps(){ sensors.requestTemperatures(); temp = sensors.getTempFByIndex(1);// Hot location temp aTemp = sensors.getTempFByIndex(0);// Ambient location cTemp = sensors.getTempFByIndex(2);// 3rd location temp dTemp = temp - aTemp; chk = DHT.read11(amb_temp); a2Temp = DHT.temperature*1.8+32; gas_sensor = analogRead(gasPin); thermistor = analogRead(thermistorPin); delay(1600); } void file_write() { if (iMinute != minute){ y++; total_hours = y/60; total_days = total_hours/24; if (start){z++; propane_hours = z/60; propane_days = propane_hours/24;} // adds time only if ignited myFile = SD.open("Magnet.txt", FILE_WRITE); myFile.print(y); myFile.print(",");myFile.print(hours); myFile.print(","); myFile.print(dayOfMonth); myFile.print(","); myFile.print(month); myFile.print(",");myFile.print(year); myFile.print(","); myFile.print(hour); myFile.print(","); myFile.print(minute); myFile.print(","); myFile.print(second); myFile.print(","); myFile.print(hours);myFile.print(","); myFile.print(hour); myFile.print(":"); if (minute < 10){myFile.print("0");} myFile.print(minute); myFile.print(","); myFile.print(month); myFile.print("/"); myFile.print(dayOfMonth); myFile.print("/");myFile.print(year); myFile.print(","); myFile.print(stat); myFile.print(","); myFile.print(stat2); myFile.print(","); myFile.print(temp); myFile.print(","); myFile.print(aTemp); myFile.print(","); myFile.print(dTemp); myFile.print(",");myFile.print(DHT.humidity); myFile.print(",");myFile.print(a2Temp); myFile.print(","); myFile.print(total_hours,2); myFile.print(","); myFile.print(propane_hours,2); myFile.print(","); myFile.print(total_days,3); myFile.print(","); myFile.print(propane_days,3); myFile.print(",");myFile.print(gas_sensor);myFile.print(","); myFile.println(thermistor);myFile.close(); } } void refresh_oled(){ //Push data to the OLED display oled.clear(); oled.set2X(); if (disp){ oled.println(stat);//oled.set1X(); oled.print(temp,1); oled.print(" ");oled.println(aTemp,1);//oled.print(" ");oled.println(DHT.humidity); //oled.println(" temp ambt humid."); oled.print("Days: ");oled.println(total_days,2); disp = false; } else { oled.println(stat); oled.print("P_days:");oled.println(propane_days,2); oled.print("Time:");oled.print(hour, DEC); oled.print(":"); oled.println(minute, DEC); disp = true; } } void serial_write(){ Serial.print(stat);Serial.print(" Temp = "); Serial.print(temp); Serial.print(" Amb Temp = "); Serial.print(aTemp); Serial.print(" dTemp = "); Serial.print(dTemp);Serial.print(" Humidity = "); Serial.println(DHT.humidity); Serial.print(hour, DEC); Serial.print(":"); Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC);Serial.println(" "); Serial.print(month, DEC);Serial.print("/"); Serial.print(dayOfMonth, DEC);Serial.print("/"); Serial.print(year, DEC);Serial.println(); Serial.print("Time: ");Serial.print(hours); Serial.print(" run hrs ");Serial.println(total_hours,3);Serial.print(" Thermistor: "); Serial.println(thermistor);Serial.println(); } void bluetooth(){ //Push data through the HC-05 bluetooth module BTserial.print(stat);BTserial.print(","); BTserial.print(hours,2);BTserial.print(","); BTserial.print(temp);BTserial.print(","); BTserial.print(aTemp);BTserial.print(","); BTserial.print(total_days,3);BTserial.print(","); BTserial.print(propane_days,3);BTserial.print(","); BTserial.print(gas_sensor,3);BTserial.print(";"); // last output needs to have the ";" }
Re: Defender Arduino Design June 01, 2021 02:21PM | Registered: 3 years ago Posts: 152 |
Re: CO2 cartridges June 03, 2021 11:07PM | Admin Registered: 7 years ago Posts: 164 |
Re: CO2 cartridges June 04, 2021 02:34PM | Registered: 3 years ago Posts: 152 |
Re: CO2 cartridges June 05, 2021 12:27PM | Admin Registered: 7 years ago Posts: 164 |
Re: CO2 cartridges June 05, 2021 10:17PM | Registered: 3 years ago Posts: 152 |