SHARE
TWEET

Untitled

a guest Sep 17th, 2019 105 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3. #include <ESP8266WiFi.h>
  4. #include <WiFiClientSecure.h>
  5. #include <UniversalTelegramBot.h>
  6.  
  7.  
  8.  
  9. char ssid[] = "Redmi";
  10. char password[] = "qwerty123";
  11.  
  12. #define BOTtoken "838984089:AAF8xrQ-EDyM1JnscPI12tMDyhbmy5xifTA"
  13. #define chat_id "464985094"
  14.  
  15. LiquidCrystal_I2C lcd(0x27, 16,2);
  16. const int AOUTpin=A0;
  17. const int DOUTpin=D8;
  18. int ledPin=D9;
  19. int ledPin2=D10;
  20. int value;
  21. int limit;
  22. float kadar;
  23.  
  24. WiFiClientSecure client;
  25. UniversalTelegramBot bot(BOTtoken, client);
  26.  
  27. void connectwifi(){
  28.   Serial.begin(115200);
  29.  
  30.   WiFi.mode(WIFI_STA);
  31.   WiFi.disconnect();
  32.   delay(100);
  33.  
  34.   Serial.print("Connecting Wifi: ");
  35.   Serial.println(ssid);
  36.   WiFi.begin(ssid, password);
  37.  
  38.   while (WiFi.status() != WL_CONNECTED) {
  39.     Serial.print(".");
  40.     delay(500);
  41.   }
  42.  
  43.   Serial.println("");
  44.   Serial.println("WiFi connected");
  45.   Serial.print("IP address: ");
  46.   Serial.println(WiFi.localIP());
  47. }
  48.  
  49. void setup() {
  50.   Serial.begin(115200);
  51.   lcd.begin();
  52.   lcd.backlight();
  53.   lcd.setCursor(0,0);lcd.print("Menghubungkan");
  54.   lcd.setCursor(0,1);lcd.print("ke Jaringan...");
  55.   connectwifi();
  56.   lcd.clear();
  57.   digitalWrite(ledPin, HIGH);
  58.  
  59.   delay(1000);
  60.   pinMode(ledPin, OUTPUT);
  61.   pinMode(ledPin2, OUTPUT);
  62.   lcd.setCursor(0,0);lcd.print("Terhubung ke");
  63.   lcd.setCursor(0,1);lcd.print("Jaringan Anda");
  64.   delay(2500);lcd.clear();
  65.   bot.sendMessage(chat_id, "Sistem Pendeteksi Kadar Alkohol Sudah Terhubung Dengan Telegram Anda.", "");
  66.   lcd.setCursor(0,0);lcd.print("Alat Memulai");
  67.   lcd.setCursor(0,1);lcd.print("Mendeteksi");
  68.   delay(2500);lcd.clear();
  69. }
  70.  
  71. void loop() {
  72.   value= analogRead(AOUTpin);
  73.   limit= digitalRead(DOUTpin);
  74.   kadar= value*(5.0/1023.0);
  75.   delay (100);
  76.   Serial.print("Alcohol value: ");
  77.   Serial.println(value);
  78.   Serial.print("Limit: ");
  79.   Serial.print(limit);
  80.   lcd.setCursor(0,0);lcd.print("Kadar : ");lcd.print(kadar);lcd.print("mg/L");
  81.   digitalWrite(ledPin, HIGH);
  82.  
  83.   if (kadar <=2.0){
  84.     //bot.sendMessage(chat_id, "Status : Aman ", "");
  85.     lcd.setCursor(0,1);lcd.print("Status: ");lcd.print("Aman  ");
  86.     digitalWrite(ledPin, HIGH);
  87.     digitalWrite(ledPin2, LOW);
  88.     delay(10000);
  89.   }
  90.   else if(kadar >2.0){
  91.     bot.sendMessage(chat_id, "Status : Bahaya ", "");
  92.     lcd.setCursor(0,1);lcd.print("Status: ");lcd.print("Bahaya  ");
  93.     digitalWrite(ledPin, LOW);
  94.     digitalWrite(ledPin2, HIGH);
  95.     delay(10000);
  96.   }
  97. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top