How to set up US 100 with serial monitoring

I want to use the US-100 ultrasonic sensor with Arduino uno to measure water level. But the before using it for liquid level measurement I am putting an object in front of it with a scale at the side. The sensor is giving very poor precision. When I move away the object it is sometimes showing a lower distance value. Even when I'm getting increased value the precision is not the same as I have read as 0.3 cm.

I am using the following code. I am a beginner and don't have much experience pls guide.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(3, 2);

unsigned int HighByte = 0;
unsigned int LowByte  = 0;
unsigned int Len  = 0;

void setup() {
  
  Serial.begin(9600);
  mySerial.begin(9600);
}

void loop() {
  mySerial.flush();
  mySerial.write(0X55);                           // trig US-100 begin to measure the distance
  delay(500);                                  
  if (mySerial.available() >= 2)                  // check receive 2 bytes correctly
  {
    HighByte = mySerial.read();
    LowByte  = mySerial.read();
    Len  = HighByte * 256 + LowByte;          // Calculate the distance
    if ((Len > 1) && (Len < 10000))
    {
      Serial.print("Distance: ");
      Serial.print(Len, DEC);          
      Serial.println("mm");                  
    }
  }
  delay(300);                                    
} 

I just want a correct way to set it up with my Arduino uno and get readings with a precision of at least 0.5 cm

To my knowledge you need a better sensor.

1 Like

Water will be a flat surface for the ultrasonic. Are you using a flat hard surface to do the reflection tests?

1 Like

Tell us the whole story so that we can find an appropriate and smart solution for your project.

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