Go Down

Topic: DYP-ME007Y - Ultrasonic distance sensor - How to disable automatic trigger (Read 39 times) previous topic - next topic

danielcugler

Hy guys,

I am using the DYP-ME007Y waterproof ultrasonic distance sensor (this version) . It is working fine, but I have a problem. I need to use two sensors close to each other. In order to avoid they are going to interfere with each other, I need to assure that each of them is going to send the ultrasonic pulse (trigger) at distinct times.

However, this sensor model send several pulses per second automatically. In addition, if I do not wire the trigger pin, the sensor keeps working (I do not know why it has a trigger pin).

Below follows the code I use to read the distance from sensor:

Code: [Select]

#include <SoftwareSerial.h>

SoftwareSerial distance_sensor1(5,6); //(echo, trigger)

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

void loop(){
  Serial.println(ping_sensor1());
}

int ping_sensor1() {
  byte read_buffer[4] = {0,0,0,0};

  byte readByte;
  byte checksum;
  int distance;
  bool ischecksumok = false;

  distance_sensor1.listen();
 
  do {
    if (distance_sensor1.available() >= 1) {
        readByte = distance_sensor1.read();
       
        for (byte i = 0; i <= 2; i++) {
          read_buffer[i] = read_buffer[i + 1];
        }

        read_buffer[3] = readByte;

    } 
   

    if (read_buffer[0] == 0xff) {
      checksum = read_buffer[0] + read_buffer[1] + read_buffer[2];

     
      if(checksum == read_buffer[3])
        ischecksumok = true;
    }
 
  } while(!ischecksumok);
 
  distance = (read_buffer[1] * 256) + read_buffer[2];
  distance = distance /10; //converting to cm
 
  if(distance < 0 || distance > 250)
    distance = 0;

  return distance; 
}



Do you guys have an idea about how to control when the pulse is sent? (disable automatic trigger)

Thanks!

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy