--- title: "Arduino laser distance meter" date: 2013-07-27 ---
image:ut390b_front.jpg[Uni-T UT390b laser distance meter front view]
## Uni-T UT390B UPDATE 2: Serial commands and timing information are now available [here][1]. UPDATE: I've posted code to parse the serial datastream [here][2]. This is a tutorial on how to get serial data out of a cheap handheld laser distance meter, which can be fed into an Arduino or a PC. You can use the distance measurements in all sorts of projects like robots and quadcopters. There are vendors who sell conversion kits that sniff the distance measurement off the LCD and output it over serial. The problem with those kits is that they cost more than the laser meter itself. Luckily I managed to find a laser distance meter that outputs distance measurements over serial directly: the UT390B from Uni-T which sells for about $56 from online retailers. Laser distance meters use precise electronics to measure the length of time it takes a laser beam to reflect back from a target. Handheld units like this one have a range of about 0.2m - 40m with a precision of 2mm. They're a great replacement for HC-SR04 ultrasonic sensors if you need long range measurements. ## Preparing the unit You can see the unit's debugging port underneath the battery cover. To take it apart, remove the 2 visible screws. image:back.jpg[UT390b device with battery cover removed showing debug pins] Now you can pry off the cover. image:cover.jpg[UT390b with front cover open] This ribbon cable connects the unit's keypad. Scrape off the glue and unplug it for now. image:ribbon.jpg[The ribbon connecting the two halves of the UT390b device] Next, remove the 2 screws with washers that hold the rubber piece at the front. If you want to remove the screen, it's connected by 4 clips to the circuit board. It's probably a better idea to leave the screen connected, so you can verify that the unit is working properly while you're testing your serial parsing code. image:lcd.jpg[Removing the screen from ut390b device] **DON'T** remove these 3 screws. They connect the laser diode to the circuit board, and if you loosen these screws you risk breaking your laser. image:screws.jpg[3 screws on circuit board which should not be removed] The easiest way to access the debug port is by desoldering the battery connector as shown below. Note: this photo shows the 3 screws removed. **DO NOT** do this, as it's unnecessary and could cause the unit to break in two. image:dont.jpg[Removing the ut390b circuit board (don't do this)] Finally you can solder some thin wires to the debug port. The pinout is as follows, seen from below the board. image:pinout.jpg[Pinout of ut390b debug pins. from left to right: GND, RX, TX,\ BOOT0, VCC (2.7V)] We can replace the original keypad with a microcontroller which can simulate button presses to control the unit. The keypad pinout is below. The ribbon connector is 8 pin, 1mm pitch. If there's enough interest, I will assemble and sell a small interface board to break out the necessary signals. image:lcdpinout.jpg[Pinout of ut390b keypad ribbon connector. From left to \ right: Unit, n/c, Func, On, GND, Mode, n/c, Off] ## Decoding the serial output This unit's serial port runs at 115200 baud (8N1). On bootup, it outputs the following text with `\r\n` line endings: ``` ldpara:395 curent ver:420411 Year:Jan 21 2013 Time:13:53:10 ldpara:395 Iint OK APDMIN=136 APDMAX=167 BIASVOLMIN=2307 BIASVOLMAX =1718 ``` Notice "APDMIN" and "APDMAX", which are likely calibration values for the avalanche photodiode used to detect the reflected laser beam. A few sloppy printfs as well.. To turn the unit on, connect the ON signal to GND for about 300ms. Once it's on, the ON signal is also used to take a measurement. After a measurement is taken, the unit outputs the following: ``` Dist: 2827,curtemp =21 V2.0 nDist: 2827,tempDv=0 ``` The Dist and nDist values are in millimeters. As far as I can tell, the two measurements are always identical. If there's a measurement error (Error 154, out of range or sensor error) the unit will output: ``` OUT_RAN dist = 30 ``` If the unit can't determine the average distance (Error 160, sensor shaking too much or Error 155, signal too weak) the unit will output one of the following lines: ``` MEDIUM2 AND THIN NOT MATCH MEDIUM1 AND MEDIUM2 NOT MATCH THICK AND MEDIUM1 NOT MATCH MEDIUM1 AND MEDIUM2 NOT MATCH ``` When you turn it off, it outputs: ``` SysPowerOff! WriteTestData TRUE Serial input? ``` I'd like to find a way to control the unit over serial. So far all I've found is that sending 0x23 ('#') or 0x73 ('r') will cause the unit to power down. It seems to ignore every other byte, as well as some common english words and modbus commands. If you manage to find any other byte sequences, [email me](mailto:qartis@gmail.com) or leave a comment below. If you liked this article, you might also like DORI, my robot project. DORI uses a slightly different laser distance measurement strategy. You can learn more on the [project homepage][3] and in [my thesis][4]. [1]: /laser-distance-meter-update-serial-commands-timing-measurements/ [2]: /parsing-laser-distance-meter-serial-output/ [3]: http://dori.qartis.com [4]: http://arxiv.org/abs/1304.5568