// Program za prikaz temeperature na LCD i slanje SMS-a // Autori Terry Kong , Mihajlovic Milenko , Vladimir Lapcevic i Sam Olesen #include #include #include #include #include #include SoftwareSerial M590(2, 3); // Rx, Tx byte led = 10; float temp1 = 0; float temp2 = 0; float temp3 = 0; float temp4 = 0; #define ONE_WIRE_BUS 8 #define I2C_ADDR 0x27 #define BACKLIGHT_PIN 3 #define En_pin 2 #define Rw_pin 1 #define Rs_pin 0 #define D4_pin 4 #define D5_pin 5 #define D6_pin 6 #define D7_pin 7 #define LED_OFF 0 #define LED_ON 1 OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin); // WP 1 DeviceAddress Probe1 = {0x28, 0xFF, 0x27, 0xAC, 0xB5, 0x16, 0x03, 0x77}; // DeviceAddress Probe2 = {0x28, 0x55, 0xB5, 0x27, 0x00, 0x00, 0x80, 0x3C}; // //DeviceAddress Probe3 = {0x28, 0x55, 0xC3, 0x27, 0x00, 0x00, 0x80, 0xCD}; // DeviceAddress Probe4 = {0x28, 0xDF, 0x65, 0x08, 0x00, 0x00, 0x80, 0xAD}; // //DeviceAddress Probe1 = { 0x28, 0xBF, 0x9A, 0x27, 0x00, 0x00, 0x80, 0x4D }; // DeviceAddress Probe3 = {0x28, 0xFF, 0x5B, 0xF7, 0xB4, 0x16, 0x05, 0x01}; // void setup() /****** SETUP: RUNS ONCE ******/ { delay(2000); pinMode(led, OUTPUT); digitalWrite(led, LOW); Serial.begin(19200); M590.begin(19200); Serial.println("GSM NEOWAY M590"); Serial.println(); Serial.println("Turn on AOH:"); M590.println("AT+CLIP=1"); // delay(100); Serial.println("Text format sms:"); M590.println("AT+CMGF=1"); // SMS tekst format delay(100); Serial.println("Mode GSM:"); M590.println("AT+CSCS=\"GSM\""); // GSM delay(100); //------- Initialize the Temperature measurement library-------------- sensors.begin(); // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster) sensors.setResolution(Probe1, 10); sensors.setResolution(Probe2, 10); sensors.setResolution(Probe3, 10); sensors.setResolution(Probe4, 10); // sensors.setResolution(Probe5, 10); //---------------- Initialize the lcd ------------------ lcd.begin(20, 4); // 20 characters, 4 lines // Switch on the backlight lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE); lcd.setBacklight(HIGH); } //--(end setup )--- void loop() /****** LOOP: RUNS CONSTANTLY ******/ { sensors.requestTemperatures(); // Send the command to get temperatures lcd.clear(); // Reset the display lcd.home(); lcd.backlight(); // Backlight ON if under program control lcd.setCursor(0, 0); // Start at character 0 on line 0 lcd.print("1:"); displayTemperature(Probe1); lcd.setCursor(0, 1); // Start at character 0 on line 1 lcd.print("2:"); displayTemperature(Probe2); lcd.setCursor(0, 2); // Start at character 0 on line 2 lcd.print("3:"); displayTemperature(Probe3); lcd.setCursor(0, 3); // Start at character 0 on line 3 lcd.print("4:"); displayTemperature(Probe4); temp1 = getTemperature(Probe1); temp2 = getTemperature(Probe2); temp3 = getTemperature(Probe3); temp4 = getTemperature(Probe4); ///////////////////////////////////////////////// // Program za konverziju promenljive float u niz znakova ////////////////////////////////////////// String MyString = ""; MyString += String(temp1, 2) + " T1 "; MyString += String(temp2, 2) + " T2 "; MyString += String(temp3, 2) + " T3 "; MyString += String(temp4, 2) + " T4 "; /////////////////////////////////////////////////////////////////////////////////////////////////// if (M590.available()) // { char ch = ' '; String val = ""; while (M590.available()) { ch = M590.read(); val += char(ch); // delay(5); } Serial.print("Neo send> "); Serial.println(val); //////////////////////////////////////////// if (val.indexOf("RING") > -1) // { if (val.indexOf("381641132255") > -1) // Broj sa koga se zove { Serial.println("Call my phone"); M590.println("ATH"); // Serial.println("Disconnection"); delay(3000); sms(MyString, String("+381641132255")); // } } /////////////////////////////////////// } delay(2000); } //--(end main loop )--- ///////////////////////////////////////////// /*-----( Declare User-written Functions )-----*/ void displayTemperature(DeviceAddress deviceAddress) { float tempC = sensors.getTempC(deviceAddress); if (tempC == -127.00) // Measurement failed or no device found { lcd.print("Greska"); } else { // lcd.print("C="); lcd.print(tempC); } } // End printTemperature float getTemperature(DeviceAddress deviceAddress) { float tempX = sensors.getTempC(deviceAddress); if (tempX == -127) { tempX = 0; } return tempX; } // End getTemperature void sms(String text, String phone) // { Serial.println("Start SMS send"); M590.println("AT+CMGS=\"+381641132255\""); // Broj na koji ide poruka delay(500); M590.print(text); delay(500); M590.print((char)26); delay(500); Serial.println("SMS send OK"); delay(2000); } // Nastavak sledi