Guest User

Untitled

a guest
Jun 15th, 2020
77
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SoftwareSerial.h>        //Libraries required for Serial communication, i²c communication, DHT11 and MLX90614
  2. char Received_SMS;              //Here we store the full received SMS (with phone sending number and date/time) as char
  3. short KOLIK_OK=-1;      //Used later it shows if there's the word "DHT"/"MLX" within the received SMS "-1" means they are not found
  4. String Data_SMS;               //Here's the SMS that we gonna send to the phone number, it may contain DHT data or MLX data
  5. SoftwareSerial sim800l(10,11); // MEGA TX10,RX11// UNO 2,3                   // RX,TX for Arduino and for the module it's TXD RXD, they should be inverted
  6. #include <LiquidCrystal_I2C.h>    
  7. LiquidCrystal_I2C lcd( 0x27, 20, 4 );
  8. #include <OneWire.h>
  9. #include <DallasTemperature.h>
  10. byte c_hacek[8] = {  //definice znaku c s háčkem = č
  11.   B01010,           // jednička svítí
  12.   B00100,           // nula nesvítí
  13.   B01110,
  14.   B10000,
  15.   B10000,
  16.   B10001,
  17.   B01110,
  18.   };
  19.  
  20. #include "HX711.h"
  21.  
  22. #define calibration_factor_1 23000//(-19300)(-42600.0) //This value is obtained using the SparkFun_HX711_Calibration sketch
  23. #define calibration_factor_2 23500//(-19300)(-42600.0) //This value is obtained using the SparkFun_HX711_Calibration sketch
  24. #define calibration_factor_3 23500//(-19300)(-42600.0) //This value is obtained using the SparkFun_HX711_Calibration sketch
  25. #define calibration_factor_4 -22300//(-19300)(-42600.0) //This value is obtained using the SparkFun_HX711_Calibration sketch
  26.  
  27. #define DOUT1  28
  28. #define CLK1  29
  29. const int Tare1 = 22;
  30. #define DOUT2  30
  31. #define CLK2  31
  32. const int Tare2 = 23;
  33. #define DOUT3  34
  34. #define CLK3  36
  35. const int Tare3 = 24;
  36. #define DOUT4  38
  37. #define CLK4  40
  38. const int Tare4 = 25;
  39.  
  40. HX711 scale1;
  41. HX711 scale2;
  42. HX711 scale3;
  43. HX711 scale4;
  44.  
  45. const int pinCidlaDS = 27;
  46. OneWire oneWireDS(pinCidlaDS);
  47. DallasTemperature senzoryDS(&oneWireDS);
  48. void setup()
  49. {
  50.    
  51.   Serial.begin(9600);
  52.   sim800l.begin(9600);   //Begin all the communications needed Arduino with PC serial and Arduino with all devices (SIM800L+DHT+MLX)
  53.   senzoryDS.begin();    
  54.   Serial.println("Starting ...");
  55.   delay(3000);         //Delay to let the module connect to network, can be removed
  56.   ReceiveMode();       //Calling the function that puts the SIM800L moduleon receiving SMS mode
  57.   lcd.init( );
  58.   lcd.backlight( );
  59.   lcd.createChar(1, c_hacek);   //odeslání definice 2. znaku
  60.  
  61. pinMode(53, OUTPUT);
  62.   digitalWrite(53, HIGH);
  63.  
  64.   scale1.begin(DOUT1, CLK1);
  65.   pinMode(Tare1, INPUT);
  66.   digitalWrite(Tare1, LOW);
  67.   scale1.set_scale(calibration_factor_1); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  68.   scale1.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
  69.  
  70.   scale2.begin(DOUT2, CLK2);
  71.   pinMode(Tare2, INPUT);
  72.   digitalWrite(Tare2, LOW);
  73.   scale2.set_scale(calibration_factor_2); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  74.   scale2.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
  75.  
  76.   scale3.begin(DOUT3, CLK3);
  77.   pinMode(Tare3, INPUT);
  78.   digitalWrite(Tare3, LOW);
  79.   scale3.set_scale(calibration_factor_3); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  80.   scale3.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
  81.  
  82.   scale4.begin(DOUT4, CLK4);
  83.   pinMode(Tare4, INPUT);
  84.   digitalWrite(Tare4, LOW);
  85.   scale4.set_scale(calibration_factor_4); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  86.   scale4.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
  87.  
  88.   //Serial.println("Readings:");
  89.  
  90. }
  91.  
  92. void loop() {
  93.  
  94.  /* Serial.print("Hmotnost: ");
  95.   Serial.print(scale1.get_units(),1); //scale.get_units() returns a float
  96.   Serial.print(" kg"); //You can change this to kg but you'll need to refactor the calibration_factor
  97.   Serial.println();
  98. */
  99.   senzoryDS.requestTemperatures();
  100.   //Serial.print(senzoryDS.getTempCByIndex(0));
  101.   lcd.clear() ;
  102.   lcd.setCursor(0,0);
  103.   lcd.print("V");
  104.   lcd.write(byte(1));    //zobrazí č (znak 1)
  105.   lcd.print("elstvo 1:");
  106.   lcd.setCursor(12,0);
  107.   lcd.print(scale1.get_units(),1); //scale.get_units() returns a float
  108.   lcd.print(" kg"); //You can change this to kg but you'll need to refactor the calibration_factor
  109.  
  110.   /*Serial.print("Hmotnost: ");
  111.   Serial.print(scale2.get_units(),1); //scale.get_units() returns a float
  112.   Serial.print(" kg"); //You can change this to kg but you'll need to refactor the calibration_factor
  113.   Serial.println();
  114.   */
  115.   lcd.setCursor(0,1);
  116.   lcd.print("V");
  117.   lcd.write(byte(1));    //zobrazí č (znak 1)
  118.   lcd.print("elstvo 2:");
  119.   lcd.setCursor(12,1);
  120.   lcd.print(scale2.get_units(),1); //scale.get_units() returns a float
  121.   lcd.print(" kg"); //You can change this to kg but you'll need to refactor the calibration_factor
  122.  
  123.   /*Serial.print("Hmotnost: ");
  124.   Serial.print(scale3.get_units(),1); //scale.get_units() returns a float
  125.   Serial.print(" kg"); //You can change this to kg but you'll need to refactor the calibration_factor
  126.   Serial.println();
  127.   */
  128.   lcd.setCursor(0,2);
  129.   lcd.print("V");
  130.   lcd.write(byte(1));    //zobrazí č (znak 1)
  131.   lcd.print("elstvo 3:");
  132.   lcd.setCursor(12,2);
  133.   lcd.print(scale3.get_units(),1); //scale.get_units() returns a float
  134.   lcd.print(" kg"); //You can change this to kg but you'll need to refactor the calibration_factor
  135.  
  136.   /*Serial.print("Hmotnost: ");
  137.   Serial.print(scale4.get_units(),1); //scale.get_units() returns a float
  138.   Serial.print(" kg"); //You can change this to kg but you'll need to refactor the calibration_factor
  139.   Serial.println();
  140.   */
  141.   lcd.setCursor(0,3);
  142.   lcd.print("V");
  143.   lcd.write(byte(1));    //zobrazí č (znak 1)
  144.   lcd.print("elstvo 4:");
  145.   lcd.setCursor(12,3);
  146.   lcd.print(scale4.get_units(),1); //scale.get_units() returns a float
  147.   lcd.print(" kg"); //You can change this to kg but you'll need to refactor the calibration_factor
  148.  
  149.   delay(1000);
  150.  
  151.   if (digitalRead(Tare1) == HIGH)
  152. {
  153. scale1.tare();
  154. }
  155. if (digitalRead(Tare2) == HIGH)
  156. {
  157. scale2.tare();
  158. }
  159. if (digitalRead(Tare3) == HIGH)
  160. {
  161. scale3.tare();
  162. }
  163. if (digitalRead(Tare4) == HIGH)
  164. {
  165. scale4.tare();
  166. }
  167.  
  168.   String RSMS;            
  169.    
  170.     while(sim800l.available()>0){       //When SIM800L sends something to the Arduino... problably the SMS received... if something else it's not a problem
  171.        
  172.     Received_SMS=sim800l.read();  //"char Received_SMS" is now containing the full SMS received
  173.     Serial.print(Received_SMS);   //Show it on the serial monitor (optional)    
  174.     RSMS.concat(Received_SMS);    //concatenate "char received_SMS" to RSMS which is "empty"
  175.     KOLIK_OK=RSMS.indexOf("KOLIK");   //And this is why we changed from char to String, it's to be able to use this function "indexOf"
  176.                                       //For example if found at the beginning it will give "0" after 1 character it will be "1"
  177.                                       //If it's not found it will give "-1", so the variables are integers
  178.        
  179.     }
  180.    
  181.   if(KOLIK_OK!=-1){                         //If "DHT" word is found within the SMS, it means that DHT_OK have other value than -1 so we can proceed
  182.     float a = scale1.get_units();        
  183.     float b = scale2.get_units();
  184.     float c = scale3.get_units();
  185.     float d = scale4.get_units();
  186.     float e = senzoryDS.getTempCByIndex(0);
  187.     Data_SMS = "HMOTNOST\nVcelstvo 1 = "+String(a,1)+" Kg"+" \nVcelstvo 2 ="+String(b,1)+" Kg"+" \nVcelstvo 3 ="+String(c,1)+" Kg"+" \nVcelstvo 4 ="+String(d,1)+" Kg"+" \nTeplota ="+String(e,1)+" stupnu Celsia";       //Prepare the SMS to send, it contains some strings like "DHT" "Temperature"...
  188.                                                                                          //And then the values read
  189.    
  190.     Send_Data();                      //This function set the sending SMS mode, prepare the phone number to which we gonna send, and send "Data_SMS" String
  191.     ReceiveMode();                   //Come back to Receving SMS mode and wait for other SMS
  192.    
  193.     KOLIK_OK=-1;                      //If the DHT is found the variable should be reset to -1 otherwise it will be kept as !=-1 and will send SMS over and over
  194.      
  195.                                      //And at this point I'm too lazy to reupload the code without it and test...
  196.  
  197.   }
  198. }
  199.  
  200.  
  201. void Serialcom() //This is used with ReceiveMode function, it's okay to use for tests with Serial monitor
  202. {
  203.   delay(500);
  204.   while(Serial.available())                                                                      
  205.   {
  206.     sim800l.write(Serial.read());//Forward what Serial received to Software Serial Port
  207.   }
  208.   while(sim800l.available())                                                                      
  209.   {
  210.     Serial.write(sim800l.read());//Forward what Software Serial received to Serial Port
  211.   }
  212. }
  213.  
  214. void ReceiveMode(){       //Set the SIM800L Receive mode
  215.  
  216.   sim800l.println("AT"); //If everything is Okay it will show "OK" on the serial monitor
  217.   Serialcom();
  218.   sim800l.println("AT+CMGF=1"); // Configuring TEXT mode
  219.   Serialcom();
  220.   sim800l.println("AT+CNMI=2,2,0,0,0"); //Configure the SIM800L on how to manage the Received SMS... Check the SIM800L AT commands manual
  221.   Serialcom();
  222. }
  223.  
  224. void Send_Data()
  225. {
  226.   Serial.println("Sending Data...");     //Displays on the serial monitor...Optional
  227.   sim800l.print("AT+CMGF=1\r");          //Set the module to SMS mode
  228.   delay(100);
  229.   sim800l.print("AT+CMGS=\"+420111111111\"\r");//Your phone number don't forget to include your country code example +212xxxxxxxxx"
  230.  delay(500);
  231.   sim800l.print(Data_SMS);  //This string is sent as SMS
  232.   delay(500);
  233.   sim800l.print((char)26);//Required to tell the module that it can send the SMS
  234.   delay(500);
  235.   sim800l.println();
  236.   Serial.println("Data Sent.");
  237.   delay(500);
  238.  
  239. }
RAW Paste Data