Sign up
Login
New paste
Home
Archive
English
English
Sign up
Login
New Paste
Browse
#include <WiFi.h> #include <WiFiClientSecure.h> #include <UniversalTelegramBot.h> #include <ArduinoJson.h> // Replace with your network credentials const char* ssid = "Rakhmat"; const char* password = "wifirakhmat123"; // Initialize Telegram BOT #define BOTtoken "1836141078:AAGpUQW4JH-xgZ5545kLCr4G49o00MkIeBo" // your Bot Token (Get from Botfather) // Use @myidbot to find out the chat ID of an individual or a group // Also note that you need to click "start" on a bot before it can // message you #define CHAT_ID "574967010" const unsigned long BOT_MTBS = 1000; // mean time between scan messages WiFiClientSecure client; UniversalTelegramBot bot(BOTtoken, client); unsigned long bot_lasttime; // last time messages' scan has been done // GANG A const int ldrA1 = 25; // ldr sens const int ldrA2 = 26; // ldr sens const int ldrA3 = 27; // ldr sens // GANG B const int ldrB1 = 18; // ldr sens const int ldrB2 = 19; // ldr sens const int ldrB3 = 21; // ldr sens void(*restart) (void) = 0; void setup() { Serial.begin(115200); Serial.println(); // PIR Motion Sensor mode INPUT_PULLUP pinMode(ldrA1, INPUT); //sensor ldr 1 input pinMode(ldrA2, INPUT); //sensor ldr 2 input pinMode(ldrA3, INPUT); pinMode(ldrB1, INPUT); pinMode(ldrB2, INPUT); pinMode(ldrB3, INPUT); // Attempt to connect to Wifi network: // configTime(0, 0, "pool.ntp.org"); // get UTC time via NTP Serial.print("Connecting to Wifi SSID "); WiFi.begin(ssid, password); client.setCACert(TELEGRAM_CERTIFICATE_ROOT); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(500); } Serial.print("\nWiFi connected. IP address: "); Serial.println(WiFi.localIP()); // Check NTP/Time, usually it is instantaneous and you can delete the code below. // Serial.print("Retrieving time: "); // time_t now = time(nullptr); // while (now < 24 * 3600) // { // Serial.print("."); // delay(100); // now = time(nullptr); // } // Serial.println(now); bot.sendMessage(CHAT_ID, "Bot started up & Sensor Ready", ""); } boolean cahaya = true; void handleNewMessages(int numNewMessages) { Serial.print("handleNewMessages "); Serial.println(numNewMessages); for (int i = 0; i < numNewMessages; i++) { String chat_id = bot.messages[i].chat_id; String text = bot.messages[i].text; String from_name = bot.messages[i].from_name; if (from_name == "") from_name = "Guest"; if (text == "/done") { bot.sendMessage(CHAT_ID, "Sensor telah direset"); restart(); } else if (text == "/start") { String welcome = "Welcome to Automated Message Sensor Bot" + from_name + ".\n"; welcome += "Ini adalah bot untuk mengontrol sensor. \n\n"; welcome += "/done : Untuk memberitau sensor jika lampu sudah diperbaiki.\n"; bot.sendMessage(chat_id, welcome, "Markdown"); } } } void loop() { int sensorData1 = digitalRead (ldrA1); int sensorData2 = digitalRead (ldrA2); int sensorData3 = digitalRead (ldrA3); int sensorData4 = digitalRead (ldrB1); int sensorData5 = digitalRead (ldrB2); int sensorData6 = digitalRead (ldrB3); Serial.print("Sensor value:"); Serial.println(sensorData1); Serial.println(sensorData2); Serial.println(sensorData3); Serial.println(sensorData4); Serial.println(sensorData5); Serial.println(sensorData6); if (millis() - bot_lasttime > BOT_MTBS) if (sensorData1 ==HIGH && cahaya == true) // lampu A1 { bot.sendMessage(CHAT_ID, "LAMPU GANG A NOMOR 1 MATI", ""); Serial.println("LAMPU GANG A NOMOR 1 MATI"); cahaya = false; // meniadakan persyaratan agar tidak berulang } else if (sensorData2 ==HIGH && cahaya == true) // lampu A2 { bot.sendMessage(CHAT_ID, "LAMPU GANG A NOMOR 2 MATI", ""); Serial.println("LAMPU GANG A NOMOR 2 MATI"); cahaya = false; // meniadakan persyaratan agar tidak berulang } else if (sensorData3 ==HIGH && cahaya == true) // lampu A3 { bot.sendMessage(CHAT_ID, "LAMPU GANG A NOMOR 3 MATI", ""); Serial.println("LAMPU GANG A NOMOR 3 MATI"); cahaya = false; // meniadakan persyaratan agar tidak berulang } else if (sensorData4 ==HIGH && cahaya == true) // lampu B1 { bot.sendMessage(CHAT_ID, "LAMPU GANG B NOMOR 1 MATI", ""); Serial.println("LAMPU GANG B NOMOR 1 MATI"); cahaya = false; // meniadakan persyaratan agar tidak berulang } else if (sensorData5 ==HIGH && cahaya == true) // lampu B2 { bot.sendMessage(CHAT_ID, "LAMPU GANG B NOMOR 2 MATI", ""); Serial.println("LAMPU GANG B NOMOR 2 MATI"); cahaya = false; // meniadakan persyaratan agar tidak berulang } else if (sensorData6 ==HIGH && cahaya == true) // lampu B3 { bot.sendMessage(CHAT_ID, "LAMPU GANG B NOMOR 3 MATI", ""); Serial.println("LAMPU GANG B NOMOR 3 MATI"); cahaya = false; // meniadakan persyaratan agar tidak berulang } else if (sensorData1 ==LOW && sensorData2 ==LOW && sensorData3 ==LOW && sensorData4 ==LOW && sensorData5 ==LOW && sensorData6 ==LOW) { cahaya = true; } { int numNewMessages = bot.getUpdates(bot.last_message_received + 1); while (numNewMessages) { Serial.println("got response"); handleNewMessages(numNewMessages); numNewMessages = bot.getUpdates(bot.last_message_received + 1); } bot_lasttime = millis(); } }
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Do you like cookies?
🍪 We use cookies to ensure you get the best experience on our website.
Learn more
I agree