Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WiFi.h>
- #include <WiFiClientSecure.h>
- #include <UniversalTelegramBot.h>
- #define LIGHT_SENSOR_PIN 34
- #define WIFI_SSID "Team2 project"
- #define WIFI_PASSWORD "123454321"
- #define BOT_TOKEN "6094929450:AAFapzcEPmso7a5VoEUOpb8lOc-BF4AejRM"
- String chat_id_1 = "-994605295";
- int total = 0;
- int stateChange = 0;
- WiFiClientSecure secured_client;
- UniversalTelegramBot bot(BOT_TOKEN, secured_client);
- void setup()
- {
- Serial.begin(115200);
- connectToWiFiAndTelegramServer();
- total = 0;
- bot.sendMessage(chat_id_1, "Thank you for Saving the Environment");
- bot.sendMessage(chat_id_1, "Curent Balance: " + String(total) + " (SAR)");
- }
- void loop()
- {
- int analogValue = analogRead(LIGHT_SENSOR_PIN);
- Serial.println(analogValue);
- if (analogValue < 3000 && stateChange == 0) { //700
- stateChange = 1;
- total += 1;
- bot.sendMessage(chat_id_1, "Curent Balance: " + String(float(total)) + " (SAR)");
- delay(1000);
- }
- else if(analogValue > 3000 && stateChange == 1){
- stateChange = 0;
- delay(1000);
- }
- }
- void connectToWiFiAndTelegramServer() {
- Serial.println();
- Serial.print("Connecting to Wifi SSID ");
- Serial.print(WIFI_SSID);
- WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
- secured_client.setCACert(TELEGRAM_CERTIFICATE_ROOT);
- while (WiFi.status() != WL_CONNECTED)
- {
- Serial.print(".");
- delay(500);
- }
- Serial.print("\nWiFi connected. IP address: ");
- Serial.println(WiFi.localIP());
- Serial.print("Retrieving time: ");
- configTime(0, 0, "pool.ntp.org");
- time_t now = time(nullptr);
- while (now < 24 * 3600)
- {
- Serial.print(".");
- delay(100);
- now = time(nullptr);
- }
- Serial.println(now);
- }
Advertisement
Add Comment
Please, Sign In to add comment