Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define trigPin 12
- #define echoPin 13
- #define MAX_DISTANCE 500
- #include <Wire.h>
- #include <NewPing.h>
- #include <SoftwareSerial.h>
- #include <LiquidCrystal_I2C.h>
- #include <LcdBarGraphRobojax.h>
- LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
- LcdBarGraphRobojax lbg0(&lcd, 20, 0, 0);
- SoftwareSerial SIM900A(10,11);
- NewPing sonar(trigPin, echoPin, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
- void setup()
- {
- lcd.init(); // initialize the lcd // initialize the lcd
- lcd.backlight();
- lcd.setCursor(0, 1);
- Serial.begin(115200);
- SIM900A.begin(9600); // Setting the baud rate of GSM Module
- Serial.begin(9600);
- }
- void loop()
- {
- long distance;
- // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
- distance = sonar.ping_cm();
- byte i0 = sonar.ping_cm();
- i0 = max(i0, 10); //maksimal bargraph mentok di 10cm dan bargraph akan tergambar full satu baris tidak menyambung kebawah saat tertampil
- lbg0.drawValue( 10, i0); //Jika value sepuluh 10 atau batas cm di tukar dengan duration sebelahnya maka graph aka terbalik dari kecil ke besar
- delay(200);
- lcd.setCursor(0,1); // Sets the location at which subsequent text written to the LCD will be displayed
- lcd.print(""); // Prints string "Distance" on the LCD
- lcd.print(distance); // Prints the distance value from the sensor
- lcd.print(" ");
- delay(200);
- if (distance > 75)
- kirimSMS();
- }
- void kirimSMS()
- {
- Serial.println ("Sending Message");
- SIM900A.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
- delay(1000);
- Serial.println ("Set SMS Number");
- SIM900A.println("AT+CMGS=\"+6289689457568\"\r"); //Mobile phone number to send message
- delay(1000);
- Serial.println ("Set SMS Content");
- SIM900A.println("its GETTING LOW?");// Messsage content
- delay(100);
- Serial.println ("Finish");
- SIM900A.println((char)26);// ASCII code of CTRL+Z
- delay(1000);
- Serial.println ("Message has been sent ->SMS Selesai dikirim");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement