Skip to content

Instantly share code, notes, and snippets.

@Blank1611
Created May 23, 2020 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Blank1611/23e6d414cbbd100db08ba4fb71c08ab4 to your computer and use it in GitHub Desktop.
Save Blank1611/23e6d414cbbd100db08ba4fb71c08ab4 to your computer and use it in GitHub Desktop.
#include <SoftwareSerial.h>
#define FLOAT_SENSOR 4 // the number of the float sensor
//#define FLOAT_SENSORE 3
//#define LED 13 // the number of the LED pin
SoftwareSerial mySerial(11, 9); //gsm pin
unsigned char flag = false; //flag for checking and alternating condition, false for empty and true for full
void setup()
{
// initialize the LED pin as an output:
//pinMode(LED, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(FLOAT_SENSOR, INPUT_PULLUP);
//pinMode(FLOAT_SENSORE, INPUT_PULLUP);
mySerial.begin(9600); // Set the baudrate of GSM module
Serial.begin(9600); //Set the baudrate of Serial monitor
Serial.println("Initializing...");
delay(1000);
mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
updateSerial();
mySerial.println("AT+CSQ"); //Signal quality test, value range is 0-31 , 31 is the best
updateSerial();
mySerial.println("AT+CCID"); //Read SIM information to confirm whether the SIM is plugged
updateSerial();
mySerial.println("AT+CREG?"); //Check whether it has registered in the network
updateSerial();
delay(1000);
}
void loop()
{
//Serial.println(flag);
if((digitalRead(FLOAT_SENSOR) == LOW) and (flag == false))
{
// turn LED on:
//digitalWrite(LED, HIGH);
//Serial.print(LED);
Serial.println(digitalRead(FLOAT_SENSOR));
empty_condition();
flag = true;
delay(1000);
empty_condition();
//Serial.println(flag);
}
else if((digitalRead(FLOAT_SENSOR) == HIGH) and (flag == true))
{
// turn LED off:
//digitalWrite(LED, LOW);
Serial.println(digitalRead(FLOAT_SENSOR));
full_condition();
flag = false;
delay(1000);
full_condition();
//Serial.print("full");
}
delay(1000);
}
void empty_condition(){
//Serial.println(mySerial.println("AT+CREG\r"));
mySerial.println("AT+CMGF=1\r"); //Sets the GSM Module in Text Mode
delay(2000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"+919082148533\"\r"); // Replace x with mobile number
delay(1000);
mySerial.println("@t1e#");// change the sms code with respect to tanks
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
Serial.print("empty");
}
void full_condition(){
mySerial.println("AT+CMGF=1\r"); //Sets the GSM Module in Text Mode
delay(2000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"+919082148533\"\r"); // Replace x with mobile number
delay(1000);
mySerial.println("@t1f#");// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
Serial.print("full ");
}
void updateSerial()
{
delay(500);
while (Serial.available())
{
mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
}
while(mySerial.available())
{
Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment