Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #include <ESP8266WiFi.h>
- #include <WiFiClientSecure.h>
- #include <UniversalTelegramBot.h>
- #define counter_pin D9
- #define buttonReset D8
- bool item_detected = false;
- bool rs_detected = true;
- int item_counter = 0;
- int statusReset = 0;
- char ssid[] = "Mi A1";
- char password[] = "11223344";
- #define BOTtoken "857476788:AAHYWAq9KSkCZWeurL0DXaoX9AF-w3OZrak"
- #define chat_id "876561354"
- LiquidCrystal_I2C lcd(0x27, 16,2);
- WiFiClientSecure client;
- UniversalTelegramBot bot(BOTtoken, client);
- void connectwifi(){
- Serial.begin(115200);
- WiFi.mode(WIFI_STA);
- WiFi.disconnect();
- delay(100);
- Serial.print("Connecting Wifi: ");
- Serial.println(ssid);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- Serial.print(".");
- delay(500);
- }
- Serial.println("");
- Serial.println("WiFi connected");
- Serial.print("IP address: ");
- Serial.println(WiFi.localIP());
- }
- void setup() {
- Serial.begin(115200);
- lcd.begin();lcd.backlight();
- pinMode( counter_pin , INPUT);
- pinMode( buttonReset , INPUT);
- lcd.setCursor(0,0);lcd.print("Menghubungkan");
- lcd.setCursor(0,1);lcd.print("ke Jaringan...");
- connectwifi();
- lcd.clear();
- lcd.setCursor(0,0);lcd.print("Terhubung ke");
- lcd.setCursor(0,1);lcd.print("Jaringan Anda");
- delay(2500);lcd.clear();
- bot.sendMessage(chat_id, "Sudah Terhubung", "");
- lcd.setCursor(0, 0);lcd.print("Selamat Datang");
- lcd.setCursor(0, 1);lcd.print("Di BP3TKI");delay(2000);
- lcd.clear();lcd.setCursor(0, 0);lcd.print("Ready");
- delay(2000);
- }
- void loop() {
- updateCounter();delay(250);
- int statusReset = digitalRead(buttonReset);
- if( (rs_detected == true) && ( statusReset == 1 )){
- rs_detected = false;
- item_counter = 0;
- lcd.clear();lcd.setCursor(2,0);lcd.print("Penghitung");
- lcd.setCursor(4,1);lcd.print("Direset");delay(2000);
- updateCounter();
- bot.sendMessage(chat_id, "Penghitung Pengunjung Direset", "");
- String cek = "Jumlah Pengunjung : ";
- cek += item_counter;
- cek += " orang.";
- bot.sendMessage(chat_id, cek, "");
- delay(50);
- }
- else if( (rs_detected == false) && ( statusReset == 0 )){
- rs_detected = true;
- }
- int val = digitalRead( counter_pin );
- if( (item_detected == false) && ( val == 0 )){
- item_detected = true;
- item_counter++;
- updateCounter();
- String cek = "Jumlah Pengunjung : ";
- cek += item_counter;
- cek += " orang.";
- bot.sendMessage(chat_id, cek, "");
- delay(250);
- }
- else if( (item_detected == true) && ( val == 1 )){
- item_detected = false;
- }
- }
- void updateCounter(){
- lcd.clear();lcd.setCursor(0,0);lcd.print("Pengunjung Masuk");
- lcd.setCursor(7,1);lcd.print(item_counter);
- Serial.println(item_counter);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement