Advertisement
thelostarc

HCSR04 with SMS module (Compile) v3 with new sonar code

Jul 12th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. #define trigPin 12
  2. #define echoPin 13
  3. #define MAX_DISTANCE 500
  4. #include <Wire.h>
  5. #include <NewPing.h>
  6. #include <SoftwareSerial.h>
  7. #include <LiquidCrystal_I2C.h>
  8. #include <LcdBarGraphRobojax.h>
  9.  
  10. LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
  11. LcdBarGraphRobojax lbg0(&lcd, 20, 0, 0);
  12. SoftwareSerial SIM900A(10,11);
  13. NewPing sonar(trigPin, echoPin, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
  14.  
  15. void setup()
  16. {
  17. lcd.init(); // initialize the lcd // initialize the lcd
  18. lcd.backlight();
  19. lcd.setCursor(0, 1);
  20. Serial.begin(115200);
  21. SIM900A.begin(9600); // Setting the baud rate of GSM Module
  22. Serial.begin(9600);
  23. }
  24.  
  25. void loop()
  26. {
  27. long distance;
  28. // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  29. distance = sonar.ping_cm();
  30.  
  31. byte i0 = sonar.ping_cm();
  32. i0 = max(i0, 10); //maksimal bargraph mentok di 10cm dan bargraph akan tergambar full satu baris tidak menyambung kebawah saat tertampil
  33.  
  34. lbg0.drawValue( 10, i0); //Jika value sepuluh 10 atau batas cm di tukar dengan duration sebelahnya maka graph aka terbalik dari kecil ke besar
  35. delay(200);
  36.  
  37. lcd.setCursor(0,1); // Sets the location at which subsequent text written to the LCD will be displayed
  38. lcd.print(""); // Prints string "Distance" on the LCD
  39. lcd.print(distance); // Prints the distance value from the sensor
  40. lcd.print(" ");
  41. delay(200);
  42.  
  43. if (distance > 75)
  44. kirimSMS();
  45. }
  46.  
  47. void kirimSMS()
  48. {
  49. Serial.println ("Sending Message");
  50. SIM900A.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
  51. delay(1000);
  52. Serial.println ("Set SMS Number");
  53. SIM900A.println("AT+CMGS=\"+6289689457568\"\r"); //Mobile phone number to send message
  54. delay(1000);
  55. Serial.println ("Set SMS Content");
  56. SIM900A.println("its GETTING LOW?");// Messsage content
  57. delay(100);
  58. Serial.println ("Finish");
  59. SIM900A.println((char)26);// ASCII code of CTRL+Z
  60. delay(1000);
  61. Serial.println ("Message has been sent ->SMS Selesai dikirim");
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement