The popular ESP32 camera module that I discussed in my previous post has a large build in LED.
In the standard build in camera program, that LED is always on. In the ESP32 camera example that comes with the ESP32 core in the Arduino IDE, that LED is OFF, both programs have no possibility to toggle the state of the LED, which is a pity.
I had a glance at adding a button, that would be visible in the UI, but that seemed quite an undertaking(see footnote), and I thought it would be easier to use bluetooth for that.
In order to do that, we need to do the following:
Open the Camera example in the IDE and add the below statements to your declaration section (say right above the “// WARNING!!! Make sure that you have either selected ESP32 Wrover Module”)
#include "BluetoothSerial.h" #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it #endif BluetoothSerial SerialBT; int incoming; #define LED_BUILTIN 4
Once you have done that, go to the setup() section and add:
Serial.begin(115200); SerialBT.begin("ESP32Camera"); //Bluetooth device name Serial.println("The device started, now you can pair it"); Serial.setDebugOutput(true); Serial.println(); pinMode (LED_BUILTIN, OUTPUT);//Specify that LED pin is output
Subsequently go to the “loop” section. That should only have a delay(10000); statement. Replace the entire ‘void loop() by:
void loop() { // put your main code here, to run repeatedly: if (SerialBT.available()) //Check if we receive anything from Bluetooth { incoming = SerialBT.read(); //Read what we recevive Serial.print("Received:"); Serial.println(incoming); if (incoming == 49) { digitalWrite(LED_BUILTIN, HIGH); SerialBT.println("LED turned ON"); } if (incoming == 48) { digitalWrite(LED_BUILTIN, LOW); SerialBT.println("LED turned OFF"); } } delay(20); }
Upload that program and check if the camera functions as normal. Then you need some kind of Bluetooth application on your phone. There are various options, but I like “Serial Bluetooth Terminal“.
To pair the Camera, open the Serial Bluetooth Terminal and tap the 3 horizontal bars in the top left.
Then choose ‘Devices’, make sure you are in the Bluetooth Classic tab, and tap the cogwheel in the top right. There you can scan for available devices and once found pair with ESP32Camera.
Then go back to the ‘Devices’ menu you were before and choose ESP32Camera (it is likely the only one there). Tap the back arrow, so you are in the main terminal menu and tap the ‘connect’ icon in the top right (it is just left of the ‘delete bin’.
The terminal window will show you the connection status.
Then tap in the command window (the one at the bottom), your keyboard comes up and press 1, to turn on the LED and 0 to turn off the LED, press ‘send’ on yr keyboard, or the right arrow in the terminal to send yr command.
Full software found here.
Altering the CameraWebServer file.
Switching the LED ON and OFF, can be done through the webserver as well. One thing that cannot be avoided if you want to do that, is to alter the html file of the webserver. Where is that? Well it is a compressed file that is available in HEX form as the index_ov2640_html_gz, array in the camera_index.h file.
So, in order to change that, you need to convert it to an HTML file and after changing it code it again to HEX. Here I show how to do that.
Fortunately that is not something one needs to do oneself, as it already has been done. Also the Robotzero website discusses that topic.