asmaklad / TeleView

A telegram photo sending bot using the ESP32 CAM on Arduino IDE.
GNU Lesser General Public License v2.1
21 stars 8 forks source link

external PIR support on "AI Thinker ESP32-CAM" #1

Closed mrmate2 closed 4 years ago

mrmate2 commented 4 years ago

Good day, is it possible to enable external PIR support on "AI Thinker ESP32-CAM", i.e. some GPIO pin to listen for PIR input, or at least to enable external physical button to activate photo capture? If yes-then to make appropriate switch in telegram bot interface. Your project is very good, but no motion detection for PIR "AI Thinker ESP32-CAM" is dissapointing... Unfortunately my skills in coding are not yet sufficient. Many thanks in advance. Best regards from Ukraine!

P.S just thoughts: -"restart" button in telegram would be a good option

setting lapse time in secons instead of minutes also would be nice. sometimes need photo every 20-30 sec...

asmaklad commented 4 years ago

Hi MrMate2, it is easy to have this. have a look in the file: camera_pins.h copy the Definitions you want from the section "CAMERA_MODEL_TTGO_T1_CAMERA" to the section "CAMERA_MODEL_AI_THINKER". i.e. copy the code :

define PIR_PIN 33 //GPIO_INPUT_IO_33 //AS312

define BUTTON_PIN 34

to line 100 and then the features you want will be enabled in your code automatically. (both telegram and web interface will start having it on the next compile)

I can't add such feature (PIR and button) in the code because that is not a default feature.

As for the restart command: I though about it. but enabling the sleep mode with an interval would make the ESP more or less same as reset every X number of mins. and then next command is to disable the sleep.

Tell me if you want further elaborations.

mrmate2 commented 4 years ago

Dear Asmaklad, many thanks for Your reply! I changed the lines as per Your advise, buttons in telegram and web interface already appeared, but if motion detection activated-the result is every second (or so) i have MOTION DETECTED alarm+photo even without PIR connected..... By the way, to what physycal pins it has to be connected, if this part code will work finally? Is it ok that pin 34 mentioned 2times in AI-thinker part? This is how it looks after editing according to Your advise:

ifndef CAMERA_PINS_H

define CAMERA_PINS_H

if defined(CAMERA_MODEL_WROVER_KIT)

define PWDN_GPIO_NUM -1

define RESET_GPIO_NUM -1

define XCLK_GPIO_NUM 21

define SIOD_GPIO_NUM 26

define SIOC_GPIO_NUM 27

define Y9_GPIO_NUM 35

define Y8_GPIO_NUM 34

define Y7_GPIO_NUM 39

define Y6_GPIO_NUM 36

define Y5_GPIO_NUM 19

define Y4_GPIO_NUM 18

define Y3_GPIO_NUM 5

define Y2_GPIO_NUM 4

define VSYNC_GPIO_NUM 25

define HREF_GPIO_NUM 23

define PCLK_GPIO_NUM 22

elif defined(CAMERA_MODEL_ESP_EYE)

define PWDN_GPIO_NUM -1

define RESET_GPIO_NUM -1

define XCLK_GPIO_NUM 4

define SIOD_GPIO_NUM 18

define SIOC_GPIO_NUM 23

define Y9_GPIO_NUM 36

define Y8_GPIO_NUM 37

define Y7_GPIO_NUM 38

define Y6_GPIO_NUM 39

define Y5_GPIO_NUM 35

define Y4_GPIO_NUM 14

define Y3_GPIO_NUM 13

define Y2_GPIO_NUM 34

define VSYNC_GPIO_NUM 5

define HREF_GPIO_NUM 27

define PCLK_GPIO_NUM 25

elif defined(CAMERA_MODEL_M5STACK_PSRAM)

define PWDN_GPIO_NUM -1

define RESET_GPIO_NUM 15

define XCLK_GPIO_NUM 27

define SIOD_GPIO_NUM 25

define SIOC_GPIO_NUM 23

define Y9_GPIO_NUM 19

define Y8_GPIO_NUM 36

define Y7_GPIO_NUM 18

define Y6_GPIO_NUM 39

define Y5_GPIO_NUM 5

define Y4_GPIO_NUM 34

define Y3_GPIO_NUM 35

define Y2_GPIO_NUM 32

define VSYNC_GPIO_NUM 22

define HREF_GPIO_NUM 26

define PCLK_GPIO_NUM 21

elif defined(CAMERA_MODEL_M5STACK_WIDE)

define PWDN_GPIO_NUM -1

define RESET_GPIO_NUM 15

define XCLK_GPIO_NUM 27

define SIOD_GPIO_NUM 22

define SIOC_GPIO_NUM 23

define Y9_GPIO_NUM 19

define Y8_GPIO_NUM 36

define Y7_GPIO_NUM 18

define Y6_GPIO_NUM 39

define Y5_GPIO_NUM 5

define Y4_GPIO_NUM 34

define Y3_GPIO_NUM 35

define Y2_GPIO_NUM 32

define VSYNC_GPIO_NUM 25

define HREF_GPIO_NUM 26

define PCLK_GPIO_NUM 21

elif defined(CAMERA_MODEL_AI_THINKER) //Board definition "AI Thinker ESP32-CAM"

define PWDN_GPIO_NUM 32

define RESET_GPIO_NUM -1

define XCLK_GPIO_NUM 0

define SIOD_GPIO_NUM 26

define SIOC_GPIO_NUM 27

define Y9_GPIO_NUM 35

define Y8_GPIO_NUM 34

define Y7_GPIO_NUM 39

define Y6_GPIO_NUM 36

define Y5_GPIO_NUM 21

define Y4_GPIO_NUM 19

define Y3_GPIO_NUM 18

define Y2_GPIO_NUM 5

define VSYNC_GPIO_NUM 25

define HREF_GPIO_NUM 23

define PCLK_GPIO_NUM 22

define FLASH_LAMP_PIN 4

define PIR_PIN 33 //GPIO_INPUT_IO_33 //AS312

define BUTTON_PIN 34

elif defined(CAMERA_MODEL_TTGO_T1_CAMERA) // Board definition "ESP32 WROVER Module"

define PWDN_GPIO_NUM 26

define RESET_GPIO_NUM -1

define XCLK_GPIO_NUM 32

define SIOD_GPIO_NUM 13

define SIOC_GPIO_NUM 12

define Y9_GPIO_NUM 39

define Y8_GPIO_NUM 36

define Y7_GPIO_NUM 23

define Y6_GPIO_NUM 18

define Y5_GPIO_NUM 15

define Y4_GPIO_NUM 4

define Y3_GPIO_NUM 14

define Y2_GPIO_NUM 5

define VSYNC_GPIO_NUM 27

define HREF_GPIO_NUM 25

define PCLK_GPIO_NUM 19

define SDA_PIN 21

define SCL_PIN 22

define I2C_DISPLAY_ADDR 0x3c

define USE_OLED_AS_FLASH 1 // the OLEDis on the same side as the camera

//#define I2C_BME280_ADDR 0x3d

define PIR_PIN 33 //GPIO_INPUT_IO_33 //AS312

define BUTTON_PIN 34

else

error "Camera model not selected"

endif

////////////////////////////////////////

if defined(FLASH_LAMP_PIN)

define IS_THERE_A_FLASH 1

endif

if defined(USE_OLED_AS_FLASH)

define IS_THERE_A_FLASH 1

endif

////////////////////////////////////////

endif //CAMERA_PINS_H

asmaklad commented 4 years ago

yes the code is like what I advised.

However, you will have to change it to the PIR PIN number that corresponds to your setup. it really depends on which PIN you chose for PIR. I recommend making a PULL _DOWN on the chosen PIN . like this circuit for example https://easyelectronicsproject.com/esp32-projects/esp32-cam-pir-motion-detector-with-photo-capture-1/

As for the button, looking back to it: I don't think I have implemented anything in the code for that. And yes , having pin 34 used twice is not correct. I would remove the #define BUTTON_PIN 34 from the AI_THINKER section.

For the BOT to refresh the command list , you need to issue the command "/options" or "/start" in telegram.

Or to avoid all of this hassle, if you really want to use PIR, order this board instead "ESP32 CAM TTGO T1 (google it)"

mrmate2 commented 4 years ago

All is done, now working perfect! Many thanks! Great project! All the best!!

asmaklad commented 4 years ago

Thanks for using the project. Please spread the word. If you want, please tell on how do you use it ? maybe some screenshots . I find satisfaction that I made something useful and usable in the real world. thanks again for sharing.

mrmate2 commented 4 years ago

Please spread the word.

Definitely, I will do my best to spread information about Your code among as many people as I can. With reference to this repository, of course! Surely,the best is to make a video on Youtube. Unfortunately, I am not a blogger at all.... :). Maybe,one day I will ask some experienced blogger from Youtube to test this code and to make review.

If you want, please tell on how do you use it ? maybe some screenshots .

For the moment, I dont have examples of my usage of Your code yet. My plan is to use 2-3 units, it in my house, to monitor movements of my children around the house when me and wife are away. To be sure that they are not doing nothing and lying on the sofa all day and watching tv... :)

Believe me,Ias I was not able to do myself,I was searching for similar code long time, already about one year. I have seen nearly all videos on youtube with reference to esp32cam., I have read many articles, in English and Russian. The sources were numerous, but none was about code with" ALL IN ONE" My search criteria was: -interaction with camera via telegram app( not emails receiving only) -pir sensor motion detection with ON/OFF -use LED as flash with ON/OFF -ability to shoot photo at intervals -ability to change resolution of photo "on a fly"

The code is great for my purposes. Only one thing can be added: support for Telegram bot to control at least 1 horisontal servo motor. And only one thing is not perfect: delay of 3-4 seconds between motion detection and first photo shot.

All the best! And many thanks for Your work! Best regards from Ukraine!

mrmate2 commented 4 years ago

Is it possible to specify more than 1 "AdminChatID", in order for my wife to control same from her phone?

asmaklad commented 4 years ago

I am already working on these two features, but I am not finished yet : 1) Pan Tilt Servo control Features . 2) More than one AdminID , and also another extra role as Viewer only.

asmaklad commented 3 years ago

@mrmate2
A new version of TeleView is available that has :