ESP32-CAM connection with HC-SR04 ultrasonic sensor

I have an ultrasonic sensor connected with my ESP32-CAM AI Thinker which is powered by an ESP32-CAM-MB. I am pretty new to Arduino, so my sensor is connected to 5v, ground, trigger to gpio13 and echo to gpio15. I am using the sensor to measure distance between an object, once the object is near, the camera takes an image and preferably save it to the SD card.

However when my sensor is connected, the SD card mount fails. Exiting with sdmmc_io: sdmmc_io_reset: unexpected return: 0x108. After some tests, if I remove the echo pin cable from the board according to the pinout it's the hs2-cmd, the SD card will mount properly. How can I actually connect the sensor to the board without loosing the SD card functionality? Will I need to use some sort of Master/Slave approach if so how ?

Use an other pin, for echo, than pin 15.

Using the SD Card in 1-Bit Mode on the ESP32-CAM from AI-Thinker – Dr. Mountain (dr-mntn.net)

As shown above, the ESP32-CAM uses the GPIO pins GPIO02 , GPIO04 , GPIO13 and GPIO15 for reading and writing data to the SD card.

Might need to use different pins for the sro4 thingy.

1 Like

Hi,
When using sd card on the esp32cam there are very limited spare gpio pins.
pin 13 is used by the sd card but you can get round this by putting the sd card in "1 bit mode", this then leaves pins 12 and 13 available (12 must not be high at boot).
see my sketch below which demonstrates using 1 bit mode and the gpio pins

Note: I have been told reading the sd card in 1 bit mode can be an issue, I have only written to it myself

Note: above post beat me to it :slight_smile:

1 Like

Thanks for the examples @Idahowalker, @alanesq and explanation! I will have a look tomorrow, hopefully the project turns out as it should.

Note: I have checked, and it is working indeed. Thank you for both of your prompt answers.

1 Like

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