Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define trigPin 12
- #define echoPin 13
- #define MAX_DISTANCE 70
- #include <Wire.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);
- void setup()
- {
- lcd.init(); // initialize the lcd // initialize the lcd
- lcd.backlight();
- lcd.setCursor(0, 1);
- pinMode(trigPin, OUTPUT);
- pinMode(echoPin, INPUT);
- SIM900A.begin(9600); // Setting the baud rate of GSM Module
- Serial.begin(9600);
- }
- void loop()
- {
- long duration, distance;
- digitalWrite(trigPin, LOW); // Added this line
- delayMicroseconds(2); // Added this line
- digitalWrite(trigPin, HIGH);
- delayMicroseconds(10); // Added this line
- digitalWrite(trigPin, LOW);
- duration = pulseIn(echoPin, HIGH);
- distance = duration*0.034/2;
- byte i0 = duration*0.034/2;
- 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(100);
- lcd.setCursor(0,1); // Sets the location at which subsequent text written to the LCD will be displayed
- lcd.print("Distance: "); // Prints string "Distance" on the LCD
- lcd.print(distance); // Prints the distance value from the sensor
- lcd.print(" cm ");
- delay(500);
- 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