I have an Ultrasonic sensor connected with my Arduino-UNO for calculating distance. I also have an ESP32-CAM, that when I press the RESET button, it captures a picture and saves it to an SDCard. What I am trying to do, is when the distance from Ultrasonic is less than 15cm, the Arduino will trigger the ESP32-CAM to take a picture and save it to the SDCard.
- I have uploaded the code to Arduino, for calculating distance.
- I have uploaded the code to ESP32-CAM to take picture and save it (that happens, when I press the RESET button). The code is extracted from this page: https://randomnerdtutorials.com/esp32-cam-take-photo-save-microsd-card/
I have read somewhere, that in order to trigger the RESET button, I need to trigger the GPIO 0 and GND of the ESP32-CAM together. In my case, these are connected to pins 12 & 13 of the Arduino. So the code in Arduino is this:
#include <Ultrasonic.h>
Ultrasonic ultrasonic(10, 9);
int distance;
#define WAIT_TIME 5000
void setup() {
Serial.begin(9600);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
}
void loop() {
// Pass INC as a parameter to get the distance in inches
distance = ultrasonic.read();
if (distance <= 15) {
Serial.print("You are gonna crash! Distance in CM: ");
Serial.println(distance);
// Trigger GPIO0 and GND.
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
delay(WAIT_TIME);
} else {
Serial.print("Distance in CM: ");
Serial.println(distance);
}
delay(300);
}
But nothing works when Ultrasonic is triggered. It just delays for the WAIT_TIME and then it continues again calculating the distance. Here is the Serial Monitor:

Please ask for any other explanation you may need. Thanks in advance!
P.S. I am total newbie in stuff like that, so please try to explain to me with simple words ![]()