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.
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.
- Raspberry Pi board –Amazon
- Ultrasonic sensor x 1 — Amazon / Banggood
- LCD screen x 1 — Amazon / Banggood
- I2C module x 1 — Amazon / Banggood
- Breadboard x 1 — Amazon / Banggood
- Female to Male jumper wires x 7 — Amazon / Banggood
- Male to Male jumper wires x 11 — Amazon / Banggood
Firstly, identify these components.
Secondly, place the ultrasonic sensor on the breadboard as you like. And then connect it to the Raspberry Pi board.
Thirdly, connect the LCD screen to the Raspberry Pi board. For that, use the circuit diagram above.
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.
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): lcd.lcd_display_string(".",2,a) sleep(0.2) lcd.lcd_clear() lcd.lcd_display_string("Wait..",1,0) 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) print(value) sleep(0.05) while True: Distance()
- 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.