Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h> //Libraries required for Serial communication, i²c communication, DHT11 and MLX90614
- char Received_SMS; //Here we store the full received SMS (with phone sending number and date/time) as char
- 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
- String Data_SMS; //Here's the SMS that we gonna send to the phone number, it may contain DHT data or MLX data
- 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
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd( 0x27, 20, 4 );
- #include <OneWire.h>
- #include <DallasTemperature.h>
- byte c_hacek[8] = { //definice znaku c s háčkem = č
- B01010, // jednička svítí
- B00100, // nula nesvítí
- B01110,
- B10000,
- B10000,
- B10001,
- B01110,
- };
- #include "HX711.h"
- #define calibration_factor_1 23000//(-19300)(-42600.0) //This value is obtained using the SparkFun_HX711_Calibration sketch
- #define calibration_factor_2 23500//(-19300)(-42600.0) //This value is obtained using the SparkFun_HX711_Calibration sketch
- #define calibration_factor_3 23500//(-19300)(-42600.0) //This value is obtained using the SparkFun_HX711_Calibration sketch
- #define calibration_factor_4 -22300//(-19300)(-42600.0) //This value is obtained using the SparkFun_HX711_Calibration sketch
- #define DOUT1 28
- #define CLK1 29
- const int Tare1 = 22;
- #define DOUT2 30
- #define CLK2 31
- const int Tare2 = 23;
- #define DOUT3 34
- #define CLK3 36
- const int Tare3 = 24;
- #define DOUT4 38
- #define CLK4 40
- const int Tare4 = 25;
- HX711 scale1;
- HX711 scale2;
- HX711 scale3;
- HX711 scale4;
- const int pinCidlaDS = 27;
- OneWire oneWireDS(pinCidlaDS);
- DallasTemperature senzoryDS(&oneWireDS);
- void setup()
- {
- Serial.begin(9600);
- sim800l.begin(9600); //Begin all the communications needed Arduino with PC serial and Arduino with all devices (SIM800L+DHT+MLX)
- senzoryDS.begin();
- Serial.println("Starting ...");
- delay(3000); //Delay to let the module connect to network, can be removed
- ReceiveMode(); //Calling the function that puts the SIM800L moduleon receiving SMS mode
- lcd.init( );
- lcd.backlight( );
- lcd.createChar(1, c_hacek); //odeslání definice 2. znaku
- pinMode(53, OUTPUT);
- digitalWrite(53, HIGH);
- scale1.begin(DOUT1, CLK1);
- pinMode(Tare1, INPUT);
- digitalWrite(Tare1, LOW);
- scale1.set_scale(calibration_factor_1); //This value is obtained by using the SparkFun_HX711_Calibration sketch
- scale1.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
- scale2.begin(DOUT2, CLK2);
- pinMode(Tare2, INPUT);
- digitalWrite(Tare2, LOW);
- scale2.set_scale(calibration_factor_2); //This value is obtained by using the SparkFun_HX711_Calibration sketch
- scale2.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
- scale3.begin(DOUT3, CLK3);
- pinMode(Tare3, INPUT);
- digitalWrite(Tare3, LOW);
- scale3.set_scale(calibration_factor_3); //This value is obtained by using the SparkFun_HX711_Calibration sketch
- scale3.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
- scale4.begin(DOUT4, CLK4);
- pinMode(Tare4, INPUT);
- digitalWrite(Tare4, LOW);
- scale4.set_scale(calibration_factor_4); //This value is obtained by using the SparkFun_HX711_Calibration sketch
- scale4.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
- //Serial.println("Readings:");
- }
- void loop() {
- /* Serial.print("Hmotnost: ");
- Serial.print(scale1.get_units(),1); //scale.get_units() returns a float
- Serial.print(" kg"); //You can change this to kg but you'll need to refactor the calibration_factor
- Serial.println();
- */
- senzoryDS.requestTemperatures();
- //Serial.print(senzoryDS.getTempCByIndex(0));
- lcd.clear() ;
- lcd.setCursor(0,0);
- lcd.print("V");
- lcd.write(byte(1)); //zobrazí č (znak 1)
- lcd.print("elstvo 1:");
- lcd.setCursor(12,0);
- lcd.print(scale1.get_units(),1); //scale.get_units() returns a float
- lcd.print(" kg"); //You can change this to kg but you'll need to refactor the calibration_factor
- /*Serial.print("Hmotnost: ");
- Serial.print(scale2.get_units(),1); //scale.get_units() returns a float
- Serial.print(" kg"); //You can change this to kg but you'll need to refactor the calibration_factor
- Serial.println();
- */
- lcd.setCursor(0,1);
- lcd.print("V");
- lcd.write(byte(1)); //zobrazí č (znak 1)
- lcd.print("elstvo 2:");
- lcd.setCursor(12,1);
- lcd.print(scale2.get_units(),1); //scale.get_units() returns a float
- lcd.print(" kg"); //You can change this to kg but you'll need to refactor the calibration_factor
- /*Serial.print("Hmotnost: ");
- Serial.print(scale3.get_units(),1); //scale.get_units() returns a float
- Serial.print(" kg"); //You can change this to kg but you'll need to refactor the calibration_factor
- Serial.println();
- */
- lcd.setCursor(0,2);
- lcd.print("V");
- lcd.write(byte(1)); //zobrazí č (znak 1)
- lcd.print("elstvo 3:");
- lcd.setCursor(12,2);
- lcd.print(scale3.get_units(),1); //scale.get_units() returns a float
- lcd.print(" kg"); //You can change this to kg but you'll need to refactor the calibration_factor
- /*Serial.print("Hmotnost: ");
- Serial.print(scale4.get_units(),1); //scale.get_units() returns a float
- Serial.print(" kg"); //You can change this to kg but you'll need to refactor the calibration_factor
- Serial.println();
- */
- lcd.setCursor(0,3);
- lcd.print("V");
- lcd.write(byte(1)); //zobrazí č (znak 1)
- lcd.print("elstvo 4:");
- lcd.setCursor(12,3);
- lcd.print(scale4.get_units(),1); //scale.get_units() returns a float
- lcd.print(" kg"); //You can change this to kg but you'll need to refactor the calibration_factor
- delay(1000);
- if (digitalRead(Tare1) == HIGH)
- {
- scale1.tare();
- }
- if (digitalRead(Tare2) == HIGH)
- {
- scale2.tare();
- }
- if (digitalRead(Tare3) == HIGH)
- {
- scale3.tare();
- }
- if (digitalRead(Tare4) == HIGH)
- {
- scale4.tare();
- }
- String RSMS;
- while(sim800l.available()>0){ //When SIM800L sends something to the Arduino... problably the SMS received... if something else it's not a problem
- Received_SMS=sim800l.read(); //"char Received_SMS" is now containing the full SMS received
- Serial.print(Received_SMS); //Show it on the serial monitor (optional)
- RSMS.concat(Received_SMS); //concatenate "char received_SMS" to RSMS which is "empty"
- 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"
- //For example if found at the beginning it will give "0" after 1 character it will be "1"
- //If it's not found it will give "-1", so the variables are integers
- }
- 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
- float a = scale1.get_units();
- float b = scale2.get_units();
- float c = scale3.get_units();
- float d = scale4.get_units();
- float e = senzoryDS.getTempCByIndex(0);
- 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"...
- //And then the values read
- Send_Data(); //This function set the sending SMS mode, prepare the phone number to which we gonna send, and send "Data_SMS" String
- ReceiveMode(); //Come back to Receving SMS mode and wait for other SMS
- 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
- //And at this point I'm too lazy to reupload the code without it and test...
- }
- }
- void Serialcom() //This is used with ReceiveMode function, it's okay to use for tests with Serial monitor
- {
- delay(500);
- while(Serial.available())
- {
- sim800l.write(Serial.read());//Forward what Serial received to Software Serial Port
- }
- while(sim800l.available())
- {
- Serial.write(sim800l.read());//Forward what Software Serial received to Serial Port
- }
- }
- void ReceiveMode(){ //Set the SIM800L Receive mode
- sim800l.println("AT"); //If everything is Okay it will show "OK" on the serial monitor
- Serialcom();
- sim800l.println("AT+CMGF=1"); // Configuring TEXT mode
- Serialcom();
- 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
- Serialcom();
- }
- void Send_Data()
- {
- Serial.println("Sending Data..."); //Displays on the serial monitor...Optional
- sim800l.print("AT+CMGF=1\r"); //Set the module to SMS mode
- delay(100);
- sim800l.print("AT+CMGS=\"+420111111111\"\r");//Your phone number don't forget to include your country code example +212xxxxxxxxx"
- delay(500);
- sim800l.print(Data_SMS); //This string is sent as SMS
- delay(500);
- sim800l.print((char)26);//Required to tell the module that it can send the SMS
- delay(500);
- sim800l.println();
- Serial.println("Data Sent.");
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement