Advertisement
Guest User

Turn on and OFF my Semi-Truck's Coolant and Cabin Air Heater

a guest
Dec 9th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.57 KB | None | 0 0
  1.  
  2. // An Arduino Sketch to Turn on and OFF my Semi-Truck's Coolant and Cabin Air Heaters as well as Lock and Unlock my Truck's Doors.
  3.  
  4. byte ProHeatDigitalOutputPin = 11;      // Connected to a relay that pushes the 7 day timer's        On/Off button.
  5. byte EsparDigitalOutputPin = 10;        // Connected to a relay that pushes the DigiMax Controller's On/Off button.
  6.  
  7. boolean RelayOn = LOW;                  // My dumb retarded relay board has a reverse HIGH/LOW trigger.
  8. boolean RelayOff = HIGH;                // My dumb retarded relay board has a reverse HIGH/LOW trigger.
  9.  
  10. #include "SIM900.h"
  11. #include <SoftwareSerial.h>
  12. //If not used, is better to exclude the HTTP library,
  13. //for RAM saving.
  14. //If your sketch reboots itself proprably you have finished,
  15. //your memory available.
  16. //#include "inetGSM.h"
  17.  
  18. //If you want to use the Arduino functions to manage SMS, uncomment the lines below.
  19. #include "sms.h"
  20. SMSGSM sms;
  21.  
  22. //To change pins for Software Serial, use the two lines in GSM.cpp.
  23.  
  24. //GSM Shield for Arduino
  25. //www.open-electronics.org
  26. //this code is based on the example of Arduino Labs.
  27.  
  28. //Simple sketch to send and receive SMS.
  29.  
  30. int numdata;
  31. boolean started = false;
  32. char smsbuffer[160];
  33. char n[20];
  34.  
  35. void setup()
  36. {
  37.   digitalWrite (ProHeatDigitalOutputPin,  RelayOff); // Make sure the default relay status is OFF.
  38.   digitalWrite (EsparDigitalOutputPin,    RelayOff); // Make sure the default relay status is OFF.
  39.  
  40.   pinMode (ProHeatDigitalOutputPin, OUTPUT);
  41.   pinMode (EsparDigitalOutputPin,   OUTPUT);
  42.  
  43.   //Serial connection.
  44.   Serial.begin(9600);
  45.   Serial.println("GSM Shield testing.");
  46.  
  47.   //Start configuration of shield with baudrate.
  48.   //For http uses is raccomanded to use 4800 or slower.
  49.   if (gsm.begin(2400)) {
  50.     Serial.println("\nstatus=READY");
  51.     started = true;
  52.   } else Serial.println("\nstatus=IDLE");
  53.  
  54.   if (started) {
  55.     //Enable this two lines if you want to send an SMS.
  56.     //if (sms.SendSMS("3471234567", "Arduino SMS"))
  57.     //Serial.println("\nSMS sent OK");
  58.   }
  59.  
  60. };
  61.  
  62. void loop()
  63. {
  64.  
  65.   byte delayTime = 100;                   // Amount of time to press On/Off button
  66.   int EsparDigiMaxLED;                    // Espar Digi Max LED's     voltage represented as 1023 degrees of resolution.
  67.   int ProHeat7DayTimerLED;                // ProHeat 7Day Timer LED's voltage represented as 1023 degrees of resolution.
  68.   const byte ProHeatAnalogInputPin = A1;  // Arduino Analog ProHeat Sensor Input Pin
  69.   const byte EsparAnalogInputPin   = A0;  // Arduino Analog Espar   Sensor Input Pin
  70.   int threshold = 300;                    // LED voltage threshold represented as 1023 degrees of resolution.
  71.   //                                      // Min 432 / Max 454 when LED is on. Min 0 / Max 0 when LED is OFF.
  72.  
  73.   if (started) {
  74.     //Read if there are messages on SIM card and print them.
  75.     if (gsm.readSMS(smsbuffer, 160, n, 20)) {
  76.  
  77.       //______________________________________________________________________________________________________________________________________________________________
  78.  
  79.       //THIS IS THE LINE THAT DOES NOT DO ANYTHING. SMS TEXT OF ON DOES NOT DO ANYTHING.      
  80.       if ( strcmp(smsbuffer, "ON") == 0 ) { //Turns >>ON<< Espar Airtronic D2 Cabin Air Heater. http://www.esparofmichigan.com/img/d2.png
  81.         Serial.println ("Turn On Espar If smsbuffer value is ON");
  82.  
  83.         //check the green On/Off LED Status on the Espar DigiMax Controller. http://www.esparparts.com/images/photo.JPG
  84.         EsparDigiMaxLED = analogRead (EsparAnalogInputPin);                 // Sample Espar Digi Max LED's voltage with 1023 degrees of resolution.
  85.         Serial.print ("Espar DigiMax LED voltage is "); Serial.print (EsparDigiMaxLED * (5.0 / 1023.0)); Serial.println ("v");
  86.  
  87.         while (EsparDigiMaxLED < threshold) { //While the green LED indicator light is OFF (less than threshold value), do the following;
  88.           Serial.println ("While the green LED indicator light is OFF (0.00v):");
  89.  
  90.           // DigiMax Controller has momentary On/Off push button that toggles the On/Off status.
  91.           digitalWrite (EsparDigitalOutputPin, RelayOn); delay (delayTime);    // 'pushes'   the DigiMax On/Off button for (delayTime) sec
  92.           Serial.print ("Push Button for "); Serial.print (100.0 / delayTime); Serial.println (" Seconds");
  93.           digitalWrite (EsparDigitalOutputPin, RelayOff); delay (delayTime);   // 'releases' the DigiMax On/Off button for (delayTime) sec
  94.           Serial.print ("Release Button for "); Serial.print (100.0 / delayTime); Serial.println (" Seconds");
  95.  
  96.           // re-sample Espar DigiMax green On/Off LED Status
  97.           Serial.println ("Re-Sample Espar DigiMax LED value");
  98.           EsparDigiMaxLED = analogRead (EsparAnalogInputPin);                 // Sample Espar DigiMaxLED's voltage with 1023 degrees of resolution.
  99.           Serial.print ("Espar DigiMax LED voltage is "); Serial.print (EsparDigiMaxLED * (5.0 / 1023.0)); Serial.println ("v");
  100.           Serial.println ("   ");
  101.         }//end while
  102.       }//end if
  103.  
  104.       //______________________________________________________________________________________________________________________________________________________________
  105.  
  106.       if (smsbuffer [0] == 'B' || smsbuffer [0] == 'X') { //Turns >>ON<< ProHeat X45 Coolant Heater.http://www.proheat.com/images/X45PlusTruckKit.jpg
  107.         Serial.println ("Turn On ProHeat If smsbuffer [0] value is B or X");
  108.  
  109.         //check the red On/Off manual LED Status on the ProHeat 7 Day Digital Timer. http://www.proheat.com/images/optionalTimer.jpg
  110.         ProHeat7DayTimerLED = analogRead (ProHeatAnalogInputPin);                   // Sample ProHeat 7 Day Digital Timer's voltage with 1023 degrees of resolution.
  111.         Serial.print ("ProHeat 7Day Timer LED voltage is "); Serial.print (ProHeat7DayTimerLED * (5.0 / 1023.0)); Serial.println ("v");
  112.  
  113.         while (ProHeat7DayTimerLED < threshold) { //While the red manual LED indicator light is OFF (less than threshold value), do the following;
  114.           Serial.println ("While the red LED indicator light is OFF (0.00v): ");
  115.  
  116.           // ProHeat 7 Day Digital Timer has momentary On/Off push button that toggles the On/Off status.
  117.           digitalWrite (ProHeatDigitalOutputPin, RelayOn);  delay (delayTime);   // 'pushes'   the DigiMax On/Off button for (delayTime) sec
  118.           Serial.print ("Push Button for "); Serial.print (100.0 / delayTime); Serial.println (" Seconds");
  119.           digitalWrite (ProHeatDigitalOutputPin, RelayOff); delay (delayTime);   // 'releases' the DigiMax On/Off button for (delayTime) sec
  120.           Serial.print ("Release Button for "); Serial.print (100.0 / delayTime); Serial.println (" Seconds");
  121.  
  122.           // re-sample Espar DigiMax green On/Off LED Status
  123.           Serial.println ("Re-Sample 7Day TimerLED voltage");
  124.  
  125.           ProHeat7DayTimerLED = analogRead (ProHeatAnalogInputPin);                   // Sample ProHeat 7 Day Digital Timer's voltage with 1023 degrees of resolution.
  126.           Serial.print ("ProHeat 7Day Timer LED voltage is "); Serial.print (ProHeat7DayTimerLED * (5.0 / 1023.0)); Serial.println ("v");
  127.           Serial.println ("   ");
  128.         }//end while
  129.       }//end if
  130.  
  131.       //______________________________________________________________________________________________________________________________________________________________
  132.  
  133.       if (smsbuffer [0] == 'C' || smsbuffer [0] == 'Z') { //Turns >>OFF<< Espar Airtronic D2 Cabin Air Heater. http://www.esparofmichigan.com/img/d2.png
  134.         Serial.println ("Turn OFF Espar If smsbuffer [0] value is C or Z");
  135.  
  136.         //check the green On/Off LED Status on the Espar DigiMax Controller. http://www.esparparts.com/images/photo.JPG
  137.         EsparDigiMaxLED = analogRead (EsparAnalogInputPin);                 // Sample Espar DigiMaxLED's voltage with 1023 degrees of resolution.
  138.         Serial.print ("Espar DigiMax LED voltage is "); Serial.print (EsparDigiMaxLED * (5.0 / 1023.0)); Serial.println ("v");
  139.  
  140.  
  141.         while (EsparDigiMaxLED > threshold) { //While the green LED indicator light is ON (Greater than threshold value), do the following;
  142.           Serial.println ("While the green LED indicator light is on (about 2.00v):");
  143.  
  144.           // DigiMax Controller has momentary On/Off push button that toggles the On/Off status.
  145.           digitalWrite (EsparDigitalOutputPin, RelayOn); delay (delayTime);    // 'pushes'   the DigiMax On/Off button for (delayTime) sec
  146.           Serial.print ("Push Button for "); Serial.print (100.0 / delayTime); Serial.println (" Seconds");
  147.           digitalWrite (EsparDigitalOutputPin, RelayOff); delay (delayTime);   // 'releases' the DigiMax On/Off button for (delayTime) sec
  148.           Serial.print ("Release Button for "); Serial.print (100.0 / delayTime); Serial.println (" Seconds");
  149.  
  150.           // re-sample Espar DigiMax green On/Off LED Status
  151.           Serial.println ("Re-Sample Espar DigiMax LED value");
  152.           EsparDigiMaxLED = analogRead (EsparAnalogInputPin);                 // Sample Espar DigiMaxLED's voltage with 1023 degrees of resolution.
  153.           Serial.print ("Espar DigiMax LED voltage is "); Serial.print (EsparDigiMaxLED * (5.0 / 1023.0)); Serial.println ("v");
  154.           Serial.println ("   ");
  155.         }//end while
  156.       }//end if
  157.  
  158.       //______________________________________________________________________________________________________________________________________________________________
  159.  
  160.       if (smsbuffer [0] == 'D' || smsbuffer [0] == 'Z') { //Turns >>OFF<< ProHeat X45 Coolant Heater.http://www.proheat.com/images/X45PlusTruckKit.jpg
  161.         Serial.println ("Turn OFF ProHeat If smsbuffer [0] value is 40 or 60");
  162.  
  163.         //check the red On/Off manual LED Status ON the ProHeat 7 Day Digital Timer. http://www.proheat.com/images/optionalTimer.jpg
  164.         ProHeat7DayTimerLED = analogRead (ProHeatAnalogInputPin);                   // Sample ProHeat 7 Day Digital Timer's voltage with 1023 degrees of resolution.
  165.         Serial.print ("ProHeat 7Day Timer LED voltage is "); Serial.print (ProHeat7DayTimerLED * (5.0 / 1023.0)); Serial.println ("v");
  166.  
  167.         while (ProHeat7DayTimerLED > threshold) { //While the red manual LED indicator light is OFF (Greater than threshold value), do the following;
  168.           Serial.println ("While the red LED indicator light is ON (about 2.00v): ");
  169.  
  170.           // ProHeat 7 Day Digital Timer has momentary On/Off push button that toggles the On/Off status.
  171.           digitalWrite (ProHeatDigitalOutputPin, RelayOn);  delay (delayTime);   // 'pushes'   the DigiMax On/Off button for (delayTime) sec
  172.           Serial.print ("Push Button for "); Serial.print (100.0 / delayTime); Serial.println (" Seconds");
  173.           digitalWrite (ProHeatDigitalOutputPin, RelayOff); delay (delayTime);   // 'releases' the DigiMax On/Off button for (delayTime) sec
  174.           Serial.print ("Release Button for "); Serial.print (100.0 / delayTime); Serial.println (" Seconds");
  175.  
  176.           // re-sample Espar DigiMax green On/Off LED Status
  177.           Serial.println ("Re-Sample 7Day TimerLED voltage");
  178.  
  179.           ProHeat7DayTimerLED = analogRead (ProHeatAnalogInputPin);                   // Sample ProHeat 7 Day Digital Timer's voltage with 1023 degrees of resolution.
  180.           Serial.print ("ProHeat 7Day Timer LED voltage is "); Serial.print (ProHeat7DayTimerLED * (5.0 / 1023.0)); Serial.println ("v");
  181.           Serial.println ("   ");
  182.         }//end while
  183.       }//end if
  184.  
  185.       //______________________________________________________________________________________________________________________________________________________________
  186.     }
  187.     delay(1000);
  188.   }
  189. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement