Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15374

'Adapted' ultrasonic sensor + Arduino Uno, does not work as expected

$
0
0

Hey guys,

I took a 4-output reverse gear sensor that I had sitting here and tested it on the bench. He actually scored correctly with an obstacle 1.2 meters away, see in this photo.

PlacaSensorUltrasom

I intend to measure some distances and I don't want to wait thirty days to receive a JSN-SR04T sensor (which would be correct).

So I decided to connect this sensor to an Arduino UNO R3. I noticed that it only shows 14-15 cms.

Sometimes I notice a small variation that is typical of a poorly regulated ultrasound (which is what I have here).

I don't have an oscilloscope to measure the duration of the pulses and so I suspect it will be pure luck to vary delayMicroseconds values ​​in the code below. And I don't think I would achieve the desired success even then.

Note that I have the display. Maybe I could send data from the Arduino UNO to it, and when it worked I would have the values ​​to put in the sensor reading code, but I lack programming knowledge for that.

#define trigPin 3
#define echoPin 2
 
long duration;
int distance;
  
void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  delay(2000);
  Serial.begin(115200);
}
 
void loop() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(5);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);

  distance = duration*0.034/2;
 
  Serial.print("Distance = ");
  Serial.print(distance);
  Serial.println(" cm");
  delay(100);
}

I came here in the hope that someone has already done something similar because this reverse gear sensor (parking sensor) is very common to use. And as the community here is very creative, I thought someone might already have some good answers.

Does anyone have any...try this?

Thanks

4 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 15374

Trending Articles