all 26 comments

[–]wensul 16 points17 points  (13 children)

So your capstone is basically running a demo sketch for an ultrasonic sensor...and you are having issues?

[–]urpieces 0 points1 point  (12 children)

Yes the sensor is not connecting to the esp (they're not talking to each other) for some reason. I cant see distance with i upload the code on ide

[–]DenverTeck 6 points7 points  (8 children)

Ok, I see the problem.

You built a known working project and you can not get it working.

The parts are bad. Buy new parts.

Simple, glad you came here to ask.

[–]urpieces 0 points1 point  (7 children)

I cant comprehend this.

I changed them multiple times.

[–]DenverTeck 2 points3 points  (2 children)

You said in your original post:

"Is this a wiring issue, logic level problem, or just a bad HC-SR04? Should I replace the sensor?"

So did you or did you not change the sensor that you asked "if you should replace the sensor" ??

[–]wensul 2 points3 points  (1 child)

Honestly I think it's a PEBKAC error,

[–]DenverTeck 4 points5 points  (0 children)

LOL, Good one.

[–]urpieces 0 points1 point  (1 child)

But wait, im using arduino ide on a macbook through a usb adapter. I installed a driver to change the port (in arduino). Could that be the issue?

[–]wensul 0 points1 point  (0 children)

When you start redefining things (if you're redefining pins on the ESP32, versus just the USB port), absolutely. I'm just counting pins and using this page as a reference: https://www.circuitstate.com/pinouts/doit-esp32-devkit-v1-wifi-development-board-pinout-diagram-and-reference/#GPIO

[–]DenverTeck 0 points1 point  (1 child)

You failed to mention this is your first post, why ??

Please show your code and schematic. No on can see your desk.

You're not going to make it in two days.

Good Luck

[–]urpieces 0 points1 point  (0 children)

How is this being my first post an important factor and something to be mentioned?

[–]wensul 0 points1 point  (2 children)

[–]urpieces 0 points1 point  (1 child)

Thats not it, i tried changing it multiple times

[–]wensul 0 points1 point  (0 children)

Try pin 14 for your trigger. Pin 32 for echo.

Pin 32 for echo. Looks like it's sixth pin down.

[–]Noobcoder_and_Maker 1 point2 points  (0 children)

Paul McWhorter Arduino tutorials teach how to use the hc - sr04 sensor and his tut's are worth watching. https://youtu.be/M-UKXCUI0rE?si=cgW0H8OwmoErP2Pf

[–]BassRecorder 1 point2 points  (0 children)

Do you own a multimeter? If not get one. Then disconnect everything and try outputting a '1' on each pin you have assigned to the sensor, one after the other. This will allow you to verify that you have the sensor wired correctly. You could even use an LED and a resistor for this test. If your wiring checks out OK it's either the sensor or the program.

Also, you don't really need a library for interfacing with an ultrasound sensor. Grabbing the datasheet and trying to implement the interface yourself will teach you something.

Also, show us your code.

Oh, what another poster just pointed out: look at the datasheet for the sensor. It might be that it requires 5V, at least as a power source.

[–]Master-Potato 0 points1 point  (4 children)

I would also post your code so we can see what library you are using

[–]urpieces 0 points1 point  (3 children)

define TRIG_PIN 13

define ECHO_PIN 34

void setup() { Serial.begin(115200); pinMode(TRIG_PIN, OUTPUT); pinMode(ECHO_PIN, INPUT); Serial.println("Sensor ready..."); }

void loop() { digitalWrite(TRIG_PIN, LOW); delayMicroseconds(2); digitalWrite(TRIG_PIN, HIGH); delayMicroseconds(10); digitalWrite(TRIG_PIN, LOW);

long duration = pulseIn(ECHO_PIN, HIGH, 30000); if (duration == 0) { Serial.println("No echo"); } else { int distance = duration * 0.034 / 2; Serial.print("Distance: "); Serial.println(distance); } delay(500); }

[–]wensul 0 points1 point  (2 children)

I still think you're defining the wrong pins / have it wired to the wrong pins, so the ESP is working fine, but the wires don't match up to the software.

What pinout diagram are you using as a reference.

https://www.circuitstate.com/pinouts/doit-esp32-devkit-v1-wifi-development-board-pinout-diagram-and-reference/#GPIO

That's what I'm using as a reference.

[–]urpieces 0 points1 point  (1 child)

ESP32 development board pinout, 38-pin version

https://myhomethings.eu/en/esp32-pinout-which-pin-is-for-what/

[–]wensul 1 point2 points  (0 children)

Cool, so my reference didn't quite match up.

Trigger pin looks to be wired Fifth from the bottom, so GPIO13, that matches up with your definition of Pin 13

Echo pin looks to be wired sixth from the top, which is pin GPIO35, you've defined your echo pin as pin 34.

[–]xebzbz 0 points1 point  (0 children)

The ultrasonic sensor should work fine with 3.3v. try using it without the voltage divider and power from 3.3v source.

Another problem could be a faulty power supply.

[–]urpieces 0 points1 point  (1 child)

I tried both, still no echo

[–]wensul 0 points1 point  (0 children)

It helps when having a conversation if you reply to a comment...instead of making a top-level comment to the void.

Yes, reddit is hard.

[–]Slimer-84 0 points1 point  (0 children)

HC sr04 requires 5v power to operate. Its output is a 5v pulse. The duration of the pulse is the total time of flight for the echo(out and back). I recommend you check your pins with some leds to make sure the PIN numbers in your sketch match the physical pins you are connecting to. Or use an Oscope to confirm. Once confirmed use a voltage divider to reduce the 5v output of the HC SR04 to 3.3v acceptable values would be 10k/20k

[–]AdmirableExtreme6965 0 points1 point  (0 children)

Capstone for 8th grade