You are on page 1of 3

/* I2C LCD with Arduino example code. More info: https://www.makerguides.

com */
#include <SoftwareSerial.h>
// Include the libraries:
// LiquidCrystal_I2C.h: https://github.com/johnrickman/LiquidCrystal_I2C
#include <Wire.h> // Library for I2C communication
#include <LiquidCrystal_I2C.h> // Library for LCD
SoftwareSerial sim800l(18, 19); // RX,TX for Arduino and for the module it's TXD
RXD, they should be inverted
// Wiring: SDA pin is connected to A4 and SCL pin to A5.
// Connect to LCD via I2C, default address 0x27 (A0-A2 not jumpered)
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2); // Change to (0x27,20,4)
for 20x4 LCD.

void setup() {
// Initiate the LCD:
sim800l.begin(9600);
lcd.init();
lcd.backlight();
pinMode (4,INPUT_PULLUP);
pinMode (26,INPUT);
pinMode (5,OUTPUT);
digitalWrite (5,LOW);
}

void loop() {
int Msensor = analogRead(34);
int Psensor = digitalRead(4);
int Tsensor = digitalRead(26);
if (Psensor == 0)
{
SendSMS2();
setbuzzer();
}
if (Msensor<=1400)
{
SendSMS3();
setbuzzer();
}
if (Tsensor==HIGH)
{
SendSMS1();
setbuzzer();
}
lcd.clear();
lcd.setCursor(2, 0); // Set the cursor on the third column and first row.
lcd.print("Pressure "); // Print the string "Hello World!"
lcd.print(Psensor);
lcd.setCursor(2, 1); // Set the cursor on the third column and first row.
lcd.print("Moisture "); // Print the string "Hello World!"
lcd.print(Msensor);
delay(2000);
lcd.clear();
lcd.setCursor(2, 0); // Set the cursor on the third column and first row.
lcd.print("Tilt"); // Print the string "Hello World!"
lcd.print(Tsensor);
delay(1000);
}

void SendSMS1()
{
Serial.println("Sending SMS..."); //Show this message on serial
monitor
sim800l.print("AT+CMGF=1\r"); //Set the module to SMS mode
delay(100);
sim800l.print("AT+CMGS=\"09667006514\"\r"); //Your phone number don't forget to
include your country code, example +212123456789"
// sim800l.print("AT+CMGS=\"09676589201\"\r"); //Your phone number don't forget
to include your country code, example +212123456789"
delay(500);
sim800l.print("Soil Erosion Sensor Alert level 3 \n Stay Vigilant!");
//This is the text to send to the phone number, don't make it too long or you have
to modify the SoftwareSerial buffer
delay(500);
sim800l.print((char)26);// (required according to the datasheet)
delay(500);
sim800l.println();
Serial.println("Text Sent.");
delay(500);

void SendSMS2()
{
Serial.println("Sending SMS..."); //Show this message on serial
monitor
sim800l.print("AT+CMGF=1\r"); //Set the module to SMS mode
delay(100);
sim800l.print("AT+CMGS=\"09667006514\"\r"); //Your phone number don't forget to
include your country code, example +212123456789"
// sim800l.print("AT+CMGS=\"09676589201\"\r");
delay(500);
sim800l.print("Soil Erosion Sensor Alert level 1 \n Soil Pressure level is
increasing"); //This is the text to send to the phone number, don't make it
too long or you have to modify the SoftwareSerial buffer
delay(500);
sim800l.print((char)26);// (required according to the datasheet)
delay(500);
sim800l.println();
Serial.println("Text Sent.");
delay(500);

void SendSMS3()
{
Serial.println("Sending SMS..."); //Show this message on serial
monitor
sim800l.print("AT+CMGF=1\r"); //Set the module to SMS mode
delay(100);
sim800l.print("AT+CMGS=\"09667006514\"\r"); //Your phone number don't forget to
include your country code, example +212123456789"
delay(500);
sim800l.print("Soil Erosion Sensor Alert level 2 \n Soil Moisture saturation
level is high"); //This is the text to send to the phone number, don't make
it too long or you have to modify the SoftwareSerial buffer
delay(500);
sim800l.print((char)26);// (required according to the datasheet)
delay(500);
sim800l.println();
Serial.println("Text Sent.");
delay(500);

void setbuzzer()
{
for (int x=0;x<20;x++)
{
digitalWrite (5,HIGH);
delay(100);
digitalWrite (5,LOW);
delay(150);
}
}

You might also like