I make a electrical ruler.


  1. Use 32bit microcontroller STM32C8T6.
  2. Use 512 line encoder .
  3. Precision 0.1mm.
  4. unit :mm,cm,meter and km.



512 line encoder

OLED display


Step 1: Design a STM32 Board

Sorry for my bad english!

I am 24 years old engineering student from Guangxi in China. It's my frist post arcitle.I want to make some friends to help me learn english.:)

Frist,I design a stm32 PCB board,it include some buttons,crystal,and usb to usart IC CP2102,5V to 3V regulator.

And then,I spent 30RMB (about $6) to make PCB board.Make a PCB board is cheap and easy in China,10cm*10cm,10PCS PCB just olny 50RMB (about $8).

Step 2: Solder Your STM32 Board

About a week,PCB factory will send PCB boards to you by experess,so,you can solder your PCB board now.

Step 3: Make a Wheel by CNC

My friends has a CNC machine,so,I use the CNC machine to cut the acrylic board,and make a wheel and some structures.

Step 4: Install Wheel to Encoder

I buy a 512 line incremental encoder from www.taobao.com,taobao.com just like ebay in China.

This mini incremental encoder about $40,and 512 line meaning every one revolution the encoder will output 512 pulses.

The wheel diameter is 16.3mm,so the wheel perimeter is 16.3mm*3.1415926≈51.2

mm,and every one revolution the encoder will output 512 pulses,so,every pulse correspond 51.2 mm/512 pulse=0.1mm length.

Step 5: Add OLED Display and Li-ion Battery

OLED display cost $1.5 in China,3.3V power supply ,SPI interface and 128*64 pix.

Step 6: Program and Testing

I use the saleae logic to show the encoder pulse wave,and I use Keil MDK to program STM32.

This encoder has 4 pins,VCC,PULSE,DIRECTION,and GROUND.if you turn the encoder ,encoder will output some pulses,if DIRECTION pin is High ,meaning direction is foreward,else if DIRECTION pin is Low,meaning direction is backward.

the STM32F103C8T6 has a encoder interface in GPIOA 12,so I connect PULSE to STM32 GPIOA 12,and DIRECTION connect to GPIOA 11.

OLED showing my school name ,project name and software version .Do you know Chinese ? :)

Step 7: Show Time!

when I start measure at 90mm,finish measure at 0mm,the OLED show measurement result is 90.0mm,and when I start measure at 0mm,turn back it to 90mm,the OLED show measurement result is -90.0mm.

you can switch the result unit as:mm,cm,m and km

I define a double variable to save measurement result,so,the limit is 1.79769e+308 ~ 2.22507e-308 mm

I use this ruler to measure a bottle perimeter,OLED show -140.1mm,I think this bottle perimeter maybe is 140mm.

sorry for my bad english .I want to make some friends.

Source code and PCB files please mail to me satelives@gmail.com.


<p>Oh yeah , i am happy to see the Chinese on your screen.</p>
<p>: )</p>
Good instructable man! Though can you skip the STM board design and opt for another board like arduino?
<p>What's the obsession with arduino? I don't want to be rude but this was clearly made to learn arm, it's a simple enough project to let you start with advanced micros so why would he switch? A nice thing mich could be, if you like to, to port this for arduino yourself and post the result! Beside the code is probably written in plain C/C++ so you can port it very easily to like every other micro you can find like PICs and AVR without the need of a bulky arduino (in terms of physical and programming space). It's so simple it would probably work even on a pic10 or attiny! The only thing is, Xiaoqiz, if you can post the whole code here so people can look at it, comment, learn without mailing you. I wonder why this isn't featured, it's a very nice project!</p>
<p>sorry ,this is my fist article in instructables.com ,and I dont't know how to upload my project files(include code files,PCB files,and schematic) ,I can share whole code with you.</p>
<p>It's easy to work in arduino because you only need to capture encoder's pulses and direction.if your wheel perimeter is 51.2mm,and your encoder output 512 pulses every revolution,so, encoder output one pulse meaning the wheel walk through 0.1 m .</p>
<p>Very good for your first Instructable. Many readers here do not have the money to do this type of worthy project, and look to build using old parts, salvaged parts, leftover parts. That is the challenge that keeps their interest, and increases their knowledge and skill. Your English is easily understood, and communicates well, please feel comfortable submitting more work and welcome.</p>

About This Instructable



Bio: I am 24 years old and come from China. I make these projects as a hobby.I want to make some friends to help me ... More »
More by Cheney Cheung:How to make a wireless mechanical keyboard Make a electrical ruler 
Add instructable to: