Advertisement
Guest User

Lukman Penghitung Pengunjung

a guest
Sep 16th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3. #include <ESP8266WiFi.h>
  4. #include <WiFiClientSecure.h>
  5. #include <UniversalTelegramBot.h>
  6.  
  7. #define counter_pin D9
  8. #define buttonReset D8
  9. bool item_detected = false;
  10. bool rs_detected = true;
  11. int item_counter = 0;
  12. int statusReset = 0;
  13.  
  14. char ssid[] = "Mi A1";
  15. char password[] = "11223344";
  16.  
  17. #define BOTtoken "857476788:AAHYWAq9KSkCZWeurL0DXaoX9AF-w3OZrak"
  18. #define chat_id "876561354"
  19.  
  20. LiquidCrystal_I2C lcd(0x27, 16,2);
  21.  
  22. WiFiClientSecure client;
  23. UniversalTelegramBot bot(BOTtoken, client);
  24.  
  25. void connectwifi(){
  26. Serial.begin(115200);
  27.  
  28. WiFi.mode(WIFI_STA);
  29. WiFi.disconnect();
  30. delay(100);
  31.  
  32. Serial.print("Connecting Wifi: ");
  33. Serial.println(ssid);
  34. WiFi.begin(ssid, password);
  35.  
  36. while (WiFi.status() != WL_CONNECTED) {
  37. Serial.print(".");
  38. delay(500);
  39. }
  40.  
  41. Serial.println("");
  42. Serial.println("WiFi connected");
  43. Serial.print("IP address: ");
  44. Serial.println(WiFi.localIP());
  45. }
  46.  
  47. void setup() {
  48. Serial.begin(115200);
  49. lcd.begin();lcd.backlight();
  50. pinMode( counter_pin , INPUT);
  51. pinMode( buttonReset , INPUT);
  52. lcd.setCursor(0,0);lcd.print("Menghubungkan");
  53. lcd.setCursor(0,1);lcd.print("ke Jaringan...");
  54. connectwifi();
  55. lcd.clear();
  56. lcd.setCursor(0,0);lcd.print("Terhubung ke");
  57. lcd.setCursor(0,1);lcd.print("Jaringan Anda");
  58. delay(2500);lcd.clear();
  59. bot.sendMessage(chat_id, "Sudah Terhubung", "");
  60. lcd.setCursor(0, 0);lcd.print("Selamat Datang");
  61. lcd.setCursor(0, 1);lcd.print("Di BP3TKI");delay(2000);
  62. lcd.clear();lcd.setCursor(0, 0);lcd.print("Ready");
  63. delay(2000);
  64. }
  65.  
  66. void loop() {
  67. updateCounter();delay(250);
  68. int statusReset = digitalRead(buttonReset);
  69. if( (rs_detected == true) && ( statusReset == 1 )){
  70. rs_detected = false;
  71. item_counter = 0;
  72. lcd.clear();lcd.setCursor(2,0);lcd.print("Penghitung");
  73. lcd.setCursor(4,1);lcd.print("Direset");delay(2000);
  74. updateCounter();
  75. bot.sendMessage(chat_id, "Penghitung Pengunjung Direset", "");
  76. String cek = "Jumlah Pengunjung : ";
  77. cek += item_counter;
  78. cek += " orang.";
  79. bot.sendMessage(chat_id, cek, "");
  80. delay(50);
  81. }
  82.  
  83. else if( (rs_detected == false) && ( statusReset == 0 )){
  84. rs_detected = true;
  85. }
  86.  
  87. int val = digitalRead( counter_pin );
  88. if( (item_detected == false) && ( val == 0 )){
  89. item_detected = true;
  90. item_counter++;
  91. updateCounter();
  92. String cek = "Jumlah Pengunjung : ";
  93. cek += item_counter;
  94. cek += " orang.";
  95. bot.sendMessage(chat_id, cek, "");
  96. delay(250);
  97. }
  98.  
  99. else if( (item_detected == true) && ( val == 1 )){
  100. item_detected = false;
  101.  
  102. }
  103. }
  104.  
  105. void updateCounter(){
  106. lcd.clear();lcd.setCursor(0,0);lcd.print("Pengunjung Masuk");
  107. lcd.setCursor(7,1);lcd.print(item_counter);
  108. Serial.println(item_counter);
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement