Waterproof ultrasonic sensor measurements problems

Hello, I have a problem with the measurements from the sensor because it no longer measures then 2.2 meters, but in the description it said that it measures about 5 meters. What can I change in the code ??

this is my code:

#define TRIGPIN 11
#define ECHOPIN 10

float duration, distance;

void setup() {
Serial.begin(115200);

pinMode(ECHOPIN, INPUT);
pinMode(TRIGPIN, OUTPUT);
}
void loop() {

digitalWrite(TRIGPIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(20);
digitalWrite(TRIGPIN, LOW);
duration = pulseIn(ECHOPIN, HIGH);

distance = (duration / 2) * 0.343;

Serial.print("distance: ");
Serial.print(distance);
Serial.println(" mm");
delay(100);

Your topic was MOVED to its current forum category as it is more suitable than the original

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Your code is incomplete and lacks code tags.
(pulseIn does not return a float, and you told us nothing about your sensor other than it might be waterproof)

You can post code by using this method that adds the code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

best regards Stefan

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