For an index to all my stories click this text
The regular readers of this blog know that I wrote a few stories on Blynk. You can find them here:
And I did some stories on the ESP32 Cam. You can find these here:
So how about combining these two and send pictures from the ESP32Cam to Blynk.
If you have no experience with Blynk I really urge you to read the above mentioned stories first and do some experiments with Blynk. This will make you getting familiar with Blynk which helps a lot with reproducing this project.
As this project uses 800 energy points I really urge you to build your own Blynk server like demonstrated in the 4th story. It is not necessary but there is little energy left for other projects if you use the free Blynk server unless you are willing to spend some money on buying energy.
What is the intention.
I am going to show you how to make a doorbell with an ESP32 Cam that sends a picture to Blynk when someone pushes a button. Next to that in the Blynk app there is a virtual button. When you press that button you will be able to make a picture wether or not there is someone at the door. So you can keep an eye on your door.
There are multiple purposes for this. And I will give you some examples at the end of this story.
The breadboard setup.
For programming the ESP32Cam I used my own ESP32Cam programming board that can be found (and re-build by yourself) here:http://lucstechblog.blogspot.com/2021/10/esp32cam-experiment-board.html
When the programming and testing finished I used my ESP32Cam experimenting board which you can be found (and build by yourself) here :
I put the ESP32Cam on the experimenting board and put a small breadboard next to it. On the breadboard I put a pushbutton with a pull-up resistor. The pushbutton is connected to IO pin 13.
For this experiment I started a new project. Surprisingly I called it Espcam doorbell.
If you have no experience with Blynk start with the first of my stories. That story tells you how to add a button and other items to Blynk. You can re-read that story here: http://lucstechblog.blogspot.com/2021/03/blynk-part-1-starting-with-blynk.html
There are just 2 items on the screen.
The first is a button which is attached to GPIO 14. I gave it the name Photo but you can use any name you like. The button was attached to GP14 and is normally low (0) and sends a high signal(1) when pushed. The text is in a large font and colored red. Off the button has the text Photo and when it is pushed the text alters to Done.
The second item is an Image Gallery. You can find that in the Widget Box in the DISPLAYS section.
The Image Gallery is attached to Virtual pin V1. I made the Image Gallery box screen wide and used FIT to make the picture fit into that box.
The most important part is to tell Blynk where to get the picture.
This is the reference where Blynk can fetch the Photo. The problem at this moment is that you do not know the IP number of the ESP32-Cam. So first we need to flash the software into the ESP32Cam.
Actually this is the program that is supplied with the ESP32 Cam board in the Arduino IDE.
So open the Arduino IDE. Choose as board AI Thinker ESP32-Cam and then load
the CameraWebServer example.
To get this working with Blynk we need to make some changes to the program. First I will give you the complete program. You can just copy and paste it if you are not interested in the modifications.
The additions for Blynk
Let's have a look at the modifications I made for getting the standard CameraWebServer program.
Next to the Wifi libraries the Blynk library must be included.
You need to fill in your routers credentials and the Blynk authetification code you received from Blynk when you created the Blynk project.
Here the pins for the buttons are defined. The physical button is attached to GPIO pin 13 at the ESP32Cam just as the breadboard showed. The Virtual pin is attached to GPIO14. Next to that The ESP32 Cam's internal flash led is attached to GPIO 4. I am using the flashlight to brighten te pictures in my rather dark mancave.
A String variable is defined in which the IP number of the camera is stored. This is later on going to be used to inform Blynk of the camera's IP number.
This routine is called from the loop() when the physical button or the virtual button is pressed. The flashlight is set ON and thye program waits 200ms to be sure that the led is ON. Then the IP adress of the ESP32-Cam (campip as found in the setup) together with the command /capture. This activates the camera, makes the photo and sends it to the Image Gallery Which has as reference in Blynk V1.
If you do not need the flashlight just remove the digitalWrite(flashled, HIGH); and digitalWrite(flashled, LOW);
Another option is to comment these lines out. Then they are easier to edit when you might need the flashlight again.
You could also add another virtual button to Blynk to set the flashlight on or off.
To test wether taking a photograph works you can put the line:
http://XXX.XXX.XXX.XXX/capture in your browser where you have to replace the XXX.XXX.XXX.XXX with the IP number of the ESP32-Cam. That way you can check wether the ESP32Cam works ok and that the resolution is to your liking.
The cams settings can be altered by putting the ESP32-cam's IP number in your browser. The cams webpage will open and there you can alter all settings like resolution. So next to the Blynk connection the ESP-cam's webpage keeps on functioning. Even the streaming function works although that will be stopped for a split second when you take a picture with Blynk.
These lines are added to the beginning of the setup() routine to set the ESP32 Cam's pins in the right mode.
In these lines the program gets the local IP number of the cam. We will need this to tell Blynk at what IP number the photo to be send can be obtained.
The last line has been added. This line gives all the information to connect to my local Blynk server. Replace the XXX's with the IP number of your own local Blynk server.
If you do not have your own local Blynk server you can replace the line by the above line. This connects the ESP32 Cam to the cloud based Blynk server.
The loop tests wether the physical button on the ESP32-Cam (the doorbell buutton) is pressed. If that is true it calls the blynkphoto() routine that actually sends the photo.
Besides the physical button there is also the virtual button attached to GP14 whic is controlled from the Blynp App. If that is pressed there also will be a photo send to the app.
The doorbell in action
Well not really. This was a proof of concept and I wanted to test wether the ESP32Cam was capable of working as a doorbell. And it is. I the webcams webpage I set the resolution low so pictures would be transferred fast to Blynk. Better resolution is better quality.
Here is a sample picture I took from my 3D printer.
The doorbell is one way for using this. You could change the physical button by a PIR or a RCWL-0516 radar module to detect movement instead of pushing a button. Use velostat and define an IO pin as an analog input to detect pressure. Use these methods to detect who is stealing your cookies. Or build a bird feeding place that sends you a picture when a bird comes to dinner.
Re-read the story about using multiple ESP's with Blynk. With this information you can build a remote controlled car with a camera on it.
I bet you can come up with a lot of projects too. The price of the ESP32Cam should be no objection.
Till next time