How to make a Digital ruler with a Raspberry Pi board

How to make a Digital ruler with a Raspberry Pi board

Hello and welcome back. In this project, we will learn how to make a Digital ruler with a Raspberry Pi board. For that, I used an ultrasonic sensor and LCD screen. That is, we can get the distance through the ultrasonic sensor and these values are displayed on the LCD screen. I think this project is most suitable for the school relaters. But, we can use this project for any measurement tasks. For that, assemble this digital ruler project on PCB(Printed Circuit Board). But I used a breadboard.

(adsbygoogle = window.adsbygoogle || []).push({});

I won’t go into too much detail about the sensors and components in these projects. Because I explained this information earlier in my previous tutorials.

  • If you want to do this project with Arduino. — Click me

Ok, let’s do this project step by step. The required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Step 2

Secondly, place the ultrasonic sensor on the breadboard as you like. And then connect it to the Raspberry Pi board.

How to make a Digital ruler with a Raspberry Pi board
(adsbygoogle = window.adsbygoogle || []).push({});

Step 3

Thirdly, connect the LCD screen to the Raspberry Pi board. For that, use the circuit diagram above.

Step 4

Now, connect the mouse, keyboard, monitor, and SD card(OS installed) to the Raspberry Pi board. And then, provide a steady 5v power supply to it.

Step 5

OK, let’s create the python script for this project. It’s as follows.

  • Full details of this project — Download
  • The I2C library is included in this file. You must remember to keep these scripts in one folder.
#Include the library files
import I2C_LCD_driver
from time import sleep
from gpiozero import DistanceSensor

# Create a object for the LCD
lcd = I2C_LCD_driver.lcd()

ultrasonic = DistanceSensor(echo=17,trigger=27)

# Starting text
lcd.lcd_display_string("Digital Ruler",1,2)
for a in range (0,16):


def Distance():
    value = ultrasonic.distance # Get the distance
    cm = int(value*100) # Convert to CM
    inch = int(cm/2.54) # Convert to inch
    lcd.lcd_display_string("Distance :",1,0)
    lcd.lcd_display_string(str(cm)+"CM ",1,10)
    lcd.lcd_display_string("Distance :",2,0)
    lcd.lcd_display_string(str(inch)+"Inch ",2,10)

while True:
(adsbygoogle = window.adsbygoogle || []).push({});
  • Now, copy and paste this script on the Thonny IDE. And then, save it and click the run button.

OK. enjoy this project. The full video guide is below. So, see you in the next tutorial or project.

How to make a Digital ruler with a Raspberry Pi board

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *