I added it as you said and the code became like this
#include <WiFi.h>
#include <WiFiClient.h>
#include <HardwareSerial.h>
#include <UniversalTelegramBot.h>
#include <Adafruit_Sensor.h>
#include <TinyGPS++.h>
#include <Arducam_Mega.h>
#include <IRremote.h>
#include <DFRobot_VoiceRecorder.h>
// constants
#define WIFI_SSID "*****"
#define WIFI_PASSWORD "******"
#define BOT_TOKEN "*******"
#define CHAT_ID "******"
CAM_IMAGE_MODE imageMode = CAM_IMAGE_MODE_QVGA;
// variables
WiFiClient client;
UniversalTelegramBot bot(BOT_TOKEN, client);
#define CAM_SCL 21
#define CAM_SDA 22
#define CAM_VSYNC 23
#define CAM_HREF 25
#define CAM_D0 26
#define CAM_D1 27
#define CAM_D2 14
#define CAM_D3 12
#define CAM_D4 13
#define CAM_D5 15
#define CAM_D6 2
#define CAM_D7 0
#define CAM_RESET 4
#define CAM_PWDN 5
#define MIC_SEL 34
#define MIC_LRCL 35
#define MIC_DOUT 32
#define MIC_BCLK 33
#define GPS_PPS 19
#define GPS_RXD 17
#define GPS_TXD 16
#define IR_RECEIVER 18
#define TAKE_PHOTO 0x1FE807F
#define START_AUDIO 0x1FE40BF
#define STOP_AUDIO 0x1FE20DF
#define GET_LOCATION 0x1FEF807
IRrecv irrecv(IR_RECEIVER);
decode_results results;
TinyGPSPlus gps;
double latitude = 0.0;
double longitude = 0.0;
HardwareSerial swSer(17);
Arducam_Mega myCAM (21);
DFRobot_VoiceRecorder_I2C voicerecorder;
void setup() {
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("WiFi connected");
irrecv.enableIRIn();
// Initialize camera
myCAM.takePicture(CAM_IMAGE_MODE_WQXGA2,CAM_IMAGE_PIX_FMT_JPG);
//myCAM.setJPEGQuality(80);
// Initialize microphone
voicerecorder.begin();
}
void loop() {
if (irrecv.decode(&results)) {
if (results.value == TAKE_PHOTO) {
// Take a photo and send it to the Telegram bot
myCAM.takePicture(imageMode,CAM_IMAGE_PIX_FMT_JPG);
}
// Get the photo file name
String photoFileName = "photo.jpg";
// Upload the photo to the Telegram bot
bot.sendPhoto(CHAT_ID, photoFileName);
}
if (results.value == START_AUDIO) {
// Start recording audio
int status = voicerecorder.recordvoiceStart();
if (status != VOICE_SUCCESS) {
Serial.println("Error starting audio recording");
}
}
if (results.value == STOP_AUDIO) {
// Stop recording audio
int status = voicerecorder.recordVoiceEnd();
if (status != VOICE_SUCCESS) {
Serial.println("Error stopping audio recording");
}
}
// Get the audio file name
String audioFileName = "audio.mp3";
// Upload the audio to the Telegram bot
bot.sendMessage(CHAT_ID, audioFileName);
if (results.value == GET_LOCATION) {
// Get the GPS location
while (swSer.available() > 0)
gps.encode(swSer.read());
{
delay(100);
}
if (gps.location.isUpdated())
{
latitude = gps.location.lat();
longitude = gps.location.lng();
}
// Send the location to the Telegram bot
String locationMessage = "Location: " + String(latitude, 6) + ", " + String(longitude, 6);
bot.sendMessage(CHAT_ID, locationMessage.c_str(), "");
}
yield();
irrecv.resume();
}
void takePhoto() {
// Take a photo
//myCAM.takePicture();
myCAM.takePicture(CAM_IMAGE_MODE_WQXGA2,CAM_IMAGE_PIX_FMT_JPG);
}
void startAudioRecording() {
// Start audio recording
int status = voicerecorder.recordvoiceStart();
if (status != VOICE_SUCCESS) {
Serial.println("Error starting audio recording");
}
}
void stopAudioRecording() {
// Stop audio recording
int status = voicerecorder.recordVoiceEnd();
if (status != VOICE_SUCCESS) {
Serial.println("Error stopping audio recording");
}
}
void getGPSLocation() {
// Get the GPS location
while (swSer.available() > 0 && !gps.location.isUpdated()) {
gps.encode(swSer.read());
delay(100);
}
if (gps.location.isUpdated()) {
latitude = gps.location.lat();
longitude = gps.location.lng();
}
// Send the location to the Telegram bot
String locationMessage = "Location: " + String(latitude, 6) + ", " + String(longitude, 6);
bot.sendMessage(CHAT_ID, locationMessage.c_str(), "");
}
And in the serial monitor this appeared
13:06:26.270 -> ets Jun 8 2016 00:22:57
13:06:26.274 ->
13:06:26.277 -> rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
13:06:26.280 -> configsip: 0, SPIWP:0xee
13:06:26.284 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
13:06:26.288 -> mode:DIO, clock div:1
13:06:26.291 -> load:0x3fff0018,len:4
13:06:26.295 -> load:0x3fff001c,len:928
13:06:26.299 -> ho 0 tail 12 room 4
13:06:26.303 -> load:0x40078000,len:8740
13:06:26.307 -> load:0x40080400,len:5788
13:06:26.311 -> entry 0x4008069c
13:06:34.609 -> ets Jun 8 2016 00:22:57
13:06:34.617 ->
13:06:34.622 -> rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
13:06:34.629 -> configsip: 0, SPIWP:0xee
13:06:34.635 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
13:06:34.641 -> mode:DIO, clock div:1
13:06:34.647 -> load:0x3fff0018,len:4
13:06:34.653 -> load:0x3fff001c,len:928
13:06:34.659 -> ho 0 tail 12 room 4
13:06:34.665 -> load:0x40078000,len:8740
13:06:34.670 -> load:0x40080400,len:5788
13:06:34.675 -> entry 0x4008069c