Send signal from Arduino-UNO to ESP32-CAM when Ultrasonic has less than desired distance

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 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:
image

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 :slight_smile:

Unless you have other things going on on your Arduino, and thus need it, I'm thinking it could all be done on the ESP32-CAM as boards can have sensors attached. ESP32 - Ultrasonic Sensor | ESP32 Tutorial

1 Like

Thanks for the link. It is really helpful, but I need to use Arduino because it is an assignment. I also use ESP32-Cam and not any ESP32.

Did a search on how to reboot/reset ESP32-CAM without pressing the button using DuckDuckGo "soft reset ESP32", and I think you have the wrong method. As it's an assignment you should be able to use this to help.

Can you paste the link with the correct "soft reset"?

Just google the words: soft reset ESP32
The 1st hit should be good.

I see that I must use ESP.restart(), but I can not use this in the code inside Arduino. My problem is ESP32-Cam to read distance from ultrasonic, through Arduino.

Looking at your ESP program, after it does the photo it puts the ESP32 to sleep with
esp_deep_sleep_start(); and the reset button is used to restart the script.

There are otherways to restart the ESP32 as defined in https://lastminuteengineers.com/esp32-deep-sleep-wakeup-sources/ for your case probably using ext0 External Wake-up Source and sending 1 high signal from Arduino to defined pin ext0 on ESP32.