WT81B003-0202 (Ultrasonic long distance sensor)

From Bambi
Revision as of 23:32, 3 August 2017 by Florian (talk | contribs) (Added prototyping script)
Jump to: navigation, search

The Waytronic WT81B003-0202 18m (see [1]) should be able to provide distance measurements at least every 250ms up to 18m with a tolerance of +-10cm.

It can be set in various operation modes, one of those communicates through a standard serial protocol (9600/8-N-1). Using an Arduino board equipped with an uart port it's possible to test the sonar performance. The sketch can be found at https://mega.nz/#F!Bo8jHabQ!kwxQR5jFZorFaOLdQKsTdw)

UART prototyping on Raspberry PI

To quickly see what the sensor transmits on the UART ports, we can use a raspberry pi and a python script. See Using UART on Raspberry PI

The wiring is simply the TX UART pin connected with the RX pin of the sensor and the TX of the sensor connected through a voltage divider (5K1, 10K) to the RX UART pin of the raspberry.

GPIO Pinout

The following python script then does all the work easily. A test output can be 1.26m 25.1°.


#!/usr/bin/env python
# -*- coding: utf-8 -*-

import serial
import binascii
from struct import *

ser = serial.Serial("/dev/ttyAMA0")
ser.baudrate = 9600

ser.write("\0")
output = ser.read(6)
header, distance, temp, checksum = unpack(">cHhc", output)

#print(binascii.hexlify(output))
	
print("%.2fm, %.1f°" % (distance/1000.0, temp/10.0))
ser.close()

Datasheet

The original datasheet is in Chinese, the following version was translated with Google Translate: