How to Use ESP32 with HCSR04 Ultrasonic Sonar sensor and Arduino IDE
Вставка
- Опубліковано 17 тра 2023
- Affiliate Link for
ESP32:- dir.indiamart.com/impcat/wifi...
Boards Manager link-
raw.githubusercontent.com/esp...
Code and Circuit Diagram-
github.com/harshkzz/ESP32-HCS...
For any business queries contact us at inovatrixhelp@gmail.com - Наука та технологія
its working fine sir, thanks a lot
Thanks you so mutch
Thank you, working fine
thanks man it works
thanks
Thanks!
By the way, after a research can get data from ultrasonic module just by using 2 wires by carry data over dc lines :)
can you share the link to read about?
O meu sensor ultrasonico hc sr04 nao está funcionando no 3.3v, sabe o que poderia resolver?
Connect power to VIN pin on the ESP32 Board.
@@INOVATRIX to receive the echo return, would there be damage to the esp32 input pin?
how do i open the link to see the code and circuit
All given in description.
distances under 40 cm can be measure without problem, more that that i just get random values. Any idea how solve it?
That is the approximate limit of the sensor. For more range you'll need to use more expensive and accurate sensor
i am using one HCSR04 with one Arduino Mega 2560 and can measure easily 2 mts in a water tank, but with ESP32 works bad, any idea?@@INOVATRIX
Will the same code work for esp8266?
Yes it should work, just make sure that you select the right pins.
@@INOVATRIX tysm!
The distance is always 0 cm. I am using a 3 3v esp8266. What is the issue?
I ran mine with a similar code, but it keeps sending me the Distance:0
Me to😢😢😢
IF YOU HAVE 0CM USE 5V instead of 3,3V!!!!!!!!!!!!!
i get a measurement of 0 how do i change it to 5V
@@nrlauliasaid8007 there is a 3,3v and a 5v output on the esp32 change it to 5v
How i can do it
This board iS 5V..... not great.
AliExpers has a new version for 3-5 volts
bad. It is not async and uses blocking functions. slow
No its good😊😊
Use this code instead and connect the VCC to VIN (Notice I changed the pins and the serial monitor baud)
#include
#define echoPin 18 // CHANGE PIN NUMBER HERE IF YOU WANT TO USE A DIFFERENT PIN
#define trigPin 5 // CHANGE PIN NUMBER HERE IF YOU WANT TO USE A DIFFERENT PIN
long duration, distance;
void setup(){
Serial.begin (115200);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop(){
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration / 58.2;
String disp = String(distance);
Serial.print("Distance: ");
Serial.print(disp);
Serial.println(" cm");
delay(1000);
}
Thank you so much. It works! But can you tell me the reason why you have thought to make this change & why was that one not working?