Defender Arduino Design July 27, 2019 08:17PM | Registered: 4 years ago Posts: 27 |
Re: Defender Arduino Design July 27, 2019 09:25PM | Admin Registered: 7 years ago Posts: 164 |
Re: Defender Arduino Design July 28, 2019 10:28PM | Moderator Registered: 4 years ago Posts: 27 |
Re: Defender Arduino Design July 30, 2019 06:00PM | Registered: 4 years ago Posts: 23 |
Re: Defender Arduino Design July 31, 2019 12:28AM | Registered: 4 years ago Posts: 27 |
Re: Defender Arduino Design July 31, 2019 01:03AM | Registered: 4 years ago Posts: 27 |
//Mosquito Magnet Defender //Version 11 #include <util/delay.h> #include <Wire.h> #include <SD.h> #include <SPI.h> #include <dht.h> #include <OneWire.h> #include <DallasTemperature.h> // Temp sensor driver dht DHT; #define amb_temp 8// Pin ambient temp sensor is connected to #define igPin 9 #define fanPin 10 #define valvePin 11 #define sd_card 53 #define Temperature_ONE_WIRE_BUS 2 #include "SSD1306AsciiAvrI2c.h"//OLED Display driver and address #define OLED_ADDRESS 0x3C //set I2c Address, OLED specific SSD1306AsciiAvrI2c oled; OneWire oneWire(2); // DS18B20 temperaure sensors DallasTemperature sensors(&oneWire); float chk; int ignit =0; float start_time = 345.1;// total igiition cycle until timeout float lightoff = 20.1;// delta T (deg F) for ignition float temp = 0; float dTemp = 0; float aTemp; float a2Temp; unsigned long readsec; unsigned long initTime; int elapsed; int x = 0; int y = 0; int sec = 0; byte iMinute = 0; byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; String stat = "IINITIALIZE"; String stat2 = "unassigned"; 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(19200); initTime = millis()/1000; sensors.begin(); 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 "); myFile.println("loop#,dayofmonth,month,year,Hour,Min,sec,Loop#,stat,stat2,elapsed,temp,aTemp,dTemp,a2Temp,"); myFile.close(); } oled.begin(&Adafruit128x64, OLED_ADDRESS); //OLED Display init oled.setFont(Adafruit5x7); uint32_t m = micros(); oled.clear(); refresh_oled(); //Show initialize screen to check temp sensors delay(6000); pinMode(fanPin, OUTPUT);pinMode(igPin, OUTPUT);pinMode(valvePin, OUTPUT); analogWrite(fanPin, 400);// Set fan to low speed digitalWrite(igPin, LOW);// igniters off until called digitalWrite(valvePin, HIGH);//propane on ignite_cycle(); Serial.print("up top ignit ");Serial.println(ignit); if (ignit == 1){ stat2 = "Ignition successful"; Serial.println(stat2); } else { stat2 = "Ignition time out"; Serial.println(stat2); cooldown(); } analogWrite(fanPin, 1000);// Set fan to high speed initTime = millis()/1000;// reset seconds after ignition } void loop(){ stat = "TRAPPING"; lightoff = dTemp - 0.5;//provides margin from ambient while (dTemp >= lightoff){ // temp delta above ambient that shows ignition continues x++; Serial.println(x); //counts loops sec = millis()/1000;// provides run time to display elapsed = (sec - initTime); // provides current run time get_temps(); iMinute = minute; readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); 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(); if (iMinute != minute){ y++; myFile = SD.open("Magnet.txt", FILE_WRITE); myFile.print(y); 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(stat); myFile.print(","); myFile.print(stat2); myFile.print(","); myFile.print(elapsed); myFile.print(","); myFile.print(temp); myFile.print(","); myFile.print(aTemp); myFile.print(","); myFile.print(dTemp); myFile.print(",");myFile.print(DHT.humidity); myFile.println(","); myFile.close(); } refresh_oled(); } x = 0; cooldown(); } void ignite_cycle(){ myFile = SD.open("Magnet.txt", FILE_WRITE); myFile.println("elapsed,temp,aTemp,dTemp,a2Temp,stat,stat2");myFile.close(); stat = "IGNITION"; digitalWrite(igPin,HIGH); // start igniter Serial.println("inside ignite_cycle"); while (elapsed < start_time && dTemp < lightoff) { x++; readsec = millis()/1000; elapsed = (readsec - initTime); // provides run time get_temps(); Serial.print("dTemp "); Serial.println(dTemp); Serial.print("temp "); Serial.println(temp); Serial.print("aTemp "); Serial.println(aTemp); Serial.print("time "); Serial.println(elapsed); myFile = SD.open("Magnet.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(a2Temp); myFile.print(","); myFile.print(stat); myFile.print(","); myFile.println(stat2); myFile.close(); 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.println(); } digitalWrite(igPin,LOW); // stop igniter if (elapsed <= start_time){ignit = 1; // stat2 = "Good Ignition"; Serial.println(stat2);oled.println(stat2); delay(1000);} else {ignit = 2; stat2 = "No Ignition"; Serial.println(stat2);oled.println(stat2);} } // 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); // set DS3231 register pointer to 00h Wire.endTransmission(); Wire.requestFrom(DS3231_I2C_ADDRESS, 7); // request seven bytes of data from DS3231 starting from register 00h *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 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.print(" temp"); oled.println(" ambt humid."); oled.println(); oled.print(hour, DEC); oled.print(":"); oled.print(minute, DEC); oled.print(":"); oled.print(second, DEC);oled.println(" "); oled.print("Loop#");oled.print(x);oled.print(" Elapse:");oled.println(elapsed); oled.println(stat2);oled.print("Mosquito Rev7"); } void cooldown(){ stat = "COOLDOWN "; digitalWrite(valvePin, LOW);//propane off digitalWrite(igPin, LOW);//be sure ignition is off\ analogWrite(fanPin, 1000);// Set fan to high speed Serial.print(stat); Serial.println(stat2);Serial.print("dTemp "); Serial.println(dTemp); Serial.print("temp "); Serial.print(temp); Serial.print(" a2Temp"); Serial.println(a2Temp); x = 1; while (x < 900){// 60 = 2 minutes; cool down x++; Serial.print("loop "); Serial.print(x); Serial.print(" "); Serial.print(stat); Serial.println(stat2);Serial.print(" temp:"); Serial.print(temp); Serial.print(" aTemp:"); Serial.print(aTemp); Serial.print(" a2Temp:"); Serial.println(a2Temp); get_temps(); readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); myFile = SD.open("Magnet.txt", FILE_WRITE); myFile.print(x); 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(stat); myFile.print(","); myFile.print(stat2); myFile.print(","); myFile.print(elapsed); myFile.print(","); myFile.print(temp); myFile.print(","); myFile.print(aTemp); myFile.print(","); myFile.print(dTemp); myFile.print(",");myFile.print(a2Temp); myFile.println(","); myFile.close(); refresh_oled(); } 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; delay(2000); }
Re: Defender Arduino Design July 31, 2019 11:46PM | Registered: 4 years ago Posts: 23 |
Re: Defender Arduino Design August 01, 2019 01:04AM | Registered: 4 years ago Posts: 27 |
Re: Defender Arduino Design August 01, 2019 11:17AM | Registered: 4 years ago Posts: 23 |
Re: Defender Arduino Design August 01, 2019 07:05PM | Admin Registered: 7 years ago Posts: 164 |
Temp=129.9C (-1.8) at 5:58325 F=1 I=0 G=1 S=1 E=0 T=62.5C H=1.8% M=11248 (198/1013:4573) R=45~140 B=1.0 V=3.1Reading your Version 11 software, on power up, the unit executes the setup routine, which turns on the gas and fan low speed to commence ignition. The original Defender had an annoying 3 minute fan only phase to cool the unit and exhaust any residual propane. I concluded this was done as a safety measure, and to check the operation of the thermistor temperature sensor. These traps are so frustrating because of their multiple safety checks that, when they fail, prevent the operation of the trap. This plus the fact that the system does not include really any error reporting, so there was no way to tell what is happening, requiring costly and time consuming return for repair. No one can afford the downtime. I believe that more status and error checking is helpful in the interest of safety and troubleshooting. But the most important thing is that, in one way or another, if the trap has failed, and it may be unsafe or non-optimum to run it anyway without correcting the underlying problem. My trap has suffered from a lot of underlying problems, including lately. See the blog. In my case, I didn't want to worry about creating a potentially dangerous situation, so I included as many or more checks as in the original, at least as far as I could determine. For example, I start the igniter before the propane, to detect correct igniter operation. The Liberty has a separate circuit and amplifier to measure the igniter current, but that is not available on the Defender.
Re: Defender Arduino Design August 01, 2019 11:23PM | Registered: 4 years ago Posts: 27 |
#include <Wire.h> #define DS3231_I2C_ADDRESS 0x68 // Convert normal decimal numbers to binary coded decimal byte decToBcd(byte val) { return( (val/10*16) + (val%10) ); } // Convert binary coded decimal to normal decimal numbers byte bcdToDec(byte val) { return( (val/16*10) + (val%16) ); } void setup() { Wire.begin(); Serial.begin(19200); //DS3231 seconds, minutes, hours, day, date, month, year setDS3231time(50,52,19,1,24,6,19); } void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte month, byte year) { // sets time and date data to DS3231 Wire.beginTransmission(DS3231_I2C_ADDRESS); Wire.write(0); // set next input to start at the seconds register Wire.write(decToBcd(second)); // set seconds Wire.write(decToBcd(minute)); // set minutes Wire.write(decToBcd(hour)); // set hours Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday) Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31) Wire.write(decToBcd(month)); // set month Wire.write(decToBcd(year)); // set year (0 to 99) Wire.endTransmission(); } void readDS3231time(byte *second, byte *minute, byte *hour, byte *dayOfWeek, byte *dayOfMonth, byte *month, byte *year) { Wire.beginTransmission(DS3231_I2C_ADDRESS); Wire.write(0); // set DS3231 register pointer to 00h Wire.endTransmission(); Wire.requestFrom(DS3231_I2C_ADDRESS, 7); // request seven bytes of data from DS3231 starting from register 00h *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 displayTime() { byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; // retrieve data from DS3231 readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); // send it to the serial monitor Serial.print(hour, DEC); Serial.print(":"); Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC); Serial.print(" "); Serial.print(month, DEC); Serial.print("/"); Serial.print(dayOfMonth, DEC); Serial.print("/"); Serial.print(year, DEC); Serial.println(); } void loop() { displayTime(); // display the real-time clock data on the Serial Monitor, delay(1000); // every second }
Re: Defender Arduino Design August 02, 2019 10:21AM | Registered: 4 years ago Posts: 23 |
Re: Defender Arduino Design August 02, 2019 02:11PM | Admin Registered: 7 years ago Posts: 164 |
Temp=124.3C (0) at 5:37327 F=1 I=0 G=1 S=1 E=0 T=54.1C H=6.3% M=11288 (223/1012:5320) R=45~140 B=1.0 V=3.1The wiki has an explanation of the various fields. The server is a free demonstration device, which has service interruptions from time to time, which is perfect for testing software error handling (although I missed a failure event because of this). I guess I didn't want to have to stand around a problematic or even perfectly working trap with who knows many blood-thirsty mosquitos hovering within just a few feet. The software implements 8 commands via MQTT, plus several parameters (e.g., network, server, topic, etc.) via the trap's combination status/configuration web page.
Re: Defender Arduino Design August 04, 2019 07:22PM | Registered: 4 years ago Posts: 27 |
Re: Defender Arduino Design August 05, 2019 09:56AM | Admin Registered: 7 years ago Posts: 164 |
Re: Defender Arduino Design August 07, 2019 09:29PM | Registered: 4 years ago Posts: 27 |
Re: Defender Arduino Design August 08, 2019 01:03AM | Registered: 4 years ago Posts: 27 |
//Mosquito Magnet Defender //Version 12 5 August 2019 #include <util/delay.h> #include <Wire.h> #include <SD.h> #include <SPI.h> #include <dht.h> #include <OneWire.h> #include <DallasTemperature.h> // Temp sensor driver dht DHT; #define amb_temp 8// Pin ambient temp sensor is connected to #define igPin 9 #define fanPin 10 #define valvePin 11 #define sd_card 53 #define Temperature_ONE_WIRE_BUS 2 #include "SSD1306AsciiAvrI2c.h"//OLED Display driver and address #define OLED_ADDRESS 0x3C //set I2c Address, OLED specific SSD1306AsciiAvrI2c oled; OneWire oneWire(2); // DS18B20 temperaure sensors DallasTemperature sensors(&oneWire); bool start = false; float chk; int ignit =0; float start_time = 360.1;// total igiition cycle until timeout float lightoff = 20.1;// delta T (deg F) for ignition float temp = 0; float dTemp = 0; float aTemp; float a2Temp; unsigned long readsec; unsigned long initTime; int elapsed; int x = 0; int y = 0; int sec = 0; byte iMinute = 0; byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; String stat = "INITIALIZE"; String stat2 = "unassigned"; 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(19200); initTime = millis()/1000; 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 "); myFile.println("loop#,dayofmonth,month,year,Hour,Min,sec,stat,stat2,elapsed,temp,aTemp,dTemp,a2Temp,humidity"); myFile.close(); } oled.begin(&Adafruit128x64, OLED_ADDRESS); //OLED Display init oled.setFont(Adafruit5x7); uint32_t m = micros(); oled.clear(); pinMode(fanPin, OUTPUT);pinMode(igPin, OUTPUT);pinMode(valvePin, OUTPUT); analogWrite(fanPin, 175);// Set fan to low speed; range is 0-255 digitalWrite(igPin, LOW);// igniters off until called refresh_oled(); //Show initialize screen to check temp sensors delay(6000); } void loop(){ get_temps(); iMinute = minute; readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); if (hour <= 15 || hour > 3){ // sleep routine stat = "SLEEPING"; start = false; digitalWrite(valvePin, LOW);//propane off analogWrite(fanPin, 200);// Set fan to mid speed } else { // trapping routine if (!start){ignite_cycle();} // runs ignition if this is the first loop passed the start time stat = "TRAPPING"; if (dTemp < lightoff -1){shut_down();} // shuts down if the hot section is not above ambient by lightoff delta } file_write(); serial_write(); refresh_oled(); } void ignite_cycle(){ myFile = SD.open("Magnet.txt", FILE_WRITE); myFile.println("loop#,elapsed,temp,aTemp,dTemp,a2Temp,stat,stat2");myFile.close(); stat = "IGNITION"; digitalWrite(valvePin, HIGH);//propane on digitalWrite(igPin,HIGH); // start igniter Serial.println("inside ignite_cycle"); initTime = millis()/1000; x = 0; while (elapsed < start_time && dTemp < lightoff) { x++; readsec = millis()/1000; elapsed = (readsec - initTime); // provides run time get_temps(); Serial.print("IGNITION dTemp "); Serial.println(dTemp); Serial.print("temp "); Serial.println(temp); Serial.print("aTemp "); Serial.println(aTemp); Serial.print("time "); Serial.println(elapsed); myFile = SD.open("Magnet.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(a2Temp); myFile.print(","); myFile.print(stat); myFile.print(","); myFile.println(stat2); myFile.close(); 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.println(); } digitalWrite(igPin,LOW); // stop igniter if (elapsed <= start_time){ start = true; stat2 = "Good Ignition"; digitalWrite(igPin, LOW); analogWrite(fanPin, 200);// Set fan to mid speed Serial.println(stat2);oled.println(stat2); delay(1000);} else {start = false; 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); // request seven bytes of data from DS3231 starting from register 00h *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(){ stat = "SHUTDOWN "; digitalWrite(valvePin, LOW);//propane off digitalWrite(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(); serial_write(); iMinute = minute; readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); file_write(); refresh_oled(); } 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; delay(2000); } void file_write() { if (iMinute != minute){ y++; myFile = SD.open("Magnet.txt", FILE_WRITE); myFile.print(y); 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(stat); myFile.print(","); myFile.print(stat2); myFile.print(","); myFile.print(elapsed); myFile.print(","); myFile.print(temp); myFile.print(","); myFile.print(aTemp); myFile.print(","); myFile.print(dTemp); myFile.print(",");myFile.print(DHT.humidity); myFile.println(","); 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.print(" temp"); oled.println(" ambt humid."); oled.println(); oled.print(hour, DEC); oled.print(":"); oled.print(minute, DEC); oled.print(":"); oled.print(second, DEC);oled.println(" "); oled.print("Loop#");oled.print(x);oled.print(" Elapse:");oled.println(elapsed); oled.println(stat2); } 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(); }
Re: Defender Arduino Design August 08, 2019 10:46AM | Admin Registered: 7 years ago Posts: 164 |
Re: Defender Arduino Design August 11, 2019 06:24PM | Registered: 4 years ago Posts: 27 |
Re: Defender Arduino Design August 12, 2019 01:38PM | Admin Registered: 7 years ago Posts: 164 |
Re: Defender Arduino Design August 15, 2019 01:29AM | Registered: 4 years ago Posts: 27 |
Re: Defender Arduino Design August 23, 2019 02:10PM | Registered: 4 years ago Posts: 23 |
Re: Defender Arduino Design August 31, 2019 06:23PM | Registered: 4 years ago Posts: 27 |
Re: Defender Arduino Design August 31, 2019 07:04PM | Registered: 4 years ago Posts: 27 |
//Mosquito Magnet Defender //Version 14 11 August 2019 #include <util/delay.h> #include <Wire.h> #include <SD.h> #include <SPI.h> #include <dht.h> #include <OneWire.h> #include <DallasTemperature.h> // Temp sensor driver dht DHT; #define amb_temp 8// Pin ambient temp sensor is connected to #define igPin 9 #define fanPin 10 #define valvePin 11 #define sd_card 53 #define Temperature_ONE_WIRE_BUS 2 #include "SSD1306AsciiAvrI2c.h"//OLED Display driver and address #define OLED_ADDRESS 0x3C //set I2c Address, OLED specific SSD1306AsciiAvrI2c oled; OneWire oneWire(2); // DS18B20 temperaure sensors DallasTemperature sensors(&oneWire); bool start = false; float chk; int ignit =0; float start_time = 360.1;// total igiition cycle until timeout float lightoff = 10.1;// delta T (deg F) for ignition float temp = 0; float iTemp; float dTemp = 0; float aTemp; float a2Temp; unsigned long readsec; unsigned long initTime; int elapsed; int x = 0; int y = 0; int sec = 0; byte iMinute = 0; byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; String stat = "INITIALIZE"; String stat2 = "unassigned"; 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(19200); Serial.println("begin initialization"); pinMode(fanPin, OUTPUT);pinMode(igPin, OUTPUT);pinMode(valvePin, OUTPUT); analogWrite(fanPin, 170);// Set fan to mid speed; range is 0-255 digitalWrite(igPin, LOW);// 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 14"); myFile.println("loop#,dayofmonth,month,year,Hour,Min,sec,stat,stat2,temp,aTemp,dTemp,a2Temp,fan speed"); 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"); myFile.close(); oled.begin(&Adafruit128x64, OLED_ADDRESS); //OLED Display init oled.setFont(Adafruit5x7); uint32_t m = micros(); oled.clear(); refresh_oled(); //Show initialize screen to check temp sensors delay(6000); } void loop(){ get_temps(); iMinute = minute; readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); if ((hour >= 0 && hour < 6) || (hour > 9 && hour < 16)){ // sleep routine stat = "SLEEPING"; start = false; digitalWrite(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){shut_down();} // shuts down if the hot section is not above ambient by lightoff delta } file_write(); serial_write(); refresh_oled(); } void ignite_cycle(){ stat = "IGNITION"; digitalWrite(valvePin, HIGH);//propane on digitalWrite(igPin,HIGH); // start igniter Serial.println("inside ignite_cycle"); initTime = millis()/1000; get_temps(); iTemp = temp; 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.55 && elapsed > 45) { digitalWrite(igPin, LOW); // turn off igniter, stay in close monitoring loop til start_time is reached analogWrite(fanPin, 210);// Set fan to mid-high speed stat2 = "igniter off"; } Serial.print("IGNITION dTemp "); Serial.println(dTemp); Serial.print("temp "); Serial.println(temp); Serial.print("aTemp "); Serial.println(aTemp); Serial.print("time "); Serial.println(elapsed); 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.println(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.close(); file_write(); // also write to main file at the one minute interval 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.println(); } digitalWrite(igPin,LOW); // stop igniter if (elapsed <= start_time){ start = true; stat2 = "Good Ignition"; digitalWrite(igPin, LOW); analogWrite(fanPin, 210);// Set fan to mid-high speed Serial.println(stat2);oled.println(stat2); delay(1000);} else {start = false; 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); // request seven bytes of data from DS3231 starting from register 00h *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(){ stat = "SHUTDOWN "; digitalWrite(valvePin, LOW);//propane off digitalWrite(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(); serial_write(); iMinute = minute; readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); file_write(); refresh_oled(); } 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; delay(2000); } void file_write() { if (iMinute != minute){ y++; myFile = SD.open("Magnet.txt", FILE_WRITE); myFile.print(y); 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(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.println(","); 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.print("temp"); oled.println(" ambt humid."); oled.println(); oled.print(hour, DEC); oled.print(":"); oled.print(minute, DEC); oled.print(":"); oled.print(second, DEC);oled.println(" "); oled.print("Loop# ");oled.print(x);oled.print(" Elapsed:");oled.println(elapsed); oled.println(stat2); } 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(); }
Hot MosFETs September 02, 2019 12:03AM | Admin Registered: 7 years ago Posts: 164 |
Re: Defender Arduino Design September 07, 2019 01:29AM | Registered: 4 years ago Posts: 27 |
//Mosquito Magnet Defender //Version 15 4 Sept 2019 #include <Wire.h> #include <SD.h> #include <SPI.h> #include <dht.h> #include <OneWire.h> #include <DallasTemperature.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 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); bool start = false; float chk; int ignit =0; float start_time = 360;// total ignition cycle until timeout float lightoff = 10.1;// delta T (deg F) for ignition float temp = 0; float iTemp; float dTemp = 0; float aTemp; float a2Temp; unsigned long readsec; unsigned long 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"; 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(19200); initTime = millis()/1000; pinMode(fanPin, OUTPUT);pinMode(igPin, OUTPUT);pinMode(valvePin, OUTPUT); analogWrite(fanPin, 170);// Set fan to mid speed; range is 0-255 digitalWrite(igPin, LOW);// 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 V15"); myFile.println("loop#,hours,dayofmonth,month,year,hour,min,sec,stat,stat2,temp,aTemp,dTemp,a2Temp,total_hrs,propane_hrs"); 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"); myFile.close(); oled.begin(&Adafruit128x64, OLED_ADDRESS); //OLED Display init oled.setFont(Adafruit5x7); uint32_t m = micros(); oled.clear(); refresh_oled(); //Show initialize screen to check temp sensors delay(6000); } 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); if ((hours > 0.25 && hours < 6) || (hours > 10 && hours < 16.25)){ // sleep routine; sleeps late at night and mid day stat = "SLEEPING"; start = false; digitalWrite(valvePin, LOW);//propane off analogWrite(fanPin, 205);// Set fan to mid-high speed } else { // trapping routine if (!start){ignite_cycle();} // runs ignition if this is the first loop passed the start time stat = "TRAPPING"; if (dTemp < lightoff -1){shut_down();} // shuts down if the hot section is not above ambient by lightoff delta } file_write(); serial_write(); refresh_oled(); } void ignite_cycle(){ stat = "IGNITION"; digitalWrite(valvePin, HIGH);//propane on digitalWrite(igPin,HIGH); // start igniter Serial.println("inside ignite_cycle"); initTime = millis()/1000; get_temps(); iTemp = temp; 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.55 && elapsed > 45) { digitalWrite(igPin, LOW); // 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 dTemp "); Serial.println(dTemp); Serial.print("temp "); Serial.println(temp); Serial.print("aTemp "); Serial.println(aTemp); Serial.print("Elapsed "); Serial.println(elapsed); 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.println(second); 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); } digitalWrite(igPin,LOW); // stop igniter if (elapsed <= start_time){ start = true; x = 0; stat2 = "Good Ignition"; digitalWrite(igPin, LOW); analogWrite(fanPin, 210);// Set fan to mid-high speed Serial.println(stat2);oled.println(stat2); delay(1000);} else {start = false; 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); // request seven bytes of data from DS3231 starting from register 00h *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(){ stat = "SHUTDOWN "; digitalWrite(valvePin, LOW);//propane off digitalWrite(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(); } 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; 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 igniited 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(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(total_hours,2); myFile.print(","); myFile.print(propane_hours,2); myFile.println(","); 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("time dec_hr:");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.println(); }
Re: Defender Arduino Design September 28, 2019 12:52AM | Admin Registered: 7 years ago Posts: 164 |
Re: Defender Arduino Design October 03, 2019 02:03AM | Registered: 4 years ago Posts: 27 |
//Mosquito Magnet Defender //Version 16 29 Sept 2019 #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 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 = 360;// total igiition cycle until timeout float lightoff = 10.1;// delta T (deg F) for ignition float temp = 0; float iTemp; float dTemp = 0; float aTemp; float a2Temp; unsigned long readsec; unsigned long 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"; 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(19200); 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 digitalWrite(igPin, LOW);// 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 V16"); myFile.println("loop#,hours,dayofmonth,month,year,hour,min,sec,hours,stat,stat2,temp,amb_Temp,delta_Temp,a2Temp,total_hrs,propane_hrs,total_days, propane_days"); 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"); myFile.close(); oled.begin(&Adafruit128x64, OLED_ADDRESS); //OLED Display init oled.setFont(Adafruit5x7); uint32_t m = micros(); oled.clear(); refresh_oled(); //Show initialize screen to check temp sensors delay(6000); } 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); if ((hours > 0.75 && hours < 6) || (hours > 9.5 && hours < 16.25)){ // sleep routine; sleeps late at night and mid day stat = "SLEEPING"; start = false; digitalWrite(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){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"; digitalWrite(valvePin, HIGH);//propane on digitalWrite(igPin,HIGH); // start igniter Serial.println("inside ignite_cycle"); 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.55 && elapsed > 45) { digitalWrite(igPin, LOW); // 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 dTemp "); Serial.println(dTemp); Serial.print("temp "); Serial.println(temp); Serial.print("aTemp "); Serial.println(aTemp); Serial.print("Elapsed "); Serial.println(elapsed); 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.println(hours); 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(); } digitalWrite(igPin,LOW); // stop igniter if (elapsed <= start_time){ start = true; x = 0; stat2 = "Good Ignition"; digitalWrite(igPin, LOW); analogWrite(fanPin, 210);// Set fan to mid-high speed Serial.println(stat2);oled.println(stat2); delay(1000);} else {start = false; 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); // request seven bytes of data from DS3231 starting from register 00h *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(){ stat = "SHUTDOWN "; digitalWrite(valvePin, LOW);//propane off digitalWrite(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; 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 igniited 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(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.println(","); 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.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(";"); // last output needs to have the ";" }
Re: Defender Arduino Design October 03, 2019 03:20PM | Admin Registered: 7 years ago Posts: 164 |
Re: Defender Arduino Design October 07, 2019 11:52AM | Registered: 4 years ago Posts: 23 |