I'v been trying to set up the DYP-ME007TX ultrasonic sensor,which has one pin for Transmit and Recieve, using the Ping example that comes with arduino Duemilanove software. Unfortunately until now i can't make it work. In sensors data sheet says that the triggering pulse should be 8 "highs" and 8 "lows".So ;
Firstly i don't know how to count 8 "highs" because i dont know how to calculate the Tb(bit period).
Secondly i'm getting a return of "1" in Serial.Print (duration)
I have used in the past a similar sensor but with one pin for transmit and one for recieve and it worked perfetcly(the triggering pulse was 10us) so i tried to run this sensor with a 10u triggering.
Can you help me find how much is the Tb of the Avr given its cloak is 16MHz.
And suggest another solution to my problem.
By the way in sensors data sheet was saying that it has arduino library. which i never found anyware.
Seems to be not so much wrong at first sight. so it might be some critical timing
From the datasheet A short ultrasonic pulse is transmitted at the time 0, reflected by an object. The senor receives this signal and converts it to an electric signal. The next pulse can be transmitted when the echo is faded away. This time period is called cycle period. The recommend cycle period should be no less than 50ms. If a 10?s width trigger pulse is sent to the signal pin, the Ultrasonic module will output eight 40kHz ultrasonic signal and detect the echo back. The measured distance is proportional to the echo pulse width and can be calculated by the formula above. If no obstacle is detected, the output pin will give a 38ms high level signal.
so I modded the code a bit , might help (or not
const int pingPin = 7;
void setup()
{
Serial.begin(9600);
}
void loop()
{
long duration, inches, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delay(60); // Keep it LOW for at least 50 ms
digitalWrite(pingPin, HIGH);
delayMicroseconds(10); // 10 us is OK
digitalWrite(pingPin, LOW);
// max delay of 8 x 25 uSec for the 8 40 Khz pulses
// you might be listening too fast
delayMicroseconds(150);
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
if (duration > 37500) // 38000 plus some margin
{
Serial.println("no obstacles found");
}
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(duration);
Serial.print(", ");
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
}
long microsecondsToInches(long microseconds)
{
return microseconds / 148;
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds /58;
}
As a return for the duration im getting a constant high "1" and as a return of in or cm im getting "0"
It's either im doing something wrong in the hardware part like cables etc or the sensor is broken..
But i must plug only 3 cables VCC GND and OUT and have tried em on a new breadboard in different spots with different cables and the sensor was brand new never used before.
Thank you alot for your help. Always electronics will have their ways to frustrate us i reckon..
I had the same problem, but I think that I solve it!
Basically, this ultrasonic range sensor (DYP-ME007TX) has a unidirectional serial interface, using a baud rate equal to 9600 baud. So, I implemented a simple block of code which uses the software serial library to implement its communication protocol described as:
This module will occupy in the use of a microcontroller IO port, connect the power, the modules within the distance once every 50ms, and from the pin OUT one, with four 8-bit data frame format is: 0XFF + H_DATA + L_DATA + SUM 1. 0XFF: as a starting data for judgments. 2. H_DATA: from the high 8-bit data. 3. L_DATA: from the lower 8 bits of data. 4. SUM: data and, for efficacy. The 0XFF + H_DATA + L_DATA = SUM (lower 8-bit only) Note: H_DATA and L_DATA synthetic 16-bit data, ie the distance in millimeters values.
You can see next the code. Any error/doubt please ask me!
#include <SoftwareSerial.h>
// TX_PIN is not used by the sensor, since that the it only transmits!
#define PING_RX_PIN 6
#define PING_TX_PIN 7
SoftwareSerial mySerial(PING_RX_PIN, PING_TX_PIN);
long inches = 0, mili = 0;
byte mybuffer[4] = {0};
byte bitpos = 0;
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
}
void loop() {
bitpos = 0;
while (mySerial.available()) {
// the first byte is ALWAYS 0xFF and I'm not using the checksum (last byte)
// if your print the mySerial.read() data as HEX until it is not available, you will get several measures for the distance (FF-XX-XX-XX-FF-YY-YY-YY-FF-...). I think that is some kind of internal buffer, so I'm only considering the first 4 bytes in the sequence (which I hope that are the most recent! :D )
if (bitpos < 4) {
mybuffer[bitpos++] = mySerial.read();
} else break;
}
mySerial.flush(); // discard older values in the next read
mili = mybuffer[1]<<8 | mybuffer[2]; // 0x-- : 0xb3b2 : 0xb1b0 : 0x--
inches = 0.0393700787 * mili;
Serial.print("PING: ");
Serial.print(inches);
Serial.print("in, ");
Serial.print(mili);
Serial.print("mili");
delay(100);
}
To be honest, I don't like this sensor very much, because I cannot control when I want to take a measure of distance (send a ping)... and I want to use multiple similar devices, so I need to control when I want to send a ping in each one in order to avoid interference/overlap!
I have the same sensors, these work as a serial output device. I've not figured it out either, as all the information on the forum is based on the Paralex device, which simply output a digital high.