Hello.
I am struggling with my current project and I'd appreciate some help. I'm quite new to Arduino programming and this is all new to me. I have also found it hard to find relevant information regarding the Arduino board since it's apparently quite new...
I have an R4 wifi, a PIR motion sensor and a flame sensor. I'm trying to get notified via a Telegram bot when the sensors detect a motion or a flame.
This is my code:
#include "WiFiS3.h"
#include <Arduino_JSON.h>
#include "arduino_secrets.h"
#include <UniversalTelegramBot.h>
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0; // your network key index number (needed only for WEP)
int status = WL_IDLE_STATUS;
WiFiClient client;
// Telegram Bot details
UniversalTelegramBot bot(BOTtoken, client);
const int flameSensorPin = A3; // Flame sensor connected to analog pin A3
const int pirSensorPin = 2; // PIR sensor connected to digital pin 2
void setup() {
Serial.begin(9600);
// Initialize WiFiS3
WiFi.begin(ssid, pass);
while (status != WL_CONNECTED) {
Serial.println("Connecting to WiFi...");
status = WiFi.begin(ssid, pass);
}
Serial.println("Connected to WiFi");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
Serial.print("BOTtoken: ");
Serial.println(BOTtoken);
Serial.print("CHAT_ID: ");
Serial.println(CHAT_ID);
bot.sendMessage(CHAT_ID, "Bot started up", "");
}
void loop() {
// Read values from sensors
int flameSensorValue = analogRead(flameSensorPin);
int pirSensorValue = digitalRead(pirSensorPin);
// Check if the flame sensor detects something
if (flameSensorValue < 100) {
Serial.println("Flame detected!");
bot.sendMessage(CHAT_ID, "Flame detected!!", "");
}
// Check if the PIR sensor detects motion
if (pirSensorValue == HIGH) {
Serial.println("Motion detected!");
bot.sendMessage(CHAT_ID, "Motion detected!!", "");
}
delay(1000); // Adjust the delay based on your requirements
}
Everything except for the Telegram part runs fine - It connects to a wifi and I'm able to ping the local IP it shows and see the module in my router settings. When I light a flame next to the flame detector it prints out "Flame detected!" like it should but I never get notifications on Telegram.
Any help would be appreciated!