Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #include <ESP8266WiFi.h>
- #include <UniversalTelegramBot.h>
- #include <WiFiClientSecure.h>
- #include <WiFiUdp.h>
- #include <ESP8266HTTPClient.h>
- #include <ArduinoJson.h>
- #include <string.h>
- int jjk=0; //jejak1
- int jjkx=0;//jejak2
- // nyambung wifi
- char ssid[] = "MEIDA"; // SSID wifi
- char password[] = "vitoganteng"; // password
- char wkt[] = "a"; //tidak guna (abaikan)
- //tele
- #define BOTtoken "1014035042:AAGqzVBVqQwiCO-E0ykWE1ddns_CG1RWcRc" // BOT Token di ambil dari bot father (telegram)
- WiFiClientSecure client;
- UniversalTelegramBot bot(BOTtoken, client);
- int Bot_mtbs = 1000; //mean time between scan messages
- long Bot_lasttime; //last time messages' scan has been done
- //tele-end
- // variable ultrasonik
- const int trigPin = 2; //D4
- const int echoPin = 0; //D3
- // defines variables ultrasionik
- long duration;
- int distance;
- //variabel soil
- int WET = 16; // Wet Indicator at Digital PIN D0
- int DRY = 2; // Dry Indicator at Digital PIN D4
- //variabel print lcd
- String prin, stringx, sa, sb, sc;
- //variabel soil
- int sense_Pin = 0; // Soil Sensor input at Analog PIN A0
- int value = 0;
- //fungsi i2c
- LiquidCrystal_I2C lcd(0x27, 16, 2);
- void setup()
- {
- Serial.begin(9600);
- lcd.begin();
- //memulai koneksi
- 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(".");
- lcd.setCursor(0, 0);
- lcd.print("Connecting");
- lcd.setCursor(0, 1);
- lcd.print("to wifi..");
- delay(500);
- }
- Serial.println("");
- Serial.println("WiFi connected");
- Serial.print("IP address: ");
- Serial.println(WiFi.localIP());
- //mengirim pesan apabila tersambung
- bot.sendMessage("970058254", "Selamat Datang XII TKJ 1 \n Koneksi Moisture", "");
- //mendefinisikan sebagai input dan output pin ultrasonnik
- pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
- pinMode(echoPin, INPUT); // Sets the echoPin as an Input
- stringx = String();
- pinMode(14, OUTPUT);
- // pinMode(WET, OUTPUT);
- // pinMode(DRY, OUTPUT);
- delay(2000);
- }
- void loop()
- {
- //xx
- digitalWrite(trigPin, LOW);
- delayMicroseconds(2);
- // Sets the trigPin on HIGH state for 10 micro seconds
- digitalWrite(trigPin, HIGH);
- delayMicroseconds(10);
- digitalWrite(trigPin, LOW);
- // Reads the echoPin, returns the sound wave travel time in microseconds
- duration = pulseIn(echoPin, HIGH);
- // Calculating the distance
- distance = duration *0.034 / 2;
- // Prints the distance on the Serial Monitor
- //Serial.print("Distance: ");
- Serial.println(distance);
- //batas
- Serial.print("MOISTURE LEVEL : ");
- value = analogRead(sense_Pin);
- value = value / 10;
- lcd.setCursor(0, 0);
- lcd.print("Lembab,Air :");
- lcd.setCursor(0, 1);
- sa = "xx";
- sb = ",";
- sc = value;
- stringx = "tes" + value;
- lcd.println(sc + sb + distance);
- Serial.println(prin);
- int harga= distance;
- String h = String(harga);
- String json = "{\"id\":\"71\",\"name\":\"update3\",\"price\":"+h+",\"description\":\"gps\",\"category_id\":\"1\",\"created\":\"gps\"}";
- HTTPClient http;
- http.begin("http://192.168.100.17/laravel/restapi8/api/product/update.php");
- http.addHeader("Content-Type", "application/x-www-form-urlencoded");
- http.POST(json);
- http.writeToStream(&Serial);
- http.end();
- if (value < 90)
- {
- if(jjk==jjkx){
- jjkx=jjk+1;
- String lembab = (String)
- "Kelembapan rendah\n" + value;
- bot.sendMessage("970058254", lembab, "");
- }
- digitalWrite(14, HIGH);
- }
- else
- {
- jjk=jjkx;
- digitalWrite(14, LOW);
- }
- delay(1500);
- // digitalWrite(WET,LOW);
- // digitalWrite(DRY, LOW);
- }
Add Comment
Please, Sign In to add comment