ESP32-CAM doesn't receive the code

Simple code to identify the color red.

My hardware connections via jumper wires are:

  • GND of the Arduino Uno to the GND of the ESP32-CAM;
  • 5V output of the Arduino Uno to the 5V input of the ESP32-CAM;
  • TXD pin of the ESP32-CAM to the pin 1 on the Arduino Uno;
  • RXD pin of the ESP32-CAM to the pin 0 on the Arduino Uno.

The code:

#include <Wire.h>
#include <esp_camera.h>

// Define the pins for ESP32-CAM
#define ESP_TX 1  // Connect ESP32-CAM TX to Arduino Uno RX (pin 1)
#define ESP_RX 0  // Connect ESP32-CAM RX to Arduino Uno TX (pin 0)

void setup() {
  Serial.begin(115200);       // Initialize serial communication with the computer
  Serial1.begin(115200);      // Initialize serial communication with ESP32-CAM
  
  Serial.println("Arduino setup");
  // Wait for serial communication to be established
  while (!Serial) {
    delay(10);
  }

  Serial.println("ESP32-CAM Serial Communication Initialized");

  // Camera setup
  camera_config_t config;
  config.pin_d0 = 21;
  config.pin_d1 = 22; 
  config.frame_size = FRAMESIZE_VGA;  // Adjust frame size as needed

  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x", err);
    return;
  }
}

void loop() {
  // Your code goes here
  
  // Example: Send a message from Arduino Uno to ESP32-CAM
  Serial1.println("Hello from Arduino Uno!");

   // Capture an image
  camera_fb_t *fb = esp_camera_fb_get();
  if (!fb) {
    Serial.println("Capture failed");
    return;
  }

  // Process the captured image
  int redPixelCount = 0;

  for (int i = 0; i < fb->len; i += 3) {
    // Check if the pixel is red (adjust thresholds as needed)
    if (fb->buf[i] > 100 && fb->buf[i + 1] < 50 && fb->buf[i + 2] < 50) {
      redPixelCount++;
    }
  }

  // Print the result to the Serial Monitor
  if (redPixelCount > 100) {
    Serial.println("Red detected!");
  } else {
    Serial.println("No red detected.");
  }

  // Release the frame buffer
  esp_camera_fb_return(fb);

  delay(1000); // Adjust delay as needed
}

Board:
AI Thinker ESP32-CAM;

Error:

A fatal error occurred: Failed to connect to ESP32: No serial data received.

Try this tutorial.

This connects a 5V output (Uno TX) to a 3.3V input (ESP32 RX), which will not function, and can actually damage one or both devices. A logic level shifter is required for that connection.

Check the GND connection on the ESP32CAM as well, on some ESP32CAMs one of the GND pins is actually connected to the ESP32 EN\Reset pin.

Follow post #11 @GolamMostafa of the following thread:

So I just need to get a logic level shifter for a proper connection, and supposedly the message "Red detected!" will show up on the serial monitor if the capture taken by the ESP32-CAM has red?

I'm sorry, I'm quite new to this forums so I'm not sure if you got notified by my other comment.

Would a logic level shifter allow the serial monitor to showcase the message "Red detected!", if the esp32-cam capture has red? Or would other hardware/code changes be required?

The level shifter is required for communication.

I have no idea whether your program will run and do as you wish.

Alright, thanks for the help.

I'm having problems, the error remains the same after I used a logical level shifter.
I'm utilizing a "Voltage Converter / Level Shifter, TXB0104".

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.