How to use an Arduino to read the signal from a set of digital callipers and send the reading over USB.

This might be useful for accurate position sensing in home made / hacked computer aided manufacture systems. Adds USB functionality to your callipers.

A great reference on reading digital callipers can be found at:

What this instructable adds to the shumatech tutorial is:
How to use an Arduino to read the callipers (using very few extra components).
Details of another protocol found to be in use on some callipers.
Basic Arduino code is provided.

To see more of my work please visit j44industries.

Step 1: The Callipers

The callipers I have been working with were the Electronic Digital Callipers by Precision Gold. I bought the callipers from Maplin (item code N48AA) in the UK for just under £20.

After some experimenting with a multi meter and a  jyetech oscilloscope (a very cheap basic oscilloscope that can be bought in kit form for under £40) I found the pins to be as shown in the diagram.

Step 2: Voltages: Logic and Power

The Arduino uses 5V logic but the callipers output 1.5V logic. This is a bit of a bodge and may not always work, really a proper logic level conversion circuit should be used but the flowing is a simple hack that worked well with my Arduino:

My Arduino changed between logic high and logic low at about 2.5V (this could vary a bit between boards).

Connecting the positive pin on the callipers to the 3.3V supply means when the clock and data pins are connected to the arduino their voltage seems to vary between 3.3V and 1.8V, which is the Arduino reads as logic high and low respectively.

Powering the callipers with the Arduino:

To avoid needing a battery in the callipers the power circuit pictured can be used (remove the button cell). This method relies on using an LED to regulate the supply voltage for the callipers.

About 200Ohm

I used a 10uF which worked well, but there would be no harm in using a larger capacitance. 2V or more rating.

For the LED try to find one which has as close to a 1.6V drop across it as possible.
I used a red LED with a 1.8V drop across it. Red and IR LEDs tend to have low voltage drops across them.

Step 3: The Data Protocol

The data protocol used on my callipers was as follows:

Clock pulse as shown in the picture.

Reading the data on a falling clock edge gave a sensible output.

Example data output:

1,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,  (Screen shows 0.00 mm or 0.000 inches)
1,0,0,0, 1,0,1,1, 1,1,1,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,  (Screen shows 10.00mm)
1,0,0,1,  0,0,1,1,  0,0,0,0,  0,0,0,0,  0,0,0,0,  0,1,0,0, (Screen shows -1.00mm)
1,0,0,0,  1,1,0,0,  1,0,1,0,  1,1,1,0,  0,0,0,0,  0,0,0,0, (Screen shows 150.00mm)

Interpretation of data:

?,X,X,X, X,X,X,X, X,X,X,X, X,X,X,X, ?,?,?,?, ?,Y,?,?
? = Not sure
X's for a binary number with least significant bit at the start of the string. The binary number is the distance in mm times 100.
Y = Sign bit if Y = 1 number is negative if Y = 0 number is positive.

Note: make sure the callipers are set to mm the inches mode behaves very similarly except the least significant bit is used to show 1/2000ths of an inch.

Step 4: Arduino Code

This is a very basic Arduino code that should be compatible with several calliper data protocols.
There are commas in between each value to make it easy to use .CSV files to import the data into spreadsheets.

The main requirement of this code is that the data is read on the falling edge of a clock pulse.

Hopefully this code should mean when you connect your Arduino to the computer and use the serial monitor at 115200 Baud you will get sensible looking binary out.

Trouble shooting:
If the length of the binary strings changes a lot you may have the clock and data pins the wrong way around.


//Simple Digital Calliper Reader
//See http://j44industries.blogspot.com/

// Pin Declarations
int dataIn = 11;
int clockIn = 12;

// Variables
int clock = 1;
int lastClock = 1;
unsigned long time = 0;
unsigned long timeStart = 0;
int out = 0;

void setup() {
  // Pin Set Up
  pinMode(dataIn, INPUT);     
  pinMode(clockIn, INPUT);  

  Serial.println("Ready: ");

void loop(){

  lastClock = clock;
  clock = digitalRead(clockIn);

  if (lastClock == 1 && clock == 0){
    out = digitalRead(dataIn)+digitalRead(dataIn)+digitalRead(dataIn); // Tripple sampling to remove glitches
    if((micros() - time) > 800){
      Serial.println(" ");
    else if((micros() - time) > 400){
      Serial.print("  ");

    if (out > 1){
    time = micros();

<p>Congratulations, the trick about connect the 1.5V and 3.3V positives and use the led as voltage divider is very smart!</p>
<p>The example code doesn't perfectly correspond to the example data output.</p><p>In the code, a 400 microsecond delay will print out a single space character. But in the example data output, you have commas. </p>
<p>I got the exact same callipers yesterday from maplin for &pound;9.99 on sale :D Looking at doing this now, so I can use the calipers with my computer :D</p>
<p>Great! Congratulations!!</p>
<p>For the 52 bit Mitutoyo protocol, see https://www.instructables.com/id/Interfacing-a-Digital-Micrometer-to-a-Microcontrol/</p>
<p>I have a 5 pin Igaging Origin unit. Do you have any pinout data?</p>
<p>this is pretty freakin cool! :)</p>
<p>Thanks a lot for the example and the arduino code!</p><p>I find out how to convert the binary output from the caliper to decimal value, the caliper sends a 24bits package.</p><p>That package follows the pattern attached, so the value is in that 16 bits (from bit1 to bit16) reversed...</p><p>Example: My caliper measure 59.0mm, the data output was: 1,0,1,0, 0,1,0,0, 0,1,1,1, 0,1,0,0, 0,0,0,0, 0,0,0,0.</p><p>Reversing the 16 bits I got: 0001011100010010, wich, in decimal, is 5906</p>
<p>what is the purpose of the capacitor across the diode? I see the diode is a 'poor mans zener' and the series R is the current limit so the zener (I mean diode) won't burn out. but why do you need a cap across it? for extra filtering? you would be feeding clean dc to this, anyway, right?</p>
Your interpritation of the circuit is correct, I am probably being paranoid with the capacitor. It was to try to avoid any issues if the callipers briefly drew more power.
<p>hello sir, i am impressived by what you done for this project, but i have a problem, i try using different calliper(which is mitutoyo calliper) but i can't get any signal come out from the data or clock at all, is that because Mitutoyo Calliper have special way to send out the signal or its just my mistake on my process. </p>
<p>as was already discussed in the article, the mitutoyo protocol is NOT the same as this one. you would be wasting your time trying to apply this code to a Mit caliper.</p>
<p>This page mentions mitutoyo </p><p><a href="http://www.shumatech.com/support/chinese_scales.htm" rel="nofollow">http://www.shumatech.com/support/chinese_scales.ht...</a></p><p>but I don't know anything about it myself. No signal could mean voltage levels are not correct. An oscilloscope is highly recommended for this project. </p>
<p>Hi J44,</p><p>Thanks for your share, really helped me a lot. But could you give me some clues about how to read the measurement once a day and store it, or send it via nrf24l01 to a station? </p><p>I even couldnt understand well the data type that is printed on serial.</p>
Hi all, <br> <br>I have done a little work on the protocol for my scales, I am trying to use a single Arduino and LCDkeypad as a DRO for my lathe. <br> <br>In terms of the string format I have noticed that the last bit (bit 23) of the string is an output to determine whether the caliper is set to mm or inches. (You can only see this change though if you read the data line on the rising clock edge.) In my case 0 =mm 1= inches. <br> <br>I hope this helps some of you, as by reading this bit correctly, the setting on the caliper can become irrelevant if you just want to change the units once via the DRO interface.
And it reads 10 mm As <br> <br>0, <br>0, 0,0, 0, <br>0, 0, <br>0, 0, 0, <br>0, 0, <br>0, 0, 0, <br>0, 0, <br>0, 0, <br>0,0,0, 0, <br>0,0, <br>0, <br> <br>There is something wrong which i can't figure out. Please help
I exactly used the same config and code but my compiler is not reading 1 at all instead it gives out put for 0 mm as 0, 0,0, 0, <br>0, 0, <br>0, 0, <br>0, 0, <br>0, 0, 0, <br>0, 0, <br>0, 0, <br>0, 0, <br>0,0, <br>0, <br> <br> <br>Which does not matches with the output in the instruction. kindly help
I have found it. <br>The data must be converted backwards. <br>Now it works perfect.
Thank you for this manual. It works great. <br>I do not understand how I convert the data output to a number. <br>could you please help me?
and the WXWS's code does not show anything on the monitor at all.
dear J44 and friends, <br> <br>i have tried exactly everything same as J44 said.... <br> <br>but i am only getting &quot;ready, 0 &quot; on the serial monitor every-time i press the reset button ... no mater how much i move the caliper but it doesnt display the value which is on the caliper's display. <br> <br>so what is wrong going on here?
any chance this could be out put to a blue tooth (USB) and linked to a pc or a laptop wirelessly? ANY Ideas on how to get this all to work. I have some digital readings but they are not practical to hardwire so I need to go wirelessly.rgans
Bluetooth probably would be a reasonable choice for wireless, I think with the right set up the system would just behave as if it were connected via the normal USB cable. This page may help: http://www.sparkfun.com/tutorials/67
shift register would help you
Would it be possible to use an digital to analog converter to change the binary to an analog signal. I am trying to bring the data from a set of calipers in to an analog signal data acquisition unit (Dataq DI-145), but it does not accept digital signal.
I don't know of a digital to analog converter that would do it, sorry.
I'm attempting this as my first arduino project- which will be a learning experience. I have wired up my HF digital indicator (which I understand to be the same interface as the chinese calipers) using the same method shown here to convert the logic level. I have uploaded the script and appears everything is correct, I'm not sure how to start the data flow. What do i do to view the data on my PC coming from the arduino? I have launched the terminal viewer, but it is blank. Is a command needed?<br>TIA, -joe
Hi Joe,<br><br>I use the serial monitor part of the arduino software (button next to upload).<br>It does not need any commands, and even if you have go the wiring wrong you should still get the&quot; ready&quot; message from the code. If you are having problems with my code try using the Graph example sketch which can be found in the communications section of the examples to test getting data from the arduino. <br><br>J44
J44, thank you for the reply. I found the error, I left the battery in the gauge and used the logic level hack which caused the arduino to not see a high/low change.<br> <br> I learned quite a bit playing with your script, and one from another forum. My goal was to have the arduino convert the binary to a decimal value. I could not figure a way to change your script to capture the 1 and 0 (sent via serial.print.) to a string or array. Is there a command so that you can append a string with bits as they are read in a loop?<br> <br> Anyways, I now have a script that mostly works; the binary string is truncated properly and converted. I need work and find a way to set the value to be divided by 1000- so that is shows inchs with a decimal place rather than thousanths of a inch (it now rounds to 1 if divided by 1000). Also, I need mod it so that it will display negative readings.<br>
//I modified this script from link below:<br> //http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235853702/0<br> <br> volatile int count = 0;<br> int total = 0;<br> char data[14];<br> int dataPin = 4;<br> int gauge = 0; // display of calipers reading<br> int factor = 0;<br> unsigned long sec;<br> <br> <br> void setup(){<br> pinMode(dataPin, INPUT); //DATA line goes to Arduino digital pin 4<br> Serial.begin(9600);<br> delay(500);<br> //attachInterrupt(0,getBit,FALLING); //CLOCK line goes to Arduino digital pin 2<br> <br> }<br> <br> void loop(){<br> int i,time;<br> for(i=2;i&lt;14;i++){ //initialize array of bits to 0<br> data[i]=0;<br> }<br> do{time = pulseIn(2, LOW);} //repeatedly get the length of LOW pulses until one is longer than 130uS<br> while(time &lt; 130);<br> <br> attachInterrupt(0,getBit,FALLING); //start watching data line<br> <br> while(count &lt; 14){} //wait till all bits are filled in<br> <br> detachInterrupt(0);<br> count = 0;<br> for(i=2;i&lt;14;i++){<br> <br> <br> }<br> <br> gauge = 0; //the following is code for converts least significant bit first binary to decminal, units are thousandths of an inch<br> factor = 1;<br> for(i=2; i&lt;14; i++){<br> gauge += data[i]*factor;<br> factor = factor*2;<br> }<br> <br> Serial.print(&quot;Time (sec):&quot;);<br> sec = millis();<br> Serial.print(sec/1000);<br> Serial.print(&quot; Inches:&quot;);<br> Serial.print(gauge);<br> <br> delay(1000);<br> Serial.println();<br> }<br> <br> <br> void getBit(){<br> char sample = 0; //variable used for &quot;triple sampling&quot;<br> if(digitalRead(dataPin) == HIGH) //here the dataPin is checked three times for a HIGH value.<br> sample++;<br> if(digitalRead(dataPin) == HIGH)<br> sample++;<br> if(digitalRead(dataPin) == HIGH)<br> sample++;<br> if(sample &gt; 1) //if the pin was HIGH at least twice, a 1 is recorded<br> data[count] = 1;<br> count++; //increment count so main() knows when the entire string of bits is ready<br> }<br>
//电子尺读数<br> // gnd data clk vcc1.5<br> // from china<br> <br> int dataIn = 3;<br> int clockIn = 2;<br> <br> int isin=0; //英寸inch=1,mm=0<br> int isfs=0; //是负数<br> int index;<br> <br> unsigned long xData,oData;//最终要输出的数据<br> <br> int ledPin = 13; // the number of the LED pin<br> int ledState = LOW; // ledState used to set the LED<br> long previousMillis = 0; // will store last time LED was updated<br> long interval = 500; // interval at which to blink (milliseconds)<br> <br> long previousGetMillis = 0; //上次中断发生时间<br> long Timeout = 8; //超时时间 8ms<br> <br> <br> <br> void setup(){<br> digitalWrite(dataIn, 1);<br> digitalWrite( clockIn, 1);<br> pinMode(dataIn, INPUT); //DATA line goes to Arduino digital pin 4<br> pinMode(clockIn, INPUT);<br> Serial.begin(9600);<br> delay(500);<br> attachInterrupt(0,getBit,RISING); //CLOCK line goes to Arduino digital pin 2 上升沿触发<br> index =0;<br> xData=0;<br> oData=999;<br> }<br> <br> void loop(){<br> <br> //超时处理<br> if ((index !=0) &amp;&amp; (millis() - previousGetMillis &gt; Timeout) ) {<br> index=0;<br> xData=0;<br> };<br> <br> //输出<br> if (index &gt;23) {<br> if (oData !=xData) {<br> if (isfs==1)<br> Serial.print('-');<br> <br> if (isin==1){ //英寸 inch<br> xData *=5;<br> Serial.print(xData/10000);<br> Serial.print('.');<br> if ((xData % 10000)&lt;1000){<br> if ((xData % 10000)&lt;100){<br> if ((xData % 10000)&lt;10){<br> Serial.print('0');<br> };<br> Serial.print('0');<br> };<br> Serial.print('0');<br> };<br> Serial.println(xData % 10000);<br> }else { //公制 mm<br> <br> Serial.print(xData/100);<br> Serial.print('.');<br> if ((xData % 100)&lt;10) //补0<br> Serial.print('0');<br> Serial.println(xData % 100);<br> };<br> }; //if 公英制<br> oData =xData;<br> index=0;<br> xData=0;<br> };<br> <br> <br> if (millis() - previousMillis &gt; interval) {<br> previousMillis = millis();<br> if (ledState == LOW)<br> ledState = HIGH;<br> else<br> ledState = LOW;<br> digitalWrite(ledPin, ledState);<br> }<br> <br> }<br> <br> <br> <br> void getBit(){<br> previousGetMillis=millis();<br> if(index &lt; 20){<br> if(digitalRead(dataIn)==1){<br> xData|= 1&lt;&lt;index;<br> <br> };<br> } else {<br> <br> if (index==20) //第21位为符号位 -<br> isfs=digitalRead(dataIn);<br> <br> <br> if (index==23) //第24位为公英制 1=英制inch<br> isin=digitalRead(dataIn);<br> <br> };<br> <br> index++;<br> }<br> <br>
Hmm interesting. <br><br>Sadly I do not have my arduinos at hand, but when I do I will try this code out.
I'm seeing this as the basics of a linear encoder setup for motion control; i.e. x,y,z machines. Possible?
I expect it is possible, it is the kind of use I had in mind when I started the hack.
//电子尺读数 <br>// gnd data clk vcc1.5 <br>// from china <br> <br>int dataIn = 3; <br>int clockIn = 2; <br> <br>int isin=0; //英寸inch=1,mm=0 <br>int isfs=0; //是负数 <br>int index; <br> <br>unsigned long xData,oData;//最终要输出的数据 <br> <br>int ledPin = 13; // the number of the LED pin <br>int ledState = LOW; // ledState used to set the LED <br>long previousMillis = 0; // will store last time LED was updated <br>long interval = 500; // interval at which to blink (milliseconds) <br> <br>long previousGetMillis = 0; //上次中断发生时间 <br>long Timeout = 8; //超时时间 8ms <br> <br> <br> <br>void setup(){ <br> digitalWrite(dataIn, 1); <br> digitalWrite( clockIn, 1); <br> pinMode(dataIn, INPUT); //DATA line goes to Arduino digital pin 4 <br> pinMode(clockIn, INPUT); <br> Serial.begin(9600); <br> delay(500); <br> attachInterrupt(0,getBit,RISING); //CLOCK line goes to Arduino digital pin 2 上升沿触发 <br> index =0; <br> xData=0; <br> oData=999; <br>} <br> <br>void loop(){ <br> <br> //超时处理 <br> if ((index !=0) &amp;&amp; (millis() - previousGetMillis &gt; Timeout) ) { <br> index=0; <br> xData=0; <br> }; <br> <br> //输出 <br> if (index &gt;23) { <br> if (oData !=xData) { <br> if (isfs==1) <br> Serial.print('-'); <br> <br> if (isin==1){ //英寸 inch <br> xData *=5; <br> Serial.print(xData/10000); <br> Serial.print('.'); <br> if ((xData % 10000)&lt;1000){ <br> if ((xData % 10000)&lt;100){ <br> if ((xData % 10000)&lt;10){ <br> Serial.print('0'); <br> }; <br> Serial.print('0'); <br> }; <br> Serial.print('0'); <br> }; <br> Serial.println(xData % 10000); <br> }else { //公制 mm <br> <br> Serial.print(xData/100); <br> Serial.print('.'); <br> if ((xData % 100)&lt;10) //补0 <br> Serial.print('0'); <br> Serial.println(xData % 100); <br> }; <br> }; //if 公英制 <br> oData =xData; <br> index=0; <br> xData=0; <br> }; <br> <br> <br> if (millis() - previousMillis &gt; interval) { <br> previousMillis = millis(); <br> if (ledState == LOW) <br> ledState = HIGH; <br> else <br> ledState = LOW; <br> digitalWrite(ledPin, ledState); <br> } <br> <br>} <br> <br> <br> <br>void getBit(){ <br> previousGetMillis=millis(); <br> if(index &lt; 20){ <br> if(digitalRead(dataIn)==1){ <br> xData|= 1&lt; <br> }; <br> } else { <br> <br> if (index==20) //第21位为符号位 - <br> isfs=digitalRead(dataIn); <br> <br> <br> if (index==23) //第24位为公英制 1=英制inch <br> isin=digitalRead(dataIn); <br> <br> }; <br> <br> index++; <br>} <br> <br>
Nice work. How do these calipers transduce the linear displacement to numbers? is it a friction wheel or an optical pick-up?
I think the callipers work with capacitance.
from your timing diagrams it *looks* like I2C. From your schematic it also Looks like I2C (2 lines, one for clock one for data)..hmmm interesting

About This Instructable




More by j44:LED Color Sensor Ultrasonic Headtracker Mouse Halloween Sugru Lights 
Add instructable to: