Advertisement
thelostarc

COmpile all test v2 fix bargraph

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