Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* TDGino Engine Preheater Control
- Sketch to control a Webasto BBW46 engine preheater and to send sms status messages
- Created 2012
- by Bo Herrmannsen
- This code is in the public domain.
- The TDGino will need a extra input at pin 7, you will need 2 resistors and a optocoupler for this
- */
- #include <GSM.h>
- #include <OneWire.h>
- #include <DallasTemperature.h>
- GSM gsm;
- // Set pin numbers:
- const int powergsm = 77;
- const int ctsgsm = 39;
- const int rtsgsm = 29;
- const int dcdgsm = 27;
- const int dtrgsm = 28;
- const int reset = 35;
- const int ring = 34;
- const int ld1 = 25;
- const int ld2 = 26;
- const int stato = 76;
- const int rele1 = 36;
- const int rele2 = 37;
- const int sda = 20;
- const int scl = 21;
- const int in1 = 84;
- const int in2 = 83;
- const int in3 = 7;
- const int stddtmf = 14;
- const int q1dtmf = 72;
- const int q2dtmf = 73;
- const int q3dtmf = 74;
- const int q4dtmf = 75;
- const int puls = 62;
- const int sonda = 63;
- #define ONE_WIRE_BUS sonda // Data wire is plugged into port 2 on the Arduino
- OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
- DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
- DeviceAddress insideThermometer = { 0x28, 0xF3, 0x19, 0x33, 0x03, 0x00, 0x00, 0x9E }; // Array to hold address for inside thermometer
- DeviceAddress outsideThermometer = { 0x28, 0xA0, 0x34, 0xC3, 0x03, 0x00, 0x00, 0x8C }; // Array to hold address for outside thermometer
- float tempC=0;
- int Flame; // Status of pin connected to flame sensor (So we can detect if there is a flame or not)
- int FlameState; // Status of the flame sensor
- int Fan; // Status of pin connected to fan sensor (So we know when the fan is turned on by the heater)
- int FanState; // Status of the fan sensor
- int Heat; // Status of pin connected to heater(circulation pump) sensor (So we know if the heater is on - might seem odd but sometimes the heater stops early due to low fuel etc)
- int HeatState; // Status of the heater sensor
- char phone_num[20]; // Array for the phone number string
- char string[160]; // Array for the sms, max 160 char's
- char inchar;
- int temperature1;
- int temperature2;
- void setup()
- {
- // set the digital pin as output:
- pinMode(powergsm, OUTPUT);
- pinMode(rtsgsm, OUTPUT);
- pinMode(dtrgsm, OUTPUT);
- pinMode(reset, OUTPUT);
- pinMode(ld1, OUTPUT);
- pinMode(ld2, OUTPUT);
- pinMode(rele1, OUTPUT);
- pinMode(rele2, OUTPUT);
- pinMode(sda, OUTPUT);
- pinMode(scl, OUTPUT);
- digitalWrite(rele1, LOW); // Set relay state to avoid false heater start on power up
- digitalWrite(rele2, LOW);
- // set the digital pin as input:
- pinMode(ctsgsm, INPUT);
- pinMode(dcdgsm, INPUT);
- pinMode(ring, INPUT);
- pinMode(stato, INPUT);
- pinMode(in1, INPUT); // Flame on/off
- pinMode(in2, INPUT); // Heater on/off
- pinMode(in3, INPUT); // Cabin fan on/off
- pinMode(stddtmf, INPUT);
- pinMode(q1dtmf, INPUT);
- pinMode(q2dtmf, INPUT);
- pinMode(q3dtmf, INPUT);
- pinMode(q4dtmf, INPUT);
- pinMode(puls, INPUT); // Button on board, not used so far
- pinMode(sonda, INPUT); // DS18B20 one wire bus
- digitalWrite(ld1, HIGH); // Light up LED1 to tell we are starting up
- Serial.begin(9600); // Start serial port at 9600 bps
- Serial.println("System startup"); // Write on the serial/usb port that we are powering up
- gsm.TurnOn(115200); // Power the GSM module on
- Serial.println("GSM Module are powered up"); // Write on the serial/usb port that GSM Module are powered up
- gsm.InitParam(PARAM_SET_1); // Configure the module
- Serial.println("GSM Module are Configured"); // Write on the serial/usb port that GSM Module are configured
- gsm.Echo(1); // Enable AT echo
- Serial.println("AT+CMGF=1"); // Set sms mode to text
- delay(30000);
- Serial.println("AT+CNMI=3,3,0,0"); // Set module to send SMS data to serial out upon receipt
- delay(400);
- sensors.setResolution(insideThermometer, 12); // Set the resolution to 12 bit
- sensors.setResolution(outsideThermometer, 12);
- Serial.println("Temp. Sensors set to 12 Bit");
- FlameState = digitalRead(in1); // Read the initial states
- HeatState = digitalRead(in2);
- FanState = digitalRead(in3);
- digitalWrite(ld2, HIGH); // Light up LED2 to tell we are ready
- }
- void loop()
- {
- sensors.requestTemperatures();
- temperature1 = sensors.getTempC(insideThermometer); // Read temp and store it in variable
- temperature2 = sensors.getTempC(outsideThermometer);
- int response=0;
- Flame = digitalRead(in1); // Read value of flamesensor pin and store it in Flame
- Heat = digitalRead(in2); // Read value of fan sensor pin and store it in Fan
- Fan = digitalRead(in3); // Read value of flame sensor pin and store it in Flame
- // ******************************************************** Flame Sensor Section Start ******************************************************
- if (Flame != FlameState ) // The state has changed!
- {
- if (Flame == LOW)
- {
- sprintf(string,"Flame On");
- Serial.println(string);
- response=gsm.SendSMS("+45********",string); // +********** insert your telephone number
- Serial.print("response ");
- Serial.println(response);
- }
- else
- {
- sprintf(string,"Flame Off");
- Serial.println(string);
- response=gsm.SendSMS("+45********",string); // +********** insert your telephone number
- Serial.print("response ");
- Serial.println(response);
- }
- FlameState = Flame; // Save the new state in our variable
- }
- // ******************************************************** Flame Sensor Section End ********************************************************
- // ******************************************************** Fan Sensor Section Start ********************************************************
- if (Fan != FanState ) // The state has changed!
- {
- if (Fan == LOW)
- {
- sprintf(string,"Fan On");
- Serial.println(string);
- response=gsm.SendSMS("+45********",string); // +********** insert your telephone number
- Serial.print("response ");
- Serial.println(response);
- }
- else
- {
- sprintf(string,"Fan Off");
- Serial.println(string);
- response=gsm.SendSMS("+45********",string); // +********** insert your telephone number
- Serial.print("response ");
- Serial.println(response);
- }
- FanState = Fan; // Save the new state in our variable
- }
- // ******************************************************** Fan Sensor Section End ***********************************************************
- // ******************************************************** Heater Sensor Section Start ******************************************************
- if (Heat != HeatState ) // The state has changed!
- {
- if (Heat == LOW)
- {
- sprintf(string,"Heater On");
- Serial.println(string);
- response=gsm.SendSMS("+45********",string); // +********** insert your telephone number
- Serial.print("response ");
- Serial.println(response);
- }
- else
- {
- sprintf(string,"Heater Off");
- Serial.println(string);
- response=gsm.SendSMS("+45********",string); // +********** insert your telephone number
- Serial.print("response ");
- Serial.println(response);
- }
- HeatState = Heat; // Save the new state in our variable
- }
- // ******************************************************** Heater Sensor Section End ********************************************************
- // ********************************************************Incoming SMS Section Start ********************************************************
- if(Serial1.available() >0) // If a character comes in from the cellular module...
- {
- inchar=Serial1.read();
- if (inchar=='@') // Control char, if sms does start with anything else nothing happens and the sms is deleted
- {
- delay(10);
- inchar=Serial1.read();
- if (inchar=='a')
- {
- delay(10);
- inchar=Serial1.read();
- if (inchar=='0')
- {
- digitalWrite(rele1, LOW); // If 0 after a then turn relay1 off
- Serial.println("Relay1 Off");
- }
- else if (inchar=='1')
- {
- digitalWrite(rele1, HIGH); // If 1 after a then turn relay1 on
- Serial.println("Relay1 On");
- }
- }
- delay(10);
- if (inchar=='b')
- {
- delay(10);
- inchar=Serial1.read();
- if (inchar=='0')
- {
- digitalWrite(rele2, LOW); // If 0 after b then turn relay2 off
- Serial.println("Relay2 Off");
- }
- else if (inchar=='1')
- {
- digitalWrite(rele2, HIGH); // If 1 after a then turn relay2 on
- Serial.println("Relay2 On");
- }
- }
- delay(10);
- if (inchar=='t')
- {
- delay(10);
- inchar=Serial1.read();
- if (inchar=='0') // If 0 after t then send text with cabin temp
- {
- int temperature1dec=temperature1;
- int temperature1uni=(temperature1*100)-(temperature1dec*100);
- sprintf(string,"Kabinetemperatur %d.%d Grader",temperature1dec,temperature1uni); // Text to send when requesting cabin temp leave the %d.%d part
- Serial.println(string);
- response=gsm.SendSMS("+45********",string); // +********** insert your telephone number
- Serial.print("response ");
- Serial.println(response);
- }
- else if (inchar=='1') // If 1 after t then send text with coolant temp
- {
- int temperature2dec=temperature2;
- int temperature2uni=(temperature2*100)-(temperature2dec*100);
- sprintf(string,"Kolertemperatur %d.%d Grader",temperature2dec,temperature2uni); // Text to send when requesting coolant temp leave the %d.%d part
- Serial.println(string);
- response=gsm.SendSMS("+45********",string); //+********** insert your telephone number
- Serial.print("response ");
- Serial.println(response);
- }
- }
- Serial1.println("AT+CMGD=1,4"); // Delete all SMS
- }
- }
- }
- // ********************************************************Incoming SMS Section End ********************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement