I bought these UM0090 ultrasonic sensors to try in my project. It said in the datasheet that it used USART(TTL) communication to get data from the sensor. I can't seem to get the data from it.
I attached the data sheet for Sensor. I use Arduino Mega 2560.
My connections are as follow:
5V to sensor 5V
GND to Sensor GND
Digital pin 12 to Sensor Pin4.
Rx0 on mega to Sensor Pin2.
I attached my code as well.
char incomingByte; // for incoming serial data
int trigPin = 12;
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode(trigPin, OUTPUT);
Serial1.begin(9600);
}
void loop() {
// digitalWrite(trigPin, HIGH);
delayMicroseconds(100);
digitalWrite(trigPin, LOW);
delayMicroseconds(60);
// send data only when you receive data:
if (Serial1.available()) {
// read the incoming byte:
incomingByte = Serial1.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte);
}
}
The datasheet asks for a 50us trigger pulse with 20ms between triggers.
The serial out is an eleven byte stream ending with 0xFF.
Try setting up your loop to send a LOW, wait 50us, HIGH trigger signal.
Then print out all serial bytes until you get a 0xFF or eleven of them.
Wait 20ms, then loop again.
I purchased 2 of these sensors to make a prototype.
After a few hours of fussing with the program, the best I could do is recover a "252" when I performed a serial.read to an integer. The serial.available was just a single character each time I woke the sensor. When I serial.read to a char it was an upside down question mark (or something similar)
I have tried adjusting the delays on the front and back end of the serial.read, but it only delivers a 252.
In a nutshell the program executes the following:
HIGH trigger for 1 second
LOW trigger for 60 us
HIGH trigger
serial.read until buffer is empty
Delay 1 second
Loop again
Has anyone else been successful in talking to these sensors?
We bought this sensor but we can not use it. If there is someone who use this sensor, please share the example codes. Thanks in advance! AUDİOWELL UM0090-000
char incomingByte; // for incoming serial data
int trigPin = 12;
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600
//bps
pinMode(trigPin, OUTPUT);
Serial1.begin(9600);
digitalWrite(trigPin, HIGH);//write high
}
void loop() {
digitalWrite(trigPin, LOW);//write low
delayMicroseconds(1000);//delay 1ms
digitalWrite(trigPin, HIGH);//write high
delayMicroseconds(50000);//delay 50ms
//until measurement finish,you cannot read correct
//data during this time
// send data only when you receive data:
if (Serial1.available()) {
// read the incoming byte:
incomingByte = Serial1.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte);
}
}
So I got this strange sensor working.
Pinout of UM0090 according to the datasheet:
Vcc
Gnd
Output
Rx
The pin 4 is the trigger and pin 3 is serial output from the UM0090. So connect pin 4 to GPIO and send a low pulse for over 50 us then the response from the sensor comes after about 13 ms.
I checked the response with a logic analyzer and noticed that the baud rate was not 9600 according the datasheet but exactly 9000 bits/s.
int trigPin = 12;
void setup() {
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, HIGH);//write high
}
void loop() {
digitalWrite(trigPin, LOW);//write low
delayMicroseconds(100);//delay 1ms
digitalWrite(trigPin, HIGH);//write high
delay(200);//delay 50ms
}
Anders,
i have this sensor on the table and I am just trying your code example and Frank's as well.
But do you have a complete sketch for UNO maybe?
And maybe you want to verify Microseconds (code) vs. ms (comments).